3syisgbyq: Add a reusable bottom sheet with the comments and composer sheets on the phone feed
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState, type MouseEvent, type Ref } from "react";
|
||||
import { useCallback, useEffect, useRef, useState, type MouseEvent, type Ref } from "react";
|
||||
import { canDelete, formatDuration, isPlayableVideo, relativeTime, type CardMedia, type CardPost } from "@/lib/feed-model";
|
||||
import { GrowButton } from "./Buttons";
|
||||
import { HexAvatar } from "./HexAvatar";
|
||||
@@ -8,6 +8,9 @@ import { PlayIcon, PostMenu } from "./PostCard";
|
||||
import { VideoPlayer } from "./VideoPlayer";
|
||||
import { FeaturedCarousel } from "./FeaturedCarousel";
|
||||
import { MobileDock } from "./MobileDock";
|
||||
import { BottomSheet } from "./BottomSheet";
|
||||
import { CommentsSection } from "./CommentsSection";
|
||||
import { Composer } from "./Composer";
|
||||
import type { DiscoverExpert } from "@/lib/discover";
|
||||
import type { FeedViewProps } from "./FeedView";
|
||||
|
||||
@@ -278,6 +281,17 @@ function LoadSlide({ index, current, sentinelRef }: { index: number; current: bo
|
||||
export function MobileFeed(p: FeedViewProps) {
|
||||
const reel = useRef<HTMLDivElement | null>(null);
|
||||
const [current, setCurrent] = useState(0);
|
||||
// The open sheet: the comments of one post, the composer, or none.
|
||||
const [sheet, setSheet] = useState<{ kind: "comments"; postId: string } | { kind: "composer" } | null>(null);
|
||||
const closeSheet = useCallback(() => setSheet(null), []);
|
||||
// A successful post closes the composer: publishing ends with no error and an emptied draft.
|
||||
const wasBusy = useRef(false);
|
||||
const composerBusy = !!p.composer?.busy;
|
||||
const composerClear = !!p.composer && !p.composer.error && !p.composer.value && !p.composer.file;
|
||||
useEffect(() => {
|
||||
if (wasBusy.current && !composerBusy && composerClear) setSheet((s) => (s?.kind === "composer" ? null : s));
|
||||
wasBusy.current = composerBusy;
|
||||
}, [composerBusy, composerClear]);
|
||||
const onCurrentChange = p.onCurrentChange;
|
||||
const showLoad = p.status === "loading" || (p.status === "ready" && !p.loadMoreFailed && (p.loadingMore || !!p.hasMore));
|
||||
const experts = p.featuredExperts ?? [];
|
||||
@@ -421,11 +435,27 @@ export function MobileFeed(p: FeedViewProps) {
|
||||
slide={{ index, kind, post: currentPost }}
|
||||
onToggleLike={p.onToggleLike}
|
||||
likeBusy={currentPost ? p.likeBusy?.has(currentPost.key) : false}
|
||||
onOpenComments={p.onOpenComments}
|
||||
onOpenComposer={p.onOpenComposer}
|
||||
onOpenComments={(postId) => {
|
||||
setSheet({ kind: "comments", postId });
|
||||
p.onOpenComments?.(postId);
|
||||
}}
|
||||
onOpenComposer={() => {
|
||||
setSheet({ kind: "composer" });
|
||||
p.onOpenComposer?.();
|
||||
}}
|
||||
onOpenMore={p.onOpenMore}
|
||||
/>
|
||||
) : null}
|
||||
{sheet?.kind === "comments" ? (
|
||||
<BottomSheet title="Comments" onClose={closeSheet} className="sheet-comments">
|
||||
<CommentsSection postId={sheet.postId} onSignedOut={p.onSignedOut} />
|
||||
</BottomSheet>
|
||||
) : null}
|
||||
{sheet?.kind === "composer" && p.composer ? (
|
||||
<BottomSheet title="New post" onClose={closeSheet} className="sheet-composer">
|
||||
<Composer {...p.composer} />
|
||||
</BottomSheet>
|
||||
) : null}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user