import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk'; import * as AlertDialog from '@radix-ui/react-alert-dialog'; import * as Tooltip from '@radix-ui/react-tooltip'; import { useState } from 'react'; import { toast } from 'sonner'; import { twMerge } from 'tailwind-merge'; import { useNDK } from '@libs/ndk/provider'; import { LoaderIcon, RepostIcon } from '@shared/icons'; export function NoteRepost({ id, pubkey }: { id: string; pubkey: string }) { const { ndk, relayUrls } = useNDK(); const [open, setOpen] = useState(false); const [isLoading, setIsLoading] = useState(false); const [isRepost, setIsRepost] = useState(false); const submit = async () => { setIsLoading(true); const tags = [ ['e', id, relayUrls[0], 'root'], ['p', pubkey], ]; const event = new NDKEvent(ndk); event.content = ''; event.kind = NDKKind.Repost; event.tags = tags; const publishedRelays = await event.publish(); if (publishedRelays) { setOpen(false); setIsRepost(true); toast.success(`Broadcasted to ${publishedRelays.size} relays successfully.`); } else { setIsLoading(false); toast.error('Repost failed, try again later'); } }; return ( Repost
Confirm repost this post? Reposted post will be visible to your followers, and you cannot undo this action.
); }