import { useEffect, useState, type ReactNode } from "react"; import { formatDate, formatTime } from "../utils/date"; import { formatRemaining } from "../utils/duration"; export 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", }; export type WallLevel = "critical" | "warning" | "ok" | "unsure"; /** Everything the board shows. A list that is null is not shown on this board (a share link that only gives numbers). */ export interface WallData { level: WallLevel; headline: string; servers: { online: number; total: number } | null; alerts: { critical: number; warning: number } | null; maintenance: number; integrationsFailing: number | null; problems: { id: string; severity: "critical" | "warning"; message: string }[] | null; windows: { id: number; name: string; endsAt: string }[] | null; integrations: { id: number; name: string; type: string; status: "ok" | "failing" | "unknown" }[] | null; environmentName: string | null; updatedAt: Date | null; } /** The headline in words for how many things need a look, or why there is no answer yet. */ export function wallHeadline(level: WallLevel, count: number, state: { loaded: boolean; failed: boolean }): string { if (level === "critical" || level === "warning") return `${count} ${count === 1 ? "thing needs" : "things need"} attention`; if (level === "unsure") return state.loaded ? "No alerts — but some checks couldn't run" : state.failed ? "Can't reach the server" : "Checking…"; return "All clear"; } 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(() => {}); }; }, []); } /** * The board itself: a full-screen status picture in type big enough to read across a room. It only draws what it is given, so the * signed-in wall and the one a share link opens look the same and can't drift apart. */ export default function WallView({ data, idle, footerActions }: { data: WallData; idle: boolean; footerActions: ReactNode }) { const now = useClock(); useWakeLock(); const { level } = data; const offline = data.servers ? data.servers.total - data.servers.online : 0; const alertCount = data.alerts ? data.alerts.critical + data.alerts.warning : 0; const showsDetail = data.problems !== null || data.windows !== null || data.integrations !== null; return (
Homelab Manager {data.environmentName && {data.environmentName}}
{formatTime(now, false)}
{now.toLocaleDateString([], { weekday: "long" })} {formatDate(now)}
{data.headline}
0 ? "wall-tile-bad" : ""}`}>
{data.servers ? (data.servers.total === 0 ? "—" : `${data.servers.online}/${data.servers.total}`) : "…"}
servers online
0 ? "wall-tile-bad" : (data.alerts?.warning ?? 0) > 0 ? "wall-tile-warn" : ""}`}>
{data.alerts ? alertCount : "…"}
alerts{data.alerts && alertCount > 0 ? ` (${data.alerts.critical} critical, ${data.alerts.warning} warning)` : ""}
0 ? "wall-tile-info" : ""}`}>
{data.maintenance}
in maintenance
0 ? "wall-tile-bad" : ""}`}>
{data.integrationsFailing === null ? "…" : data.integrationsFailing}
integrations failing
{showsDetail ? (
{data.problems && ( <>

Needs attention

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

In maintenance

    {data.windows.slice(0, 8).map((w) => (
  • {w.name} · {formatRemaining(w.endsAt, now.getTime())} left
  • ))} {data.maintenance > 8 &&
  • and {data.maintenance - 8} more
  • }
)}
{data.integrations && ( <>

Integrations

{data.integrations.length === 0 ? (
None connected.
) : (
    {data.integrations.map((i) => (
  • {i.name}{" "} {TYPE_LABELS[i.type] ?? i.type} — {i.status === "failing" ? "failing" : i.status === "ok" ? "working" : "not checked yet"}
  • ))}
)} )}
) : (
This board shows the numbers only.
)}
); }