import { Dialog, Transition } from '@headlessui/react'; import { NDKEvent, NDKFilter } from '@nostr-dev-kit/ndk'; import { useQuery } from '@tanstack/react-query'; import { Fragment, useRef, useState } from 'react'; import { useNDK } from '@libs/ndk/provider'; import { BellIcon, CancelIcon, LoaderIcon } from '@shared/icons'; import { NotificationUser } from '@shared/notification/user'; import { User } from '@shared/user'; import { dateToUnix, getHourAgo } from '@utils/date'; export function NotificationModal({ pubkey }: { pubkey: string }) { const now = useRef(new Date()); const [isOpen, setIsOpen] = useState(false); const { ndk } = useNDK(); const { status, data } = useQuery( ['user-notification', pubkey], async () => { const filter: NDKFilter = { '#p': [pubkey], kinds: [1, 6, 7, 9735], since: dateToUnix(getHourAgo(48, now.current)), }; const events = await ndk.fetchEvents(filter); return [...events]; }, { refetchOnMount: false, refetchOnReconnect: false, refetchOnWindowFocus: false, staleTime: Infinity, } ); const closeModal = () => { setIsOpen(false); }; const openModal = () => { setIsOpen(true); }; const renderItem = (event: NDKEvent) => { if (event.kind === 1) { return (

{event.content}

); } if (event.kind === 6) { return (
); } if (event.kind === 7) { return (
); } if (event.kind === 9735) { return (
); } return
{event.content}
; }; return ( <>
Notification
All things happen when you rest in 48 hours ago
{status === 'loading' ? (
) : data.length < 1 ? (

🎉

Yo!, you've no new notifications

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