import { commands } from "@/commands.gen"; import { toLumeEvents } from "@/commons"; import { Spinner, User } from "@/components"; import { LumeWindow } from "@/system"; 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 { nanoid } from "nanoid"; import type { NostrEvent } from "nostr-tools"; import { type RefObject, useCallback, useRef } from "react"; import { Virtualizer } from "virtua"; export const Route = createLazyFileRoute("/columns/_layout/discover-newsfeeds")( { component: Screen, }, ); function Screen() { const { isLoading, isError, error, isFetchingNextPage, hasNextPage, fetchNextPage, data, } = useInfiniteQuery({ queryKey: ["local-newsfeeds"], initialPageParam: 0, queryFn: async ({ pageParam }: { pageParam: number }) => { const until = pageParam > 0 ? pageParam.toString() : null; const res = await commands.getAllLocalNewsfeeds(until); if (res.status === "ok") { const data = toLumeEvents(res.data); return data; } else { throw new Error(res.error); } }, getNextPageParam: (lastPage) => { const lastEvent = lastPage.at(-1); if (lastEvent) { return lastEvent.created_at - 1; } }, select: (data) => data?.pages .flat() .filter( (item) => item.tags.filter((tag) => tag[0] === "p")?.length > 0, ), refetchOnWindowFocus: false, }); const ref = useRef(null); const renderItem = useCallback( (item: NostrEvent) => { const users = item.tags.filter((tag) => tag[0] === "p"); const name = item.tags.find((tag) => tag[0] === "title")?.[1] || "Unnamed"; const label = item.tags.find((tag) => tag[0] === "d")?.[1] || nanoid(); return (
{users.slice(0, 5).map((tag) => ( ))} {users.length > 5 ? (

+{users.length - 5}

) : null}
{name}
); }, [data], ); return ( }> {isLoading ? (

Loading event...

) : isError ? (

{error?.message ?? "Error"}

) : !data?.length ? (

Nothing to show yet, you can use Lume more and comeback lack to see new events.

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