fix(diagnostics): count the 24 hours from the moment the level was raised

The countdown's clock was the moment Settings mounted, so a level raised
two minutes after opening the page read "24 h 2 m" until the first tick
(measured on prod). The clock is read at render; the interval only
re-renders.
This commit is contained in:
2026-09-19 05:03:31 +02:00
parent 2fa5c8c394
commit 6bbf532b70
2 changed files with 31 additions and 5 deletions
@@ -15,14 +15,17 @@ const LEVELS: readonly DiagnosticsLevel[] = ["INFO", "DEBUG", "TRACE"];
/** Hours and minutes until `until`, refreshed every 30 s — the status line counts down. */
function useRemaining(until: string | null): { h: number; m: number } | null {
const [now, setNow] = useState(() => Date.now());
// The clock is read at render, and the interval only re-renders: a `now` held in state was the
// moment the page MOUNTED, so a level raised two minutes after opening Settings read "24 h 2 m"
// until the first tick (prod UAT 2026-09-19).
const [, tick] = useState(0);
useEffect(() => {
if (!until) return;
const id = window.setInterval(() => setNow(Date.now()), 30_000);
const id = window.setInterval(() => tick((n) => n + 1), 30_000);
return () => window.clearInterval(id);
}, [until]);
if (!until) return null;
const minutes = Math.max(0, Math.ceil((Date.parse(until) - now) / 60_000));
const minutes = Math.max(0, Math.ceil((Date.parse(until) - Date.now()) / 60_000));
return { h: Math.floor(minutes / 60), m: minutes % 60 };
}