import { LoaderIcon } from "@lume/icons"; import { NDKEventWithReplies } from "@lume/types"; import { NDKSubscription } from "@nostr-dev-kit/ndk"; import { useEffect, useState } from "react"; import { twMerge } from "tailwind-merge"; import { useArk } from "../../provider"; import { Reply } from "./builds/reply"; export function NoteReplyList({ eventId, title, className, }: { eventId: string; title?: string; className?: string }) { const ark = useArk(); const [data, setData] = useState(null); useEffect(() => { let sub: NDKSubscription; let isCancelled = false; async function fetchRepliesAndSub() { const events = await ark.getThreads({ id: eventId }); if (!isCancelled) { setData(events); } // subscribe for new replies sub = ark.subscribe({ filter: { "#e": [eventId], since: Math.floor(Date.now() / 1000), }, closeOnEose: false, cb: (event: NDKEventWithReplies) => setData((prev) => [event, ...prev]), }); } fetchRepliesAndSub(); return () => { isCancelled = true; if (sub) sub.stop(); }; }, [eventId]); return (

{title}

{!data ? (
) : data.length === 0 ? (

👋

Be the first to Reply!

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