diff --git a/AppImage/components/hardware.tsx b/AppImage/components/hardware.tsx index 53e0b2a1..6ff29b63 100644 --- a/AppImage/components/hardware.tsx +++ b/AppImage/components/hardware.tsx @@ -163,14 +163,49 @@ const groupAndSortTemperatures = (temperatures: any[]) => { } export default function Hardware() { + // Static data - load once without refresh const { - data: hardwareData, - error, - isLoading, + data: staticHardwareData, + error: staticError, + isLoading: staticLoading, } = useSWR("/api/hardware", fetcher, { - refreshInterval: 5000, + revalidateOnFocus: false, + revalidateOnReconnect: false, + refreshInterval: 0, // No auto-refresh for static data }) + // Dynamic data - refresh every 5 seconds for temperatures, fans, power, ups + const { + data: dynamicHardwareData, + error: dynamicError, + isLoading: dynamicLoading, + } = useSWR("/api/hardware", fetcher, { + refreshInterval: 5000, // 5 second refresh for dynamic data + }) + + // Merge static and dynamic data, preferring static for CPU/memory/PCI/disks + const hardwareData = staticHardwareData + ? { + ...dynamicHardwareData, + // Keep static data from initial load + cpu: staticHardwareData.cpu, + motherboard: staticHardwareData.motherboard, + memory_modules: staticHardwareData.memory_modules, + pci_devices: staticHardwareData.pci_devices, + storage_devices: staticHardwareData.storage_devices, + gpus: staticHardwareData.gpus, + // Use dynamic data for these + temperatures: dynamicHardwareData?.temperatures, + fans: dynamicHardwareData?.fans, + power_meter: dynamicHardwareData?.power_meter, + power_supplies: dynamicHardwareData?.power_supplies, + ups: dynamicHardwareData?.ups, + } + : undefined + + const error = staticError || dynamicError + const isLoading = staticLoading + useEffect(() => { if (hardwareData?.storage_devices) { console.log("[v0] Storage devices data from backend:", hardwareData.storage_devices) diff --git a/AppImage/components/proxmox-dashboard.tsx b/AppImage/components/proxmox-dashboard.tsx index ec7cb8cb..88c4f0dc 100644 --- a/AppImage/components/proxmox-dashboard.tsx +++ b/AppImage/components/proxmox-dashboard.tsx @@ -27,6 +27,7 @@ import { Box, Cpu, FileText, + SettingsIcon, } from "lucide-react" import Image from "next/image" import { ThemeToggle } from "./theme-toggle" @@ -54,7 +55,7 @@ export function ProxmoxDashboard() { const [systemStatus, setSystemStatus] = useState({ status: "healthy", uptime: "Loading...", - lastUpdate: new Date().toLocaleTimeString(), + lastUpdate: new Date().toLocaleTimeString("en-US", { hour12: false }), serverName: "Loading...", nodeId: "Loading...", }) @@ -99,12 +100,15 @@ export function ProxmoxDashboard() { status = "warning" } + const uptimeValue = + data.uptime && typeof data.uptime === "string" && data.uptime.trim() !== "" ? data.uptime : "N/A" + setSystemStatus({ status, - uptime: data.uptime, - lastUpdate: new Date().toLocaleTimeString(), - serverName: data.hostname, - nodeId: data.node_id, + uptime: uptimeValue, + lastUpdate: new Date().toLocaleTimeString("en-US", { hour12: false }), + serverName: data.hostname || "Unknown", + nodeId: data.node_id || "Unknown", }) setIsServerConnected(true) } catch (error) { @@ -122,16 +126,27 @@ export function ProxmoxDashboard() { serverName: "Server Offline", nodeId: "Server Offline", uptime: "N/A", - lastUpdate: new Date().toLocaleTimeString(), + lastUpdate: new Date().toLocaleTimeString("en-US", { hour12: false }), })) } }, []) useEffect(() => { + // Siempre fetch inicial fetchSystemData() - const interval = setInterval(fetchSystemData, 10000) - return () => clearInterval(interval) - }, [fetchSystemData]) + + // Solo hacer polling si estamos en overview + let interval: ReturnType | null = null + if (activeTab === "overview") { + interval = setInterval(fetchSystemData, 10000) + } else { + interval = setInterval(fetchSystemData, 60000) + } + + return () => { + if (interval) clearInterval(interval) + } + }, [fetchSystemData, activeTab]) useEffect(() => { if ( @@ -217,6 +232,8 @@ export function ProxmoxDashboard() { return "Hardware" case "logs": return "System Logs" + case "settings": + return "Settings" default: return "Navigation Menu" } @@ -300,7 +317,9 @@ export function ProxmoxDashboard() { {systemStatus.status} -
Uptime: {systemStatus.uptime}
+
+ Uptime: {systemStatus.uptime || "N/A"} +
+ @@ -540,6 +580,10 @@ export function ProxmoxDashboard() { + + + +