import { useEffect, useState } from 'hono/jsx' import { apps } from '../state' import { DashboardContainer, DashboardHeader, DashboardSubtitle, DashboardTitle, StatCard, StatLabel, StatValue, StatsGrid, } from '../styles' import { UnifiedLogs, type UnifiedLogLine } from './UnifiedLogs' import { Vitals } from './Vitals' interface SystemMetrics { cpu: number ram: { used: number, total: number, percent: number } disk: { used: number, total: number, percent: number } } export function DashboardLanding() { const [metrics, setMetrics] = useState({ cpu: 0, ram: { used: 0, total: 0, percent: 0 }, disk: { used: 0, total: 0, percent: 0 }, }) const [logs, setLogs] = useState([]) const regularApps = apps.filter(app => !app.tool) const toolApps = apps.filter(app => app.tool) const runningApps = apps.filter(app => app.state === 'running') // Subscribe to system metrics SSE useEffect(() => { const metricsSource = new EventSource('/api/system/metrics/stream') metricsSource.onmessage = e => { try { setMetrics(JSON.parse(e.data)) } catch {} } return () => metricsSource.close() }, []) // Subscribe to unified logs SSE useEffect(() => { const logsSource = new EventSource('/api/system/logs/stream') logsSource.onmessage = e => { try { const line = JSON.parse(e.data) as UnifiedLogLine setLogs((prev: UnifiedLogLine[]) => [...prev.slice(-199), line]) } catch {} } return () => logsSource.close() }, []) const handleClearLogs = async () => { try { await fetch('/api/system/logs/clear', { method: 'POST' }) setLogs([]) } catch {} } return ( Toes Your personal web appliance {regularApps.length} Apps {toolApps.length} Tools {runningApps.length} Running ) }