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-interests")( { component: Screen, }, ); function Screen() { const { isLoading, isError, error, isFetchingNextPage, hasNextPage, fetchNextPage, data, } = useInfiniteQuery({ queryKey: ["local-interests"], initialPageParam: 0, queryFn: async ({ pageParam }: { pageParam: number }) => { const until = pageParam > 0 ? pageParam.toString() : null; const res = await commands.getAllLocalInterests(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] === "t")?.length > 0, ), refetchOnWindowFocus: false, }); const ref = useRef(null); const renderItem = useCallback( (item: NostrEvent) => { const name = item.tags.find((tag) => tag[0] === "title")?.[1] || "Unnamed"; const label = item.tags.find((tag) => tag[0] === "label")?.[1] || nanoid(); return (
{item.tags .filter((tag) => tag[0] === "t") .map((tag) => (
{tag[1].includes("#") ? tag[1] : `#${tag[1]}`}
))}
{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)) )}

Lume running sync in the background,
the more you use the more event you see.

{hasNextPage ? ( ) : null}
); }