import { Reply, useArk } from "@lume/ark"; import { LoaderIcon } from "@lume/icons"; import { NDKEventWithReplies } from "@lume/types"; import { cn } from "@lume/utils"; import { NDKKind, type NDKSubscription } from "@nostr-dev-kit/ndk"; import { useEffect, useState } from "react"; import { ReplyForm } from "./editor/replyForm"; export function ReplyList({ eventId, className, }: { eventId: string; className?: string }) { const ark = useArk(); const [data, setData] = useState(null); useEffect(() => { let sub: NDKSubscription = undefined; let isCancelled = false; async function fetchRepliesAndSub() { const id = ark.getCleanEventId(eventId); const events = await ark.getThreads(id); if (!isCancelled) { setData(events); } if (!sub) { sub = ark.subscribe({ filter: { "#e": [id], kinds: [NDKKind.Text], since: Math.floor(Date.now() / 1000), }, closeOnEose: false, cb: (event: NDKEventWithReplies) => setData((prev) => [event, ...prev]), }); } } // subscribe for new replies fetchRepliesAndSub(); return () => { isCancelled = true; if (sub) sub.stop(); }; }, [eventId]); return (
{!data ? (
) : data.length === 0 ? (

👋

Be the first to Reply!

) : ( data.map((event) => ) )}
); }