import {useEffect, useState} from 'react'; import {useTranslation} from 'react-i18next'; import {toast} from 'sonner'; import {Button} from '@/components/ui/button'; import GameCover from './GameCover.jsx'; import {fetchRemovedGames, restoreGame} from '../utils/manualGames.js'; /** * The games the user removed, in a closed `
`, one Restore button each. Shows nothing when there are none or * the list does not load: it is a safety net, not a page. */ export default function RemovedGamesSection() { const {t} = useTranslation(); const [games, setGames] = useState([]); const [busy, setBusy] = useState(false); useEffect(() => { let active = true; fetchRemovedGames().then(({ok, data}) => { if (active && ok) setGames(data.results); }); return () => { active = false; }; }, []); const restore = async (appid) => { setBusy(true); try { const response = await restoreGame(appid); if (response.status === 401) return; if (response.ok || response.status === 404) { setGames((current) => current.filter((game) => game.appid !== appid)); if (response.ok) toast.success(t('REMOVED_GAMES.RESTORED')); } else { toast.error(t('BACKLOG.SAVE_FAILED')); } } catch (err) { console.error('restore error:', err); toast.error(t('INFO.ERROR.NETWORK_FAILURE')); } finally { setBusy(false); } }; if (games.length === 0) return null; return (
{t('REMOVED_GAMES.TITLE_COUNT', {count: games.length})}

{t('REMOVED_GAMES.HINT')}

); }