import { useEffect, useState } from "react"; import { Link, useNavigate } from "react-router-dom"; import { api, type IntegrationSummary, type MaintenanceWindow, type ServerSummary } from "../api/client"; import { alertBadge, useAlertsReport } from "../hooks/useAlertsReport"; import { useEnvironment } from "../utils/environment"; import { formatRemaining } from "../utils/duration"; const REFRESH_MS = 30_000; const TYPE_LABELS: Record = { tailscale: "Tailscale", proxmox: "Proxmox", synology: "Synology", semaphore: "Semaphore", gitea: "Gitea", dockhand: "Docker", uptimekuma: "Uptime Kuma", phpipam: "phpIPAM", pbs: "Proxmox Backup", osticket: "osTicket", }; function useClock(): Date { const [now, setNow] = useState(() => new Date()); useEffect(() => { const t = setInterval(() => setNow(new Date()), 1000); return () => clearInterval(t); }, []); return now; } /** Keeps the screen awake while the page is open, where the browser allows it. */ function useWakeLock() { useEffect(() => { let lock: { release: () => Promise } | null = null; let gone = false; const request = async () => { try { const nav = navigator as Navigator & { wakeLock?: { request: (type: "screen") => Promise<{ release: () => Promise }> } }; if (nav.wakeLock && !gone) lock = await nav.wakeLock.request("screen"); } catch { // not allowed (battery saver, no permission): the screen may sleep like any other } }; void request(); const onVisible = () => document.visibilityState === "visible" && void request(); document.addEventListener("visibilitychange", onVisible); return () => { gone = true; document.removeEventListener("visibilitychange", onVisible); void lock?.release().catch(() => {}); }; }, []); } /** * A full-screen status board for a spare monitor or tablet: how things are, in type big enough to read across a room, refreshing * by itself. Nothing on it can be clicked into, so it can be left alone; Esc (or the corner link) goes back to the app. */ export default function Wall() { const navigate = useNavigate(); const environment = useEnvironment(); const now = useClock(); const { report, failed, reload } = useAlertsReport(); const [servers, setServers] = useState(null); const [integrations, setIntegrations] = useState(null); const [windows, setWindows] = useState([]); const [updatedAt, setUpdatedAt] = useState(null); const [idle, setIdle] = useState(false); useWakeLock(); useEffect(() => { let alive = true; const load = () => { reload(); Promise.allSettled([api.servers.summary(), api.integrations.list(), api.maintenance.list()]).then(([s, i, m]) => { if (!alive) return; if (s.status === "fulfilled") setServers(s.value); if (i.status === "fulfilled") setIntegrations(i.value.integrations); if (m.status === "fulfilled") setWindows(m.value.windows); setUpdatedAt(new Date()); }); }; load(); const t = setInterval(load, REFRESH_MS); return () => { alive = false; clearInterval(t); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, []); // Esc leaves; the pointer hides itself when nobody is using it. useEffect(() => { const onKey = (e: KeyboardEvent) => e.key === "Escape" && !document.fullscreenElement && navigate("/"); let timer: ReturnType; const onMove = () => { setIdle(false); clearTimeout(timer); timer = setTimeout(() => setIdle(true), 5000); }; onMove(); window.addEventListener("keydown", onKey); window.addEventListener("mousemove", onMove); return () => { window.removeEventListener("keydown", onKey); window.removeEventListener("mousemove", onMove); clearTimeout(timer); }; }, [navigate]); const badge = alertBadge(report); const blind = report?.couldntCheck.length ?? 0; const level: "critical" | "warning" | "ok" | "unsure" = !report ? "unsure" : badge ? badge.level : blind > 0 ? "unsure" : "ok"; const active = (report?.alerts ?? []).filter((a) => !a.silenced && a.severity !== "info").sort((a, b) => (a.severity === b.severity ? 0 : a.severity === "critical" ? -1 : 1)); const failing = (integrations ?? []).filter((i) => i.enabled && i.health?.status === "failing"); const offline = servers?.offline.length ?? 0; const headline = level === "critical" || level === "warning" ? `${badge!.count} ${badge!.count === 1 ? "thing needs" : "things need"} attention` : level === "unsure" ? report ? "No alerts — but some checks couldn't run" : failed ? "Can't reach the server" : "Checking…" : "All clear"; return (
Homelab Manager {environment?.name && {environment.name}}
{now.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}
{now.toLocaleDateString([], { weekday: "long", day: "numeric", month: "long" })}
{headline}
0 ? "wall-tile-bad" : ""}`}>
{servers ? (servers.online + offline === 0 ? "—" : `${servers.online}/${servers.online + offline}`) : "…"}
servers online
0 ? "wall-tile-bad" : (report?.counts.warning ?? 0) > 0 ? "wall-tile-warn" : ""}`}>
{report ? report.counts.critical + report.counts.warning : "…"}
alerts{report && report.counts.critical + report.counts.warning > 0 ? ` (${report.counts.critical} critical, ${report.counts.warning} warning)` : ""}
0 ? "wall-tile-info" : ""}`}>
{windows.length}
in maintenance
0 ? "wall-tile-bad" : ""}`}>
{integrations ? failing.length : "…"}
integrations failing

Needs attention

{active.length === 0 ? (
Nothing right now.
) : (
    {active.slice(0, 7).map((a) => (
  • {a.severity}: {a.message}
  • ))} {active.length > 7 &&
  • and {active.length - 7} more
  • }
)} {windows.length > 0 && ( <>

In maintenance

    {windows.map((w) => (
  • {w.targetName} · {formatRemaining(w.endsAt, now.getTime())} left
  • ))}
)}

Integrations

{(integrations ?? []).filter((i) => i.enabled).length === 0 ? (
None connected.
) : (
    {[...(integrations ?? [])] .filter((i) => i.enabled) .sort((a, b) => Number(b.health?.status === "failing") - Number(a.health?.status === "failing") || a.name.localeCompare(b.name)) .map((i) => { const status = i.health?.status; return (
  • {i.name}{" "} {TYPE_LABELS[i.type]} — {status === "failing" ? "failing" : status === "ok" ? "working" : "not checked yet"}
  • ); })}
)}
); }