Accessibility: skip link, labelled landmarks, visible focus, page-change announcements, sortable headings as real buttons, every label tied to its field, named row checkboxes, and text contrast raised to 4.5:1 in both themes. Command palette: also runs actions (silence/end maintenance, theme, density, wall display, sign out) and is a proper dialog; g-then-letter shortcuts, "/" and "?". Row detail panel for six tables. Server Activity card, with the health check now recording offline/back-online and disk events in the audit log. Map page of hosts, servers, DNS names and monitors. Full-screen wall display. A getting-started checklist on the admin dashboard. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
239 lines
10 KiB
TypeScript
239 lines
10 KiB
TypeScript
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<IntegrationSummary["type"], string> = {
|
|
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<void> } | null = null;
|
|
let gone = false;
|
|
const request = async () => {
|
|
try {
|
|
const nav = navigator as Navigator & { wakeLock?: { request: (type: "screen") => Promise<{ release: () => Promise<void> }> } };
|
|
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<ServerSummary | null>(null);
|
|
const [integrations, setIntegrations] = useState<IntegrationSummary[] | null>(null);
|
|
const [windows, setWindows] = useState<MaintenanceWindow[]>([]);
|
|
const [updatedAt, setUpdatedAt] = useState<Date | null>(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<typeof setTimeout>;
|
|
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 (
|
|
<div className={`wall ${idle ? "wall-idle" : ""}`} data-bs-theme="dark">
|
|
<header className="wall-header">
|
|
<img src="/logo.webp" alt="Homelab Manager" width={901} height={460} className="wall-logo" />
|
|
{environment?.name && <span className="badge env-badge">{environment.name}</span>}
|
|
<div className="wall-clock" aria-label="Time">
|
|
<div className="wall-time">{now.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}</div>
|
|
<div className="wall-date">{now.toLocaleDateString([], { weekday: "long", day: "numeric", month: "long" })}</div>
|
|
</div>
|
|
</header>
|
|
|
|
<section className={`wall-status wall-status-${level}`} role="status" aria-live="polite">
|
|
<span className="wall-status-symbol" aria-hidden="true">
|
|
{level === "critical" ? "✕" : level === "warning" ? "▲" : level === "ok" ? "✓" : "?"}
|
|
</span>
|
|
<span>{headline}</span>
|
|
</section>
|
|
|
|
<section className="wall-tiles" aria-label="Summary">
|
|
<div className={`wall-tile ${offline > 0 ? "wall-tile-bad" : ""}`}>
|
|
<div className="wall-tile-figure">{servers ? (servers.online + offline === 0 ? "—" : `${servers.online}/${servers.online + offline}`) : "…"}</div>
|
|
<div className="wall-tile-label">servers online</div>
|
|
</div>
|
|
<div className={`wall-tile ${(report?.counts.critical ?? 0) > 0 ? "wall-tile-bad" : (report?.counts.warning ?? 0) > 0 ? "wall-tile-warn" : ""}`}>
|
|
<div className="wall-tile-figure">{report ? report.counts.critical + report.counts.warning : "…"}</div>
|
|
<div className="wall-tile-label">
|
|
alerts{report && report.counts.critical + report.counts.warning > 0 ? ` (${report.counts.critical} critical, ${report.counts.warning} warning)` : ""}
|
|
</div>
|
|
</div>
|
|
<div className={`wall-tile ${windows.length > 0 ? "wall-tile-info" : ""}`}>
|
|
<div className="wall-tile-figure">{windows.length}</div>
|
|
<div className="wall-tile-label">in maintenance</div>
|
|
</div>
|
|
<div className={`wall-tile ${failing.length > 0 ? "wall-tile-bad" : ""}`}>
|
|
<div className="wall-tile-figure">{integrations ? failing.length : "…"}</div>
|
|
<div className="wall-tile-label">integrations failing</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section className="wall-columns">
|
|
<div>
|
|
<h2 className="wall-heading">Needs attention</h2>
|
|
{active.length === 0 ? (
|
|
<div className="wall-empty">Nothing right now.</div>
|
|
) : (
|
|
<ul className="wall-list">
|
|
{active.slice(0, 7).map((a) => (
|
|
<li key={a.id} className={a.severity === "critical" ? "wall-bad" : "wall-warn"}>
|
|
<span aria-hidden="true">{a.severity === "critical" ? "✕" : "▲"}</span> <span className="visually-hidden">{a.severity}: </span>
|
|
{a.message}
|
|
</li>
|
|
))}
|
|
{active.length > 7 && <li className="wall-more">and {active.length - 7} more</li>}
|
|
</ul>
|
|
)}
|
|
{windows.length > 0 && (
|
|
<>
|
|
<h2 className="wall-heading mt-4">In maintenance</h2>
|
|
<ul className="wall-list wall-list-small">
|
|
{windows.map((w) => (
|
|
<li key={w.id}>
|
|
{w.targetName} <span className="wall-dim">· {formatRemaining(w.endsAt, now.getTime())} left</span>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</>
|
|
)}
|
|
</div>
|
|
<div>
|
|
<h2 className="wall-heading">Integrations</h2>
|
|
{(integrations ?? []).filter((i) => i.enabled).length === 0 ? (
|
|
<div className="wall-empty">None connected.</div>
|
|
) : (
|
|
<ul className="wall-list wall-list-small">
|
|
{[...(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 (
|
|
<li key={i.id} className={status === "failing" ? "wall-bad" : status === "ok" ? "wall-good" : "wall-dim"}>
|
|
<span aria-hidden="true">{status === "failing" ? "✕" : status === "ok" ? "✓" : "·"}</span> {i.name}{" "}
|
|
<span className="wall-dim">
|
|
{TYPE_LABELS[i.type]} — {status === "failing" ? "failing" : status === "ok" ? "working" : "not checked yet"}
|
|
</span>
|
|
</li>
|
|
);
|
|
})}
|
|
</ul>
|
|
)}
|
|
</div>
|
|
</section>
|
|
|
|
<footer className="wall-footer">
|
|
<span>
|
|
{updatedAt ? `Updated ${updatedAt.toLocaleTimeString()}` : "Loading…"} · refreshes every {REFRESH_MS / 1000} s
|
|
</span>
|
|
<span className="wall-footer-actions">
|
|
<button type="button" className="wall-link" onClick={() => void document.documentElement.requestFullscreen?.().catch(() => {})}>
|
|
Full screen
|
|
</button>
|
|
<Link to="/" className="wall-link">
|
|
Exit (Esc)
|
|
</Link>
|
|
</span>
|
|
</footer>
|
|
</div>
|
|
);
|
|
}
|