A "What to do" note (text and/or link) can be written once for a whole kind of alert and shows beside every alert of that kind; alerts now carry their kind and source type. New optional setting: warn when a Docker host has N or more high vulnerabilities (off by default). The wall display gains tiles (Hetzner and game servers running, critical vulnerabilities, stuck downloads) and a summary line for each group of integrations, also in share links. Migration 0074; docs and tests included. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
112 lines
3.9 KiB
TypeScript
112 lines
3.9 KiB
TypeScript
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<PublicWall | null>(null);
|
|
const [state, setState] = useState<"loading" | "ok" | "dead" | "unreachable">("loading");
|
|
const [updatedAt, setUpdatedAt] = useState<Date | null>(null);
|
|
const [idle, setIdle] = useState(false);
|
|
|
|
useEffect(() => {
|
|
let alive = true;
|
|
let timer: ReturnType<typeof setInterval> | 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<typeof setTimeout>;
|
|
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 (
|
|
<div className="wall" data-bs-theme="dark">
|
|
<section className="wall-status wall-status-unsure" role="alert">
|
|
<span className="wall-status-symbol" aria-hidden="true">
|
|
?
|
|
</span>
|
|
<span>This link doesn't work any more</span>
|
|
</section>
|
|
<div className="wall-empty">It may have ended or been taken back. Ask whoever gave it to you for a new one.</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
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,
|
|
tiles: wall?.tiles,
|
|
groups: wall?.groups,
|
|
problems: wall?.problems ?? null,
|
|
windows: wall?.maintenanceWindows ?? null,
|
|
integrations: (wall?.integrations as WallData["integrations"]) ?? null,
|
|
environmentName: wall?.environment ?? null,
|
|
updatedAt,
|
|
};
|
|
|
|
return (
|
|
<WallView
|
|
data={data}
|
|
idle={idle}
|
|
footerActions={
|
|
<button type="button" className="wall-link" onClick={() => void document.documentElement.requestFullscreen?.().catch(() => {})}>
|
|
Full screen
|
|
</button>
|
|
}
|
|
/>
|
|
);
|
|
}
|