'use client'; import { PageShell } from '@/components/layout/PageShell'; import { Button } from '@/components/ui/Button'; import { Panel } from '@/components/ui/Panel'; import { StatStrip } from '@/components/ui/StatStrip'; import { Table, TableBody, TableCell, TableEmpty, TableHead, TableHeader, TableRow, TableWrap, } from '@/components/ui/Table'; import { useToast } from '@/components/ui/Toast'; import { getCached, setCached } from '@/lib/vconCache'; import { useCallback, useEffect, useState } from 'react'; export default function StoragePage() { const { success, error } = useToast(); const [stats, setStats] = useState(() => getCached('vcon:storage-stats', null) ); const [files, setFiles] = useState(() => getCached('vcon:storage-files', []) ); const [flushing, setFlushing] = useState(false); const fetchStorageData = useCallback(async () => { try { const res = await fetch('/api/storage'); if (!res.ok) throw new Error('Unable to load storage partitions'); const data = await res.json(); setStats(setCached('vcon:storage-stats', data.stats)); setFiles(setCached('vcon:storage-files', data.files || [])); } catch { error('Storage load failed', 'Could not load storage partitions.'); } }, [error]); useEffect(() => { fetchStorageData(); }, [fetchStorageData]); const handleManualFlush = async () => { setFlushing(true); try { const res = await fetch('/api/storage', { method: 'POST' }); if (res.ok) { const data = await res.json(); success('Buffer Flushed', `Flushed ${data.flushedCount} events to CSV`); fetchStorageData(); } else { error('Flush Failed', 'Could not flush buffer'); } } catch (err: any) { error('Error', err.message); } finally { setFlushing(false); } }; return ( } > Client Filename Size Rows Modified {files.length === 0 ? ( ) : ( files.map((file, idx) => ( {file.clientId} {file.filename} {(file.sizeBytes / 1024).toFixed(1)} KB {file.linesCount.toLocaleString()} {new Date(file.modifiedAt).toLocaleString()} )) )}
); }