import { commands } from "@/commands.gen"; import { Spinner, User } from "@/components"; import { LumeWindow } from "@/system"; import type { NostrEvent } 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/discover-relays")({ component: Screen, }); function Screen() { const { isLoading, isError, error, isFetchingNextPage, hasNextPage, fetchNextPage, data, } = useInfiniteQuery({ queryKey: ["discover-relays"], initialPageParam: 0, queryFn: async ({ pageParam }: { pageParam: number }) => { const until = pageParam > 0 ? pageParam.toString() : null; const res = await commands.getAllRelayLists(until); if (res.status === "ok") { const data: NostrEvent[] = res.data.map((item) => JSON.parse(item)); 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(), refetchOnWindowFocus: false, refetchOnReconnect: false, refetchOnMount: false, }); const ref = useRef(null); const renderItem = useCallback( (item: NostrEvent) => { return (
{item.tags.map((tag) => tag[1]?.startsWith("wss://") ? (
{tag[1]}
) : null, )}
); }, [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}
); }