import {useEffect, useState} from 'react'; import {useTranslation} from 'react-i18next'; import {Trophy} from 'lucide-react'; import {Card} from '@/components/ui/card'; import FitText from './FitText.jsx'; import GameCover from './GameCover.jsx'; import GameStatusBadge from './GameStatusBadge.jsx'; import {formatPlaytime} from '../utils/games.js'; import {fetchProfileGame} from '../utils/people.js'; /** * One game of a public profile, above its tiles. Shows what the profile shares of it; a game the user hides or does * not have gets one message. */ export default function ProfileGameCard({ticket, appid}) { const {t, i18n} = useTranslation(); const [game, setGame] = useState(null); const [missing, setMissing] = useState(false); useEffect(() => { let cancelled = false; setGame(null); setMissing(false); (async () => { const {ok, data} = await fetchProfileGame(ticket, appid); if (cancelled) return; if (ok) setGame(data); else setMissing(true); })(); return () => { cancelled = true; }; }, [ticket, appid]); if (missing) { return {t('PROFILE.GAME_NOT_SHOWN')}; } if (!game) return null; return (
{game.status && } {game.playtimeMinutes != null && {formatPlaytime(game.playtimeMinutes)}} {game.achievementsTotal != null && ( {t('PROFILE.GAME_ACHIEVEMENTS', { unlocked: game.achievementsUnlocked, total: game.achievementsTotal, percent: game.completionPercent.toLocaleString(i18n.language), })} )}
); }