import { useEffect, useState } from "react"; import { useParams } from "react-router-dom"; import { api, type PublicWall } from "../api/client"; import WallView, { REFRESH_MS, wallHeadline, type WallData } from "../components/WallView"; import { setDateTimeSettings } from "../utils/date"; /** * The wall display behind a share link: the same board, read-only and without signing in. The address carries the secret, and the * server decides how much it may show — this only draws what comes back. A link that doesn't work (never made, ended, taken back) * says so and stops asking. */ export default function SharedWall() { const { token = "" } = useParams(); const [wall, setWall] = useState(null); const [state, setState] = useState<"loading" | "ok" | "dead" | "unreachable">("loading"); const [updatedAt, setUpdatedAt] = useState(null); const [idle, setIdle] = useState(false); useEffect(() => { let alive = true; let timer: ReturnType | undefined; const load = () => api.publicWall .get(token) .then((w) => { if (!alive) return; setDateTimeSettings({ dateFormat: w.display.dateFormat as "ymd" | "dmy" | "mdy", timeFormat: w.display.timeFormat as "24h" | "12h" }); setWall(w); setUpdatedAt(new Date()); setState("ok"); }) .catch((err: unknown) => { if (!alive) return; const status = (err as { status?: number }).status; if (status === 404 || status === 429) { // 404: this link doesn't work (any more). Asking again would only repeat that. if (status === 404) { setState("dead"); if (timer) clearInterval(timer); } return; } setState((s) => (s === "ok" ? "ok" : "unreachable")); }); void load(); timer = setInterval(load, REFRESH_MS); return () => { alive = false; if (timer) clearInterval(timer); }; }, [token]); // The pointer hides itself when nobody is using it. useEffect(() => { let timer: ReturnType; const onMove = () => { setIdle(false); clearTimeout(timer); timer = setTimeout(() => setIdle(true), 5000); }; onMove(); window.addEventListener("mousemove", onMove); return () => { window.removeEventListener("mousemove", onMove); clearTimeout(timer); }; }, []); if (state === "dead") { return (
This link doesn't work any more
It may have ended or been taken back. Ask whoever gave it to you for a new one.
); } const count = wall ? wall.alerts.critical + wall.alerts.warning : 0; const data: WallData = { level: wall?.level ?? "unsure", headline: wallHeadline(wall?.level ?? "unsure", count, { loaded: !!wall, failed: state === "unreachable" }), servers: wall ? { online: wall.servers.online, total: wall.servers.online + wall.servers.offline } : null, alerts: wall ? wall.alerts : null, maintenance: wall?.maintenance ?? 0, integrationsFailing: wall ? wall.integrationsFailing : null, problems: wall?.problems ?? null, windows: wall?.maintenanceWindows ?? null, integrations: (wall?.integrations as WallData["integrations"]) ?? null, environmentName: wall?.environment ?? null, updatedAt, }; return ( void document.documentElement.requestFullscreen?.().catch(() => {})}> Full screen } /> ); }