import { useEffect, useState } from "react"; import { getJSON, type Resource } from "../api"; import { ResourceCard } from "../components/ResourceCard"; import { readFavorites } from "../favorites"; import { useI18n } from "../i18n"; export function FavoritesPage() { const { t, lang } = useI18n(); const [items, setItems] = useState([]); useEffect(() => { let cancelled = false; (async () => { const ids = readFavorites(); const out: Resource[] = []; for (const id of ids) { try { const r = await getJSON( `/api/resources/${id}?lang=${encodeURIComponent(lang)}`, ); out.push(r); } catch { // ignore missing } } if (!cancelled) setItems(out); })(); return () => { cancelled = true; }; }, [lang]); return (

{t("favorites")}

{items.length === 0 ? (

{t("favoritesEmpty")}

) : null}
{items.map((r) => ( ))}
); }