import { useCallback, useEffect, useState } from "react"; import { getConfig, getPreview, type Preview, putConfig } from "../api.js"; import { Badge, Button, Card, useToast } from "../components.js"; import { platformOf } from "../hooks.js"; export const Games = () => { const [preview, setPreview] = useState(); const [loading, setLoading] = useState(false); const [showSkipped, setShowSkipped] = useState(false); const toast = useToast(); const refresh = useCallback(() => { setLoading(true); getPreview() .then(setPreview) .catch((e) => toast(String(e))) .finally(() => setLoading(false)); }, [toast]); useEffect(refresh, [refresh]); // Toggle a title's exclude override, persist, and refresh the preview. const setExcluded = async (externalId: string, exclude: boolean) => { const config = await getConfig(); const overrides = { ...config.gameOverrides }; const current = overrides[externalId] ?? {}; if (exclude) overrides[externalId] = { ...current, exclude: true }; else { const { exclude: _drop, ...rest } = current; if (Object.keys(rest).length) overrides[externalId] = rest; else delete overrides[externalId]; } await putConfig({ ...config, gameOverrides: overrides }); toast(exclude ? "Excluded" : "Included"); refresh(); }; if (!preview) return {loading ? "Scanning…" : "Loading…"}; const { entries, report } = preview; const excluded = report.excluded ?? []; return ( <> {loading ? "Scanning…" : "Rescan"} } > {entries.length === 0 && excluded.length === 0 ? (
No games found. Add ROM roots in Setup, then rescan.
) : (
{entries.map((e) => ( ))} {excluded.map((x) => ( ))}
Title Platform Launch command Include
{e.art?.portrait ? ( {`${e.title} ) : ( )} {e.title} {platformOf(e.external_id)} {truncate(e.launch?.value ?? "", 70)} setExcluded(e.external_id, true)} />
{x.title} {platformOf(x.external_id)} excluded setExcluded(x.external_id, false)} />
)}
{report.skipped.length > 0 && ( setShowSkipped((s) => !s)}> {showSkipped ? "Hide" : "Show"} } > {showSkipped && (
{report.skipped.map((s) => ( ))}
{s.title} {s.reason}
)}
)} ); }; const truncate = (s: string, n: number): string => s.length > n ? `${s.slice(0, n)}…` : s;