aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/src/pages/ReadArticles.tsx
blob: 2538446f0257f61d6c8f3556f4137061f779f8b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { useSearch } from "wouter";
import { ArticleList, FeedSidebar } from "../components";
import { usePaginatedArticles } from "../hooks/usePaginatedArticles";

export function ReadArticles() {
	const search = useSearch();
	const params = new URLSearchParams(search);
	const feedId = params.get("feed");

	const { articles, hasNextPage, loading, loadingMore, loadMore, error } =
		usePaginatedArticles({ isReadView: true, feedId });

	return (
		<div className="flex gap-8">
			<FeedSidebar basePath="/read" />
			<div className="min-w-0 flex-1">
				<div className="mb-6">
					<h1 className="text-xl font-semibold text-stone-900">Read</h1>
					{!loading && articles.length > 0 && (
						<p className="mt-1 text-sm text-stone-400">
							{articles.length}
							{hasNextPage ? "+" : ""} article
							{articles.length !== 1 ? "s" : ""}
						</p>
					)}
				</div>
				{loading ? (
					<div className="py-8 text-center">
						<p className="text-sm text-stone-400">Loading read articles...</p>
					</div>
				) : error ? (
					<div className="rounded-lg bg-red-50 p-4 text-sm text-red-600">
						Error: {error.message}
					</div>
				) : (
					<ArticleList
						articles={articles}
						isReadView={true}
						isSingleFeed={!!feedId}
						hasNextPage={hasNextPage}
						loadingMore={loadingMore}
						onLoadMore={loadMore}
					/>
				)}
			</div>
		</div>
	);
}