import { commands } from "@/commands.gen"; import { toLumeEvents } from "@/commons"; import { RepostNote, Spinner, TextNote } from "@/components"; import type { LumeEvent } from "@/system"; import { Kind } from "@/types"; import { ArrowDown } from "@phosphor-icons/react"; import * as ScrollArea from "@radix-ui/react-scroll-area"; import { useInfiniteQuery } from "@tanstack/react-query"; import { createLazyFileRoute } from "@tanstack/react-router"; import { type RefObject, useCallback, useRef } from "react"; import { Virtualizer } from "virtua"; export const Route = createLazyFileRoute("/columns/_layout/groups/$id")({ component: Screen, }); export function Screen() { const group = Route.useLoaderData(); const params = Route.useParams(); const { data, isLoading, isFetching, isFetchingNextPage, hasNextPage, fetchNextPage, } = useInfiniteQuery({ queryKey: ["groups", params.id], initialPageParam: 0, queryFn: async ({ pageParam }: { pageParam: number }) => { const until = pageParam > 0 ? pageParam.toString() : null; const res = await commands.getAllEventsByAuthors(group, until); if (res.status === "error") { throw new Error(res.error); } return toLumeEvents(res.data); }, getNextPageParam: (lastPage) => { const lastEvent = lastPage.at(-1); if (lastEvent) { return lastEvent.created_at - 1; } }, select: (data) => data?.pages.flat(), enabled: group?.length > 0, refetchOnWindowFocus: false, }); const ref = useRef(null); const renderItem = useCallback( (event: LumeEvent) => { if (!event) return; switch (event.kind) { case Kind.Repost: { const repostId = event.repostId; return ( ); } default: return ( ); } }, [data], ); return ( }> {isFetching && !isLoading && !isFetchingNextPage ? (
Getting new notes...
) : null} {isLoading ? (
Loading...
) : !data?.length ? (
🎉 Yo. You're catching up on all latest notes.
) : ( data.map((item) => renderItem(item)) )} {hasNextPage ? (
) : null}
); }