import { useCallback, useEffect, useState } from "react"; import type { components } from "../api/generated"; import { api } from "../services/api-client"; import { FeedItem } from "./FeedItem"; type Feed = components["schemas"]["Feed"]; interface Props { onFeedUnsubscribed?: () => void; } export function FeedList({ onFeedUnsubscribed }: Props) { const [feeds, setFeeds] = useState([]); const [fetching, setFetching] = useState(true); const [error, setError] = useState(null); const fetchFeeds = useCallback(async () => { setFetching(true); const { data } = await api.GET("/api/feeds"); if (data) { setFeeds(data); setError(null); } else { setError("Failed to load feeds"); } setFetching(false); }, []); useEffect(() => { fetchFeeds(); }, [fetchFeeds]); const handleFeedUnsubscribed = () => { fetchFeeds(); onFeedUnsubscribed?.(); }; const handleFeedChanged = () => { fetchFeeds(); }; if (fetching) { return (

Loading feeds...

); } if (error) { return (
Error: {error}
); } if (feeds.length === 0) { return (

No feeds added yet.

); } return (
{feeds.map((feed) => ( ))}
); }