diff --git a/web/src/components/Dashboard.jsx b/web/src/components/Dashboard.jsx index cea51de..9c567c0 100644 --- a/web/src/components/Dashboard.jsx +++ b/web/src/components/Dashboard.jsx @@ -43,7 +43,7 @@ export default function Dashboard({ api, refreshRef }) { const [recentCmds, setRecentCmds] = useState([]) const [processes, setProcesses] = useState([]) const [metrics, setMetrics] = useState(null) - const [copiedIdx, setCopiedIdx] = useState(-1) + const [copiedSet, setCopiedSet] = useState(new Set()) const cpuRef = useRef([]) const memRef = useRef([]) const netRxRef = useRef([]) @@ -109,6 +109,23 @@ export default function Dashboard({ api, refreshRef }) { .map(([cmd, count]) => ({ cmd, count })) })() + const maxCount = topCmds.length > 0 ? topCmds[0].count : 1 + + const copyCmd = (cmd, key) => { + navigator.clipboard.writeText(cmd) + setCopiedSet(prev => new Set(prev).add(key)) + setTimeout(() => setCopiedSet(prev => { const next = new Set(prev); next.delete(key); return next }), 1500) + } + + const relativeTime = (ts) => { + if (!ts) return '' + const diff = Math.floor((Date.now() - new Date(ts).getTime()) / 1000) + if (diff < 60) return `${diff}s` + if (diff < 3600) return `${Math.floor(diff / 60)}m` + if (diff < 86400) return `${Math.floor(diff / 3600)}h` + return `${Math.floor(diff / 86400)}d` + } + const recentUnique = (() => { const seen = new Set() return recentCmds.filter(c => {