import { faCheck, faCircle, faTrash } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useMutation } from "urql"; import type { GetFeedsQuery } from "../graphql/generated/graphql"; import { MarkFeedReadDocument, MarkFeedUnreadDocument, UnsubscribeFeedDocument, } from "../graphql/generated/graphql"; type Feed = NonNullable[0]; interface Props { feed: Feed; onFeedUnsubscribed?: () => void; } export function FeedItem({ feed, onFeedUnsubscribed }: Props) { 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?.(); } }; return (

{feed.title}

{feed.url}

Last fetched: {formatDateTime(new Date(feed.fetchedAt))}
); } function formatDateTime(date: Date): string { const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, "0"); const day = String(date.getDate()).padStart(2, "0"); const hours = String(date.getHours()).padStart(2, "0"); const minutes = String(date.getMinutes()).padStart(2, "0"); return `${year}-${month}-${day} ${hours}:${minutes}`; }