import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { useVirtualizer } from '@tanstack/react-virtual'; import { useRef } from 'react'; import { useNDK } from '@libs/ndk/provider'; import { NoteKind_1, NoteSkeleton } from '@shared/notes'; import { nHoursAgo } from '@utils/date'; import { LumeEvent } from '@utils/types'; export function UserFeed({ pubkey }: { pubkey: string }) { const parentRef = useRef(); const { fetcher, relayUrls } = useNDK(); const { status, data } = useQuery(['user-feed', pubkey], async () => { const events = await fetcher.fetchAllEvents( relayUrls, { kinds: [1], authors: [pubkey] }, { since: nHoursAgo(48) }, { sort: true } ); return events as unknown as LumeEvent[]; }); const rowVirtualizer = useVirtualizer({ count: data ? data.length : 0, getScrollElement: () => parentRef.current, estimateSize: () => 400, }); const itemsVirtualizer = rowVirtualizer.getVirtualItems(); return (
{status === 'loading' ? (
) : itemsVirtualizer.length === 0 ? (

No new posts about this hashtag in 48 hours ago

) : (
{itemsVirtualizer.map((virtualRow) => (
))}
)}
); }