import { TextNote } from "@/components/text"; import { RepostNote } from "@/components/repost"; import { ArrowRightCircleIcon, InfoIcon } from "@lume/icons"; import { Event, Kind } from "@lume/types"; import { FETCH_LIMIT } from "@lume/utils"; import { useInfiniteQuery } from "@tanstack/react-query"; import { useRouteContext } from "@tanstack/react-router"; import { Spinner } from "@lume/ui"; export function EventList({ id }: { id: string }) { const { ark } = useRouteContext({ strict: false }); const { data, hasNextPage, isLoading, isFetchingNextPage, fetchNextPage } = useInfiniteQuery({ queryKey: ["events", id], initialPageParam: 0, queryFn: async ({ pageParam }: { pageParam: number }) => { const events = await ark.get_events_from(id, FETCH_LIMIT, pageParam); return events; }, getNextPageParam: (lastPage) => { const lastEvent = lastPage?.at(-1); if (!lastEvent) return; return lastEvent.created_at - 1; }, select: (data) => data?.pages.flatMap((page) => page), refetchOnWindowFocus: false, }); const renderItem = (event: Event) => { if (!event) return; switch (event.kind) { case Kind.Repost: return ; default: return ; } }; return (
{isLoading ? (
) : !data.length ? (

Empty newsfeed.

) : ( data.map((item) => renderItem(item)) )}
{hasNextPage ? ( ) : null}
); }