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

+95
View File
@@ -0,0 +1,95 @@
/* The one place that talks to the server.
*
* Same-origin by design: in development Vite proxies /api to port 8090, in
* production Caddy serves this bundle and the API from the same hostname.
* That means session cookies behave identically in both, and there is no CORS
* configuration anywhere.
*/
export class ApiError extends Error {
readonly status: number;
readonly body: unknown;
constructor(status: number, message: string, body: unknown) {
super(message);
this.name = "ApiError";
this.status = status;
this.body = body;
}
/** True when the endpoint is simply not built yet (Phase 2 / Phase 3). */
get isMissingEndpoint(): boolean {
return this.status === 404;
}
}
async function request<T>(path: string, init?: RequestInit): Promise<T> {
let response: Response;
try {
response = await fetch(`/api/v1${path}`, {
credentials: "same-origin",
headers: { Accept: "application/json", ...init?.headers },
...init,
});
} catch (cause) {
// fetch only rejects on a network-level failure: server down, DNS, CORS.
throw new ApiError(0, `Cannot reach the server: ${String(cause)}`, null);
}
const text = await response.text();
let body: unknown = null;
if (text.length > 0) {
try {
body = JSON.parse(text);
} catch {
body = text;
}
}
if (!response.ok) {
throw new ApiError(response.status, `${response.status} ${response.statusText}`, body);
}
return body as T;
}
export function apiGet<T>(path: string): Promise<T> {
return request<T>(path);
}
export function apiPost<T>(path: string, payload?: unknown): Promise<T> {
return request<T>(path, {
method: "POST",
headers: payload === undefined ? {} : { "Content-Type": "application/json" },
body: payload === undefined ? undefined : JSON.stringify(payload),
});
}
/* --- response types ---------------------------------------------------
* These mirror the server. Keep them in step with the FastAPI handlers;
* generating them from /openapi.json is a worthwhile upgrade once there are
* more than a handful. */
export interface HealthResponse {
status: "ok" | "degraded";
version: string;
uptime_s: number;
database: {
ok: boolean;
error: string | null;
devices?: number;
captures?: number;
last_backup_at?: string | null;
};
disk: {
available: boolean;
path: string;
total_bytes?: number;
free_bytes?: number;
used_pct?: number | null;
};
enroll_secret_configured: boolean;
}
export function getHealth(): Promise<HealthResponse> {
return apiGet<HealthResponse>("/health");
}