import { useEffect, useMemo, useState } from 'react' import { useTranslation } from '@shared/i18n/react' import { listAvatarHistory, type AvatarHistoryEntry } from '@features/account/api' type Props = { /** Bumped by the parent after each successful upload so the store is re-read. */ tick: number pending: boolean onPick: (blob: Blob) => void } /** The last few avatars cropped on this device (IndexedDB only, not the account's full history). */ export function AvatarHistoryStrip({ tick, pending, onPick }: Props) { const { t } = useTranslation('account') const [entries, setEntries] = useState([]) useEffect(() => { let active = true listAvatarHistory() .then((list) => active && setEntries(list)) .catch(() => active && setEntries([])) return () => { active = false } }, [tick]) if (entries.length === 0) return null return (

{t('avatar.historyHint')}

) } function HistoryThumb({ entry, disabled, onPick }: { entry: AvatarHistoryEntry; disabled: boolean; onPick: (blob: Blob) => void }) { const { t } = useTranslation('account') const url = useMemo(() => URL.createObjectURL(entry.blob), [entry]) useEffect(() => () => URL.revokeObjectURL(url), [url]) return ( ) }