RepostNotification.tsx raw

   1  import client from '@/services/client.service'
   2  import { Repeat } from 'lucide-react'
   3  import { Event, validateEvent } from 'nostr-tools'
   4  import { useMemo } from 'react'
   5  import { useTranslation } from 'react-i18next'
   6  import Notification from './Notification'
   7  
   8  export function RepostNotification({
   9    notification,
  10    isNew = false,
  11    navIndex
  12  }: {
  13    notification: Event
  14    isNew?: boolean
  15    navIndex?: number
  16  }) {
  17    const { t } = useTranslation()
  18    const event = useMemo(() => {
  19      try {
  20        const event = JSON.parse(notification.content) as Event
  21        const isValid = validateEvent(event)
  22        if (!isValid) return null
  23        client.addEventToCache(event)
  24        return event
  25      } catch {
  26        return null
  27      }
  28    }, [notification.content])
  29    if (!event) return null
  30  
  31    return (
  32      <Notification
  33        notificationId={notification.id}
  34        icon={<Repeat size={24} className="text-green-400" />}
  35        sender={notification.pubkey}
  36        sentAt={notification.created_at}
  37        targetEvent={event}
  38        description={t('reposted your note')}
  39        isNew={isNew}
  40        navIndex={navIndex}
  41      />
  42    )
  43  }
  44