Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 3x 3x 3x 3x 3x 2x 2x 2x 2x 1x 1x 1x 1x 3x 1x 1x 2x | 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<Item[]>([]);
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) => {
Iif (!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 <div className="feed-items-loading">Loading items...</div>;
Iif (error) return <div className="feed-items-error">Error: {error}</div>;
return (
<div className="feed-items">
<h2>Items</h2>
{/* TODO: Add Feed Title here if possible, maybe pass from location state or fetch feed details */}
{items.length === 0 ? (
<p>No items found.</p>
) : (
<ul className="item-list">
{items.map((item) => (
<FeedItem key={item._id} item={item} />
))}
</ul>
)}
</div>
);
}
|