aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/src/components/FeedList.tsx
blob: 24bcfc765842b599a61862d1129a208f5e33ebe2 (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
49
50
import { useQuery } from "urql";
import { GetFeedsDocument } from "../graphql/generated/graphql";
import { FeedItem } from "./FeedItem";

interface Props {
	onFeedUnsubscribed?: () => void;
}

const urqlContextFeed = { additionalTypenames: ["Feed"] };

export function FeedList({ onFeedUnsubscribed }: Props) {
	const [{ data, fetching, error }] = useQuery({
		query: GetFeedsDocument,
		context: urqlContextFeed,
	});

	if (fetching) {
		return (
			<div className="py-8 text-center">
				<p className="text-sm text-stone-400">Loading feeds...</p>
			</div>
		);
	}
	if (error) {
		return (
			<div className="rounded-lg bg-red-50 p-4 text-sm text-red-600">
				Error: {error.message}
			</div>
		);
	}
	if (!data?.feeds || data.feeds.length === 0) {
		return (
			<div className="py-8 text-center">
				<p className="text-sm text-stone-400">No feeds added yet.</p>
			</div>
		);
	}

	return (
		<div className="space-y-3">
			{data.feeds.map((feed) => (
				<FeedItem
					key={feed.id}
					feed={feed}
					onFeedUnsubscribed={onFeedUnsubscribed}
				/>
			))}
		</div>
	);
}