import {useCallback, useEffect, useState} from "react"; import {Link} from "react-router-dom"; import {toast} from "sonner"; import {Plus, Pencil, Trash2} from "lucide-react"; import {newsApi} from "@/api"; import type {NewsDto} from "@/api/schema.gen"; import {Button} from "@/components/ui/button"; import {Badge} from "@/components/ui/badge"; import {Table, TableHeader, TableBody, TableRow, TableHead, TableCell} from "@/components/ui/table"; export function NewsListPage() { const [news, setNews] = useState([]); const [loading, setLoading] = useState(true); const load = useCallback(() => { setLoading(true); newsApi.list({}) .then(setNews) .catch(() => toast.error("Failed to load news")) .finally(() => setLoading(false)); }, []); useEffect(() => { load(); }, [load]); const remove = async (id: string) => { if (!confirm("Delete this news item?")) return; try { await newsApi.remove(id); toast.success("News item deleted"); load(); } catch { toast.error("Failed to delete"); } }; return (

News

{loading ? (

Loading…

) : ( Title Status Author Updated Actions {news.map(n => ( {n.title} {n.published ? ( published ) : n.publish_at ? ( scheduled ) : ( draft )} {n.author ?? "—"} {new Date(n.updated_at).toLocaleDateString("en-US")}
))}
)}
); }