import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk'; import { useQuery } from '@tanstack/react-query'; import { nip19 } from 'nostr-tools'; import { useCallback } from 'react'; import { Link } from 'react-router-dom'; import { useNDK } from '@libs/ndk/provider'; import { ArticleNote, FileNote, LinkPreview, NoteActions, NoteSkeleton, RepostUser, TextNote, UnknownNote, } from '@shared/notes'; import { User } from '@shared/user'; export function Repost({ event }: { event: NDKEvent }) { const embedEvent: null | NDKEvent = event.content.length > 0 ? JSON.parse(event.content) : null; const { ndk } = useNDK(); const { status, data } = useQuery( ['repost', event.id], async () => { const id = event.tags.find((el) => el[0] === 'e')[1]; if (id === undefined) throw new Error('wrong id'); const ndkEvent = await ndk.fetchEvent(id); if (!ndkEvent) throw new Error('Event not found'); return ndkEvent; }, { enabled: embedEvent === null, refetchOnWindowFocus: false, } ); const renderKind = useCallback((repostEvent: NDKEvent) => { switch (repostEvent.kind) { case NDKKind.Text: return ; case NDKKind.Article: return ; case 1063: return ; default: return ; } }, []); if (embedEvent) { return (
{renderKind(embedEvent)}
); } if (status === 'loading') { return (
); } if (status === 'error') { // @ts-expect-error, root_id isn't exist on NDKEvent const noteLink = `https://njump.me/${nip19.noteEncode(event.root_id)}`; return (
lume
Lume (System)
Lume cannot find this post with your current relays, but you can view it via njump.me.{' '} Learn more
); } return (
{renderKind(data)}
); }