import { useEffect, useState } from 'react'; import { useParams } from 'react-router-dom'; import type { Item } from '../types'; import FeedItem from './FeedItem'; import './FeedItems.css'; export default function FeedItems() { const { feedId } = useParams<{ feedId: string }>(); const [items, setItems] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); useEffect(() => { setLoading(true); setError(''); const url = feedId ? `/api/stream?feed_id=${feedId}` : '/api/stream'; // Default or "all" view? For now let's assume we need a feedId or handle "all" logic later fetch(url) .then((res) => { if (!res.ok) { throw new Error('Failed to fetch items'); } return res.json(); }) .then((data) => { setItems(data); setLoading(false); }) .catch((err) => { setError(err.message); setLoading(false); }); }, [feedId]); if (loading) return
Loading items...
; if (error) return
Error: {error}
; return (

Items

{/* TODO: Add Feed Title here if possible, maybe pass from location state or fetch feed details */} {items.length === 0 ? (

No items found.

) : ( )}
); }