import { Conversation } from "@/components/conversation"; import { Quote } from "@/components/quote"; import { RepostNote } from "@/components/repost"; import { TextNote } from "@/components/text"; import { ArrowRightCircleIcon, ArrowRightIcon } from "@lume/icons"; import { type ColumnRouteSearch, type Event, Kind } from "@lume/types"; import { Spinner } from "@lume/ui"; import { useInfiniteQuery } from "@tanstack/react-query"; import { Link, redirect } from "@tanstack/react-router"; import { createFileRoute } from "@tanstack/react-router"; import { Virtualizer } from "virtua"; export const Route = createFileRoute("/newsfeed")({ validateSearch: (search: Record): ColumnRouteSearch => { return { account: search.account, label: search.label, name: search.name, }; }, beforeLoad: async ({ search, context }) => { const ark = context.ark; const settings = await ark.get_settings(); const contacts = await ark.get_contact_list(); if (!contacts.length) { throw redirect({ to: "/create-newsfeed/users", search: { ...search, redirect: "/newsfeed", }, }); } return { settings, contacts }; }, component: Screen, }); export function Screen() { const { label, account } = Route.useSearch(); const { ark, contacts } = Route.useRouteContext(); const { data, isLoading, isFetching, isFetchingNextPage, hasNextPage, fetchNextPage, } = useInfiniteQuery({ queryKey: [label, account], initialPageParam: 0, queryFn: async ({ pageParam }: { pageParam: number }) => { const events = await ark.get_local_events(contacts, 20, pageParam); return events; }, getNextPageParam: (lastPage) => lastPage?.at(-1)?.created_at - 1, select: (data) => data?.pages.flatMap((page) => page), refetchOnWindowFocus: false, }); const renderItem = (event: Event) => { if (!event) return; switch (event.kind) { case Kind.Repost: return ; default: { const isConversation = event.tags.filter((tag) => tag[0] === "e" && tag[3] !== "mention") .length > 0; const isQuote = event.tags.filter((tag) => tag[0] === "q").length > 0; if (isConversation) { return ; } if (isQuote) { return ; } return ; } } }; return (
{isFetching && !isLoading && !isFetchingNextPage ? (
Fetching new notes...
) : null} {isLoading ? (
Loading...
) : !data.length ? (
Yo. You're catching up on all the things happening around you.
) : ( {data.map((item) => renderItem(item))} )} {data?.length && hasNextPage ? (
) : null}
); }