import { faCheck, faCircle, faTrash } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import type { components } from "../api/generated"; import { api } from "../services/api-client"; type Feed = components["schemas"]["Feed"]; interface Props { feed: Feed; onFeedUnsubscribed?: () => void; onFeedChanged?: () => void; } export function FeedItem({ feed, onFeedUnsubscribed, onFeedChanged }: Props) { const handleMarkAllRead = async (feedId: string) => { await api.POST("/api/feeds/{feedId}/read", { params: { path: { feedId } }, }); onFeedChanged?.(); }; const handleMarkAllUnread = async (feedId: string) => { await api.POST("/api/feeds/{feedId}/unread", { params: { path: { feedId } }, }); onFeedChanged?.(); }; const handleUnsubscribeFeed = async (feedId: string) => { const confirmed = window.confirm( "Are you sure you want to unsubscribe from this feed?", ); if (confirmed) { await api.DELETE("/api/feeds/{feedId}", { params: { path: { 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}`; }