// Bin.jsx - what was deleted, and the two ways out of it. function Bin({ drive, toast, onChanged }) { const [entries, setEntries] = React.useState([]); const [busy, setBusy] = React.useState(true); const [days, setDays] = React.useState(30); const load = React.useCallback(async () => { setBusy(true); try { const r = await api.drive({ op: 'bin', drive }); setEntries(r.entries || []); setDays(r.purges_after_days || 30); } catch (err) { toast('error', err.message); } finally { setBusy(false); } }, [drive, toast]); React.useEffect(() => { load(); }, [load]); async function act(input, ok) { try { await api.drive(input); toast('ok', ok); load(); onChanged && onChanged(); } catch (err) { toast('error', err.message); } } function purge(e) { if (!window.confirm(`Delete ${e.name} permanently? This cannot be undone.`)) return; act({ op: 'purge', drive, id: e.id }, `${e.name} deleted permanently`); } function emptyAll() { if (!entries.length) return; if (!window.confirm(`Permanently delete all ${entries.length} items in the bin? This cannot be undone.`)) return; act({ op: 'empty-bin', drive }, 'Bin emptied'); } // Restoring can fail because the folder is gone or the name was reused while // the file sat here. Both are ordinary; offer the way out rather than just // reporting the refusal. async function restore(e) { try { await api.drive({ op: 'restore', drive, id: e.id }); toast('ok', `${e.name} restored`); load(); onChanged && onChanged(); } catch (err) { const name = window.prompt( `${err.message}\n\nRestore to the drive root under this name:`, e.name); if (!name) return; act({ op: 'restore', drive, id: e.id, to_path: '/', to_name: name }, `${name} restored to the root`); } } if (busy) { return
Loading…
; } if (!entries.length) { return (

The bin is empty.

Deleted files wait {days} days here before they go for good.

); } return ( <>
Deleted files are removed permanently after {days} days. They still count against your quota until then.
{entries.map(e => ( ))}
Name Was in Size Deleted
{e.name} {e.original_path} {e.kind === 'folder' ? '—' : humanBytes(e.size)} {whenText(e.deleted)}
); }