import { Eraser, Loader2, ScanSearch } from 'lucide-react'; import React from 'react'; import { useTranslation } from '../../../i18n'; import { formatBytes } from '../../../utils/formatBytes'; import { relativeTime } from '../../../utils/relativeTime'; import Section from '../../Settings/Section'; import ToggleSwitch from '../../Settings/ToggleSwitch'; import { SETTINGS_BUTTON, SettingRow, SettingRows, SettingsHint, StatusPill } from '../../Settings/settingsKit'; import { fs } from '../../shared/DialogShell'; import type { ReclaimCount, ReclaimView } from './reclaimModel'; interface Props { reclaim: ReclaimView; /** A check was asked for or is running. */ checking: boolean; /** The switch is on its way to the server. */ saving: boolean; onCheck: () => void; onDelete: (enabled: boolean) => void; /** The category whose confirmation is on its way. */ confirming: ReclaimView['lines'][number]['category'] | null; onConfirm: (request: { category: ReclaimView['lines'][number]['category']; unreferenced: number }) => void; } /** * Unreferenced files on the desktop storage panel: what the last check found, * the switch that lets the nightly run delete them, a check on demand and the * confirmation a category with an unusually large share of unused files waits * for. The phone shows the same through MStorageReclaimCard, off the same view model. */ export default function StorageReclaimSection({ reclaim, checking, saving, onCheck, onDelete, confirming, onConfirm, }: Props): React.ReactElement { const { t, locale } = useTranslation(); const count = (c: ReclaimCount) => t('storage.usage.line', { count: c.objects, size: formatBytes(c.bytes) }); const checked = reclaim.checkedAt !== null; return (
{checking ? ( ) : ( )} {checking ? t('storage.reclaim.running') : t('storage.reclaim.check')} } > onDelete(!reclaim.deleteEnabled)} label={t('storage.reclaim.delete')} disabled={saving} /> } />

{reclaim.checkedAt !== null ? t('storage.reclaim.checked', { age: relativeTime(reclaim.checkedAt, locale) }) : t('storage.reclaim.never')}

{reclaim.stopped && (

{t(reclaim.stopped === 'failed' ? 'storage.reclaim.stoppedFailed' : 'storage.reclaim.stopped')}

)} {checked && (
)} {checked && !reclaim.stopped && reclaim.lines.length === 0 && ( {t('storage.reclaim.nothing')} )} {reclaim.lines.length > 0 && (
    {reclaim.lines.map((line) => (
  • {t(`storage.category.${line.category}`)} {line.freeable.objects > 0 && ( {t('storage.reclaim.freeable')}: {count(line.freeable)} )} {line.waiting.objects > 0 && ( {t('storage.reclaim.waiting')}: {count(line.waiting)} )} {line.skipped && ( {t(`storage.reclaim.skip.${line.skipped}`)} )}
    {line.confirmationRequired && (

    {t('storage.reclaim.confirmNeeded')}

    )}
  • ))}
)}
); } function Figure({ label, value }: { label: string; value: string }): React.ReactElement { return (

{label}

{value}

); }