import { faCheckDouble, faCircle, faTrash, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useMutation, useQuery } from "urql"; import { GetFeedsDocument, MarkFeedReadDocument, MarkFeedUnreadDocument, RemoveFeedDocument, } from "../graphql/generated/graphql"; interface Props { onFeedDeleted?: () => void; selectedFeeds?: Set; onSelectFeed?: (feedId: string, selected: boolean) => void; } export function FeedList({ onFeedDeleted, selectedFeeds, onSelectFeed, }: Props) { const [{ data, fetching, error }] = useQuery({ query: GetFeedsDocument, }); const [, markFeedRead] = useMutation(MarkFeedReadDocument); const [, markFeedUnread] = useMutation(MarkFeedUnreadDocument); const [, removeFeed] = useMutation(RemoveFeedDocument); const handleMarkAllRead = async (feedId: string) => { await markFeedRead({ id: feedId }); }; const handleMarkAllUnread = async (feedId: string) => { await markFeedUnread({ id: feedId }); }; const handleDeleteFeed = async (feedId: string) => { const confirmed = window.confirm( "Are you sure you want to delete this feed?", ); if (confirmed) { await removeFeed({ id: feedId }); onFeedDeleted?.(); } }; if (fetching) return
Loading feeds...
; if (error) return
Error: {error.message}
; if (!data?.feeds || data.feeds.length === 0) { return
No feeds added yet.
; } return (
{data.feeds.map((feed) => { const unreadCount = feed.articles.filter((a) => !a.isRead).length; const totalCount = feed.articles.length; const isSelected = selectedFeeds?.has(feed.id) ?? false; return (
{selectedFeeds && onSelectFeed && (
onSelectFeed(feed.id, e.target.checked)} className="mt-1 rounded border-gray-300 text-blue-600 focus:ring-blue-500" />

{feed.title}

{feed.url}

{unreadCount} unread / {totalCount} total Last fetched:{" "} {new Date(feed.fetchedAt).toLocaleString()}
)} {(!selectedFeeds || !onSelectFeed) && (

{feed.title}

{feed.url}

{unreadCount} unread / {totalCount} total Last fetched: {new Date(feed.fetchedAt).toLocaleString()}
)}
); })}
); }