UI: scaffold the web app - shell, themes, i18n, auth plumbing

React 19 + TypeScript + Vite + TanStack Query/Router in web/, built on the
dev machine and shipped as static files (SPEC section 6). Typechecks and
builds clean; the System page reads live /health through the Vite proxy,
which proves browser -> proxy -> FastAPI -> PostgreSQL end to end.

Themes: light, dark and blue (dark navy), as design tokens on data-theme.
An inline script applies the stored theme before first paint. No colour
literal lives outside tokens.css.

check-contrast.mjs asserts WCAG AA for every text/background pair in every
theme, with no dependencies. It failed on its first run and found three
--border-strong values below the 3:1 that WCAG 1.4.11 wants for interactive
boundaries; all three are fixed and 36 pairs now pass. Colour contrast is
the classic silently-regressing property, so it gets a test rather than a
promise.

i18n is hand-written and typed rather than react-i18next: en.ts defines the
key set, de.ts is typed against it, so a missing German string fails the
build instead of quietly showing English to a German user.

Authentication is built but NOT enforced, deliberately. /auth/session,
/auth/login and /auth/logout do not exist yet, so router.tsx does not wrap
routes in RequireAuth and a banner says so plainly. There is no development
bypass: a bypass that works is the kind of code that survives into
production, and an auth bypass that works is the worst possible bug.

Gallery and Devices render honest empty states rather than mock rows. Fake
data hides the layout problems real data exposes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Thomas KarnerandClaude Opus 5 committed 2026-09-21 01:17:07 +02:00
1 parent 5a098e44d8
commit 384b09371a
28 files changed
+3968 -1

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
import { EmptyState } from "../components/EmptyState";
import { useT } from "../i18n/I18nProvider";
export function DevicesPage() {
const t = useT();
return (
<section>
<h1 className="page-title">{t("devices.title")}</h1>
<EmptyState title={t("devices.empty.title")} body={t("devices.empty.body")} />
</section>
);
}
+16
View File
@@ -0,0 +1,16 @@
import { EmptyState } from "../components/EmptyState";
import { useT } from "../i18n/I18nProvider";
/* The gallery. Phase 2 gives it something to show; until /captures exists
* there is nothing to fetch, so this is honestly empty rather than filled
* with fake rows that would hide layout problems. */
export function GalleryPage() {
const t = useT();
return (
<section>
<h1 className="page-title">{t("gallery.title")}</h1>
<EmptyState title={t("gallery.empty.title")} body={t("gallery.empty.body")} />
</section>
);
}
+141
View File
@@ -0,0 +1,141 @@
import { useQuery } from "@tanstack/react-query";
import { useT } from "../i18n/I18nProvider";
import { getHealth } from "../lib/api";
import type { HealthResponse } from "../lib/api";
import type { Translate } from "../i18n/I18nProvider";
/* The only page wired to real data at Phase 3, because /health is the only
* endpoint that exists. That makes it the end-to-end proof: browser ->
* Vite proxy -> FastAPI -> PostgreSQL and back. */
function formatBytes(bytes: number | undefined): string {
if (bytes === undefined) return "—";
const units = ["B", "KB", "MB", "GB", "TB"];
let value = bytes;
let unit = 0;
while (value >= 1024 && unit < units.length - 1) {
value /= 1024;
unit += 1;
}
return `${value.toFixed(value < 10 && unit > 0 ? 1 : 0)} ${units[unit]}`;
}
function formatUptime(seconds: number): string {
const s = Math.floor(seconds);
if (s < 60) return `${s}s`;
const m = Math.floor(s / 60);
if (m < 60) return `${m}m ${s % 60}s`;
const h = Math.floor(m / 60);
if (h < 24) return `${h}h ${m % 60}m`;
return `${Math.floor(h / 24)}d ${h % 24}h`;
}
function Row({ label, children }: { label: string; children: React.ReactNode }) {
return (
<div className="row">
<dt className="row-label">{label}</dt>
<dd className="row-value">{children}</dd>
</div>
);
}
function HealthDetail({ health, t }: { health: HealthResponse; t: Translate }) {
const dbOk = health.database.ok;
return (
<>
<div className="card">
<dl className="rows">
<Row label={t("system.status")}>
<span className={dbOk ? "pill pill-ok" : "pill pill-warn"}>
{health.status === "ok" ? t("system.status.ok") : t("system.status.degraded")}
</span>
</Row>
<Row label={t("system.version")}>
<code>{health.version}</code>
</Row>
<Row label={t("system.uptime")}>{formatUptime(health.uptime_s)}</Row>
<Row label={t("system.enrollSecret")}>
{health.enroll_secret_configured ? (
t("system.enrollSecret.set")
) : (
<span className="warn">{t("system.enrollSecret.unset")}</span>
)}
</Row>
</dl>
</div>
<div className="card">
<dl className="rows">
<Row label={t("system.database")}>
<span className={dbOk ? "pill pill-ok" : "pill pill-danger"}>
{dbOk ? t("system.database.ok") : t("system.database.down")}
</span>
{health.database.error !== null && (
<div className="mono-small">{health.database.error}</div>
)}
</Row>
<Row label={t("system.devices")}>{health.database.devices ?? "—"}</Row>
<Row label={t("system.captures")}>{health.database.captures ?? "—"}</Row>
<Row label={t("system.lastBackup")}>
{health.database.last_backup_at ? (
new Date(health.database.last_backup_at).toLocaleString()
) : (
/* Not an error yet -- backups are Phase 5 and blocked on the
NAS protocol question. It becomes an alarm then, not now. */
<span className="muted">{t("system.lastBackup.never")}</span>
)}
</Row>
</dl>
</div>
<div className="card">
<dl className="rows">
<Row label={t("system.disk")}>
{health.disk.available ? (
<>
{t("system.disk.free", {
free: formatBytes(health.disk.free_bytes),
total: formatBytes(health.disk.total_bytes),
})}
<div className="mono-small">{health.disk.path}</div>
</>
) : (
<span className="warn">{t("system.disk.unavailable")}</span>
)}
</Row>
</dl>
</div>
</>
);
}
export function SystemPage() {
const t = useT();
const { data, error, isPending, refetch } = useQuery({
queryKey: ["health"],
queryFn: getHealth,
refetchInterval: 15_000,
retry: false,
});
return (
<section>
<h1 className="page-title">{t("system.title")}</h1>
{isPending && <p className="muted">{t("common.loading")}</p>}
{error !== null && !isPending && (
<div className="card">
<h2 className="empty-title">{t("system.unreachable.title")}</h2>
<p className="empty-body">{t("system.unreachable.body")}</p>
<button className="button" onClick={() => void refetch()}>
{t("common.retry")}
</button>
</div>
)}
{data !== undefined && <HealthDetail health={data} t={t} />}
</section>
);
}