aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/src/pages/UnreadArticles.tsx
blob: dc4c37797aaf85373bd0cd8fded3a2b592db89c7 (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
import { useQuery } from "urql";
import { ArticleList } from "../components";
import { GetUnreadArticlesDocument } from "../graphql/generated/graphql";

const urqlContextArticle = { additionalTypenames: ["Article"] };

export function UnreadArticles() {
	const [{ data, fetching, error }] = useQuery({
		query: GetUnreadArticlesDocument,
		context: urqlContextArticle,
	});

	if (fetching) {
		return <div className="p-4">Loading unread articles...</div>;
	}

	if (error) {
		return <div className="p-4 text-red-600">Error: {error.message}</div>;
	}

	return (
		<div>
			<div className="border-b border-gray-200 bg-white px-4 py-3">
				<h1 className="text-xl font-semibold text-gray-900">Unread Articles</h1>
				{data?.unreadArticles && (
					<p className="text-sm text-gray-500">
						{data.unreadArticles.length} article
						{data.unreadArticles.length !== 1 ? "s" : ""}
					</p>
				)}
			</div>
			{data?.unreadArticles && (
				<ArticleList articles={data.unreadArticles} isReadView={false} />
			)}
		</div>
	);
}