import { useAtomValue, useSetAtom } from "jotai"; import { Suspense, useEffect } from "react"; import { useSearch } from "wouter"; import { articleFeedFilterAtom, articlesInfiniteAtom, articleViewAtom, } from "../atoms"; import { ArticleList } from "../components/ArticleList"; import { ErrorBoundary } from "../components/ErrorBoundary"; import { FeedSidebar } from "../components/FeedSidebar"; import { LoadingSpinner } from "../components/LoadingSpinner"; export function UnreadArticles() { const search = useSearch(); const params = new URLSearchParams(search); const feedId = params.get("feed"); const setView = useSetAtom(articleViewAtom); const setFeedFilter = useSetAtom(articleFeedFilterAtom); useEffect(() => { setView("unread"); setFeedFilter(feedId); }, [feedId, setView, setFeedFilter]); return (
}>
); } function UnreadArticleList({ feedId }: { feedId: string | null }) { const { data, isLoading, isFetchingNextPage, hasNextPage, fetchNextPage, error, } = useAtomValue(articlesInfiniteAtom); const articles = data?.pages.flatMap((page) => page.articles) ?? []; if (isLoading) { return (

Loading unread articles...

); } if (error) { return (
Error: {error.message}
); } return ( <>

Unread

{articles.length > 0 && (

{articles.length} {hasNextPage ? "+" : ""} article {articles.length !== 1 ? "s" : ""} to read

)}
fetchNextPage()} /> ); }