import { LoaderIcon } from '@lume/icons'; import { NDKEventWithReplies } from '@lume/types'; import { NDKSubscription } from '@nostr-dev-kit/ndk'; import { useEffect, useState } from 'react'; import { useArk } from '../../provider'; import { Reply } from './builds/reply'; export function NoteReplies({ eventId }: { eventId: 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]); if (!data) { return (
); } return (

Replies

{data?.length === 0 ? (

👋

Be the first to Reply!

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