import { commands } from "@/commands.gen"; import { toLumeEvents } from "@/commons"; import { Quote, RepostNote, Spinner, TextNote } from "@/components"; import type { LumeEvent } from "@/system"; import { Kind } from "@/types"; import { ArrowCircleRight } from "@phosphor-icons/react"; import * as ScrollArea from "@radix-ui/react-scroll-area"; import { useInfiniteQuery } from "@tanstack/react-query"; import { createFileRoute } from "@tanstack/react-router"; import { useCallback, useRef } from "react"; import { Virtualizer } from "virtua"; export const Route = createFileRoute("/columns/_layout/global")({ component: Screen, }); export function Screen() { const { label, account } = Route.useSearch(); const { data, isLoading, isFetching, isFetchingNextPage, hasNextPage, fetchNextPage, } = useInfiniteQuery({ queryKey: [label, account], initialPageParam: 0, queryFn: async ({ pageParam }: { pageParam: number }) => { const until = pageParam > 0 ? pageParam.toString() : undefined; const res = await commands.getGlobalEvents(until); if (res.status === "error") { throw new Error(res.error); } return toLumeEvents(res.data); }, getNextPageParam: (lastPage) => lastPage?.at(-1)?.created_at - 1, select: (data) => data?.pages.flat(), refetchOnWindowFocus: false, }); const ref = useRef(null); const renderItem = useCallback( (event: LumeEvent) => { if (!event) return; switch (event.kind) { case Kind.Repost: return ; default: { if (event.isQuote) { return ; } else { 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}
); }