import { faCheck, faCircle, faTrash } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useMutation, useQuery } from "urql"; import { GetFeedsDocument, MarkFeedReadDocument, MarkFeedUnreadDocument, UnsubscribeFeedDocument, } from "../graphql/generated/graphql"; interface Props { onFeedUnsubscribed?: () => void; } export function FeedList({ onFeedUnsubscribed }: Props) { const [{ data, fetching, error }] = useQuery({ query: GetFeedsDocument, }); const [, markFeedRead] = useMutation(MarkFeedReadDocument); const [, markFeedUnread] = useMutation(MarkFeedUnreadDocument); const [, unsubscribeFeed] = useMutation(UnsubscribeFeedDocument); const handleMarkAllRead = async (feedId: string) => { await markFeedRead({ id: feedId }); }; const handleMarkAllUnread = async (feedId: string) => { await markFeedUnread({ id: feedId }); }; const handleUnsubscribeFeed = async (feedId: string) => { const confirmed = window.confirm( "Are you sure you want to unsubscribe from this feed?", ); if (confirmed) { await unsubscribeFeed({ id: feedId }); onFeedUnsubscribed?.(); } }; 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) => { return (

{feed.title}

{feed.url}

Last fetched: {new Date(feed.fetchedAt).toLocaleString()}
); })}
); }