About 1,600 more headings, buttons, table columns, status words, placeholders and short messages are translated. Tables of words built when the app loads are now read when they are drawn, so they follow the language, and a test fails if text is translated at load time. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
120 lines
4.5 KiB
TypeScript
120 lines
4.5 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";
|
|
import { useWallRotation } from "../hooks/useWallRotation";
|
|
import { t } from "../i18n";
|
|
|
|
/**
|
|
* 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);
|
|
// The named display this link opens, once the board has been read: its pages and its speed.
|
|
const [displayConfig, setDisplayConfig] = useState<PublicWall["displayConfig"]>(null);
|
|
const rotation = useWallRotation(displayConfig?.rotateSeconds ?? null);
|
|
|
|
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);
|
|
setDisplayConfig(w.displayConfig ?? null);
|
|
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>{t("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}
|
|
display={displayConfig ? { name: displayConfig.name, pages: displayConfig.pages, night: displayConfig.night } : null}
|
|
rotation={{ seconds: rotation.seconds, onChange: rotation.setSeconds }}
|
|
footerActions={
|
|
<button type="button" className="wall-link" onClick={() => void document.documentElement.requestFullscreen?.().catch(() => {})}>
|
|
{t("Full screen")}
|
|
</button>
|
|
}
|
|
/>
|
|
);
|
|
}
|