import { Suspense, lazy, useEffect, useMemo } from "react" import { Card, CardContent, CardHeader, CardTitle } from "../ui/card" import { $alerts, $hubVersion, $systems, pb } from "@/lib/stores" import { useStore } from "@nanostores/react" import { GithubIcon } from "lucide-react" import { Separator } from "../ui/separator" import { alertInfo, updateRecordList, updateSystemList } from "@/lib/utils" import { AlertRecord, SystemRecord } from "@/types" import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" import { $router, Link } from "../router" import { Plural, t, Trans } from "@lingui/macro" import { getPagePath } from "@nanostores/router" const SystemsTable = lazy(() => import("../systems-table/systems-table")) export default function Home() { const hubVersion = useStore($hubVersion) const alerts = useStore($alerts) const systems = useStore($systems) const activeAlerts = useMemo(() => { const activeAlerts = alerts.filter((alert) => { const active = alert.triggered && alert.name in alertInfo if (!active) { return false } alert.sysname = systems.find((system) => system.id === alert.system)?.name return true }) return activeAlerts }, [alerts]) useEffect(() => { document.title = t`Dashboard` + " / Beszel" // make sure we have the latest list of systems updateSystemList() // subscribe to real time updates for systems / alerts pb.collection("systems").subscribe("*", (e) => { updateRecordList(e, $systems) }) // todo: add toast if new triggered alert comes in pb.collection("alerts").subscribe("*", (e) => { updateRecordList(e, $alerts) }) return () => { pb.collection("systems").unsubscribe("*") // pb.collection('alerts').unsubscribe('*') } }, []) return ( <> {/* show active alerts */} {activeAlerts.length > 0 && (
Active Alerts
{activeAlerts.length > 0 && (
{activeAlerts.map((alert) => { const info = alertInfo[alert.name as keyof typeof alertInfo] return ( {alert.sysname} {info.name().toLowerCase().replace("cpu", "CPU")} Exceeds {alert.value} {info.unit} in last ) })}
)}
)} {hubVersion && (
GitHub Beszel {hubVersion}
)} ) }