The client half. The gallery now reads real captures, pages by cursor and loads thumbnails through the auth-checked route, so an image is only ever served to a request that carried a valid session. Virtualised because the gallery is the one screen that grows without bound. 5000 captures a day is past a million DOM nodes inside a year, and the browser gives up long before the database does. react-virtual virtualises a list rather than a grid, so the grid is a list of rows whose column count is computed from the measured container width - which also makes it responsive without a media-query ladder, and is why the width is observed rather than assumed. A ResizeObserver rather than a window resize listener, because the filter panel changes that element's width without the window changing at all. Filters cover what the server can answer: date range, device, kept, reviewed, pre-trigger. Taxon and tag are deliberately absent until taxa is seeded and the observation editor exists, for the same reason they are absent from the endpoint. The triage filters are tri-state selects rather than checkboxes, because "kept" has three meanings - everything, only kept, only rejected - and a checkbox expresses two of them. Filters are part of the query key, so changing one starts fresh pagination instead of appending. A cursor from the previous filter set describes a position in a list that no longer exists. The viewer is keyboard-driven on purpose. Labelling a day of captures is look-decide-next a few hundred times, and that loop is only bearable from the keyboard. It steps only through what is already loaded, and the button is disabled at the edge rather than showing a blank frame while a page arrives. Two contract details the UI has to get right, both now carried in code with the reason attached: captured_at_device is null when the camera's clock was unsynced and is rendered as "not synced" rather than as 1970 (API.md, X-Captured-At: 0), and a model-sourced observation is badged as a prediction, because that table is also the training data for any future model and a prediction shown as a human label would poison it. has_thumb is why the summary carries it: the grid shows a placeholder for a capture whose thumbnail job has not run, instead of a broken image. Conventions held: no user-facing string literal in a component - 60-odd new keys in en.ts and de.ts, and the typed catalogue makes a missing German string a build error rather than English in front of a German user. No colour literal outside tokens.css either; the one place that wanted rgba() uses color-mix against a token instead. 36 contrast pairs across three themes still pass. Verified against the real stack with 506 real captures through the Vite proxy, which is the path the browser takes: 9 pages of 60 following the cursor, all 506 seen, zero duplicates across pages that include real burst timestamp ties, 0.28s for the lot, and 12 of 12 sampled thumbnails arriving as valid WebP. Not verified: how it looks. I have no browser here, so the layout, the scroll behaviour and the virtualisation actually recycling rows are unconfirmed by eye. Typecheck, build and the data path are green; the visual pass is yours. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
158 lines
6.3 KiB
Markdown
158 lines
6.3 KiB
Markdown
# poorBird web
|
|
|
|
Phase 3 scaffolding: shell, themes, i18n and the auth plumbing. Built on the
|
|
dev machine and shipped to the server as static files — nothing here runs on
|
|
the server (SPEC §6).
|
|
|
|
```bash
|
|
cd web
|
|
npm install
|
|
npm run dev # http://localhost:5173
|
|
```
|
|
|
|
The dev server proxies `/api` to `http://127.0.0.1:8090`, so start the API
|
|
too (see [`../server/README.md`](../server/README.md)). Both must be running
|
|
or the System page shows "cannot reach the server", which is the honest
|
|
answer rather than a blank screen.
|
|
|
|
**Two things the server side needs before you can sign in:**
|
|
|
|
```bash
|
|
cd ../server
|
|
# 1. Secure cookies are dropped over plain http, and this dev server is http.
|
|
# Without this, login returns 200 and you are never signed in.
|
|
echo 'POORBIRD_SESSION_COOKIE_SECURE=false' >> .env
|
|
|
|
# 2. There is no sign-up page. Accounts are created on the server.
|
|
.venv/Scripts/poorbird user add me --role admin
|
|
```
|
|
|
|
`--role admin` enables TOTP and prints an `otpauth://` URI once — scan it
|
|
before pressing on, because the app will ask for a code and the URI is not
|
|
shown again. `--no-totp` skips it and says why that is a bad idea.
|
|
|
|
| Script | Does |
|
|
|---|---|
|
|
| `npm run dev` | Vite dev server with HMR |
|
|
| `npm run build` | typecheck, then production bundle into `dist/` |
|
|
| `npm run typecheck` | `tsc --noEmit` on its own |
|
|
| `npm run check:contrast` | assert WCAG contrast for all three themes |
|
|
|
|
> On Windows, Vite binds IPv6 `localhost`. Use `http://localhost:5173`, not
|
|
> `http://127.0.0.1:5173`.
|
|
|
|
---
|
|
|
|
## What is real and what is not
|
|
|
|
**Authentication is real and enforced.** `/auth/session`, `/auth/login` and
|
|
`/auth/logout` exist, so every route is now behind `RequireAuth`:
|
|
|
|
- the gallery needs any signed-in user; **Devices and System need `admin`**
|
|
(SPEC §3.1), so a `viewer` account sees a "no access" message there
|
|
- TOTP is required whenever the account has a secret, which `user add --role
|
|
admin` sets up by default
|
|
- signing out is in the header, next to the theme and language switchers
|
|
- **there is still no development bypass**, and there never was one — a bypass
|
|
that works is the kind of code that survives into production
|
|
|
|
The guard here decides what to *render*. It is not access control: the server
|
|
authorises every request on its own, and deleting `RequireAuth.tsx` would
|
|
expose no data, it would only render pages whose requests then 401.
|
|
|
|
**The gallery is real.** It reads `GET /api/v1/captures`, pages by cursor,
|
|
and loads thumbnails through the auth-checked route — so an image is only
|
|
served to a request that carried a valid session.
|
|
|
|
To have something to look at:
|
|
|
|
```bash
|
|
cd ../server
|
|
.venv/Scripts/poorbird seed --captures 500
|
|
.venv/Scripts/poorbird seed --clear # when you are done
|
|
```
|
|
|
|
`--clear` only ever removes seeded data. It is scoped to its own device, so a
|
|
real camera's captures are never in scope.
|
|
|
|
**Devices still renders an honest empty state.** It needs a device listing
|
|
endpoint, which is Phase 4. It is deliberately not filled with mock rows —
|
|
fake data hides exactly the layout problems real data exposes.
|
|
|
|
The grid is virtualised, which matters at the scale this reaches rather than
|
|
the scale it starts at: 5000 captures a day is past a million DOM nodes within
|
|
a year, and the browser gives up long before the database does. Only visible
|
|
rows exist, and the column count is computed from the measured container width
|
|
rather than from media queries.
|
|
|
|
---
|
|
|
|
## Conventions
|
|
|
|
**No user-facing string literal in a component. Ever.** Every one goes
|
|
through `useT()`. `src/i18n/en.ts` defines the key set; `de.ts` is typed as
|
|
`Catalogue`, so a missing or misspelled German key fails `npm run build`
|
|
rather than showing English to a German user at runtime.
|
|
|
|
**No colour literal outside `src/styles/tokens.css`.** Components reference
|
|
tokens, which is what makes a fourth theme a single CSS block. Run
|
|
`npm run check:contrast` after touching any colour — it caught three failing
|
|
`--border-strong` values the first time it ran.
|
|
|
|
**`lib/api.ts` is the only place that calls `fetch`,** and the only place that
|
|
knows about CSRF. It reads the `poorbird_csrf` cookie and echoes it in
|
|
`X-CSRF-Token` on every POST/PUT/PATCH/DELETE; the server compares it against
|
|
the token stored on the session row. A new mutating call needs nothing extra,
|
|
which is the point of there being one such place.
|
|
|
|
**Themes** are `data-theme` on `<html>`: `light`, `dark`, `blue` (dark navy).
|
|
An inline script in `index.html` applies the stored choice before first paint
|
|
to avoid a flash of the wrong theme; it must stay in sync with
|
|
`theme/ThemeProvider.tsx` — same storage key, same attribute, same default.
|
|
Once accounts exist, `users.theme` becomes the source of truth and
|
|
localStorage stays as the pre-login default.
|
|
|
|
---
|
|
|
|
## Layout
|
|
|
|
```
|
|
src/
|
|
main.tsx providers, in order
|
|
router.tsx the whole route table, one flat file
|
|
i18n/ en.ts (source of truth), de.ts (typed against it)
|
|
theme/ data-theme on <html>
|
|
auth/ provider, login form, route guard
|
|
lib/api.ts the only place that calls fetch, and the only one
|
|
that knows about CSRF or builds image URLs
|
|
components/ layout, shared pieces, CaptureGrid, CaptureViewer,
|
|
GalleryFilters
|
|
pages/ one per route
|
|
styles/ tokens.css (themes), global.css (everything else)
|
|
scripts/check-contrast.mjs
|
|
```
|
|
|
|
---
|
|
|
|
## Notes on the stack
|
|
|
|
**TypeScript is strict**, including `noUncheckedIndexedAccess` and
|
|
`verbatimModuleSyntax`. Learning TypeScript with the checks off teaches a
|
|
different language than the one everyone else writes. The error messages say
|
|
what to do.
|
|
|
|
**i18n is hand-written, not `react-i18next`.** Two languages and a few hundred
|
|
strings do not need a library, and the typed catalogue gives compile-time
|
|
completeness that i18next does not provide by default. If real plural grammar
|
|
is ever needed, ICU MessageFormat is the upgrade and the call sites keep their
|
|
shape.
|
|
|
|
**TanStack Router with code-based routes**, per SPEC §6, rather than the
|
|
file-based convention — one visible route table, no codegen step. Its payoff
|
|
is that `<Link to="/devices">` is typechecked, so a typo in a path is a build
|
|
error instead of a 404 found later.
|
|
|
|
**No ESLint yet.** `tsc --noEmit` catches the important class of mistakes;
|
|
ESLint is worth adding but its flat-config setup is a distraction during
|
|
scaffolding.
|