PollResponseNotification.tsx raw
1 import { useFetchEvent } from '@/hooks'
2 import { generateBech32IdFromETag, tagNameEquals } from '@/lib/tag'
3 import { Vote } from 'lucide-react'
4 import { Event } from 'nostr-tools'
5 import { useMemo } from 'react'
6 import Notification from './Notification'
7 import { useTranslation } from 'react-i18next'
8
9 export function PollResponseNotification({
10 notification,
11 isNew = false,
12 navIndex
13 }: {
14 notification: Event
15 isNew?: boolean
16 navIndex?: number
17 }) {
18 const { t } = useTranslation()
19 const eventId = useMemo(() => {
20 const eTag = notification.tags.find(tagNameEquals('e'))
21 return eTag ? generateBech32IdFromETag(eTag) : undefined
22 }, [notification])
23 const { event: pollEvent } = useFetchEvent(eventId)
24
25 if (!pollEvent) {
26 return null
27 }
28
29 return (
30 <Notification
31 notificationId={notification.id}
32 icon={<Vote size={24} className="text-violet-400" />}
33 sender={notification.pubkey}
34 sentAt={notification.created_at}
35 targetEvent={pollEvent}
36 description={t('voted in your poll')}
37 isNew={isNew}
38 navIndex={navIndex}
39 />
40 )
41 }
42