'use client'; import { useEffect, useState } from 'react'; import VMCard from '@/components/VMCard'; import UserMenu from '@/components/UserMenu'; import Skeleton from '@/components/ui/Skeleton'; interface VM { vmid: string; name: string; status: string; mem: string; bootdisk: string; } export default function Dashboard() { const [vms, setVms] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const fetchVMs = async () => { try { const res = await fetch('/api/vms'); if (!res.ok) throw new Error('Failed to fetch VMs'); const data = await res.json(); setVms(data.vms); setError(null); } catch (err) { setError(err instanceof Error ? err.message : 'Unknown error'); } finally { setLoading(false); } }; useEffect(() => { fetchVMs(); const interval = setInterval(fetchVMs, 5000); return () => clearInterval(interval); }, []); const runningCount = vms.filter(vm => vm.status === 'running').length; return (
{/* Header */}

NEXUS

VM Control Center

{!loading && (
{vms.length} VMs ยท {runningCount} Running
)}
{/* Main Content */}
{error && (

Error: {error}

)} {loading ? (
{[1, 2, 3].map((i) => ( ))}
) : (
{vms.map((vm) => ( ))}
)}
); }