import { useQuery } from '@tanstack/react-query' import { useCallback, useState } from 'react' import { settingsApi } from '../api/client' function fmtSize(bytes: number): string { if (bytes === 0) return '0 B' const units = ['B', 'KB', 'MB', 'GB', 'TB'] const i = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1) return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + units[i] } function fmtPercent(p: number): string { return p.toFixed(1) + '%' } function CopyPath({ path }: { path: string }) { const [copied, setCopied] = useState(false) const copy = useCallback(async () => { try { await navigator.clipboard.writeText(path) setCopied(true) setTimeout(() => setCopied(false), 1500) } catch {} }, [path]) return ( {path} {copied && ✓} ) } export default function Status() { const { data, isLoading, error } = useQuery({ queryKey: ['server-health'], queryFn: settingsApi.health, refetchInterval: 10000, }) if (isLoading) return
Loading status...
if (error) returnFailed to load status: {(error as Error).message}
if (!data) return null return (| Path | Exists | Writable |
|---|---|---|
|
|
|
| Path | Total | Free | Used |
|---|---|---|---|
| {fmtSize(d.total_bytes)} | {fmtSize(d.free_bytes)} | 90 ? 'text-red-400' : d.used_percent > 75 ? 'text-yellow-400' : ''}> {fmtPercent(d.used_percent)} |