# The Angular frontend

The interface is an Angular application served by the same Quarkus as the API. You will know how it is built and bootstrapped, which structural rules the screens follow, and a few pitfalls that cost a lot when rediscovered: the poll that doubles the event stream, the keyboard, the theme, Leaflet.

## A single deployment

The Quinoa extension runs `npm ci && npm run build` during `mvn package` and copies the bundle into the static resources ([`application.properties`](repo:src/main/resources/application.properties), `quarkus.quinoa.*`). In production there is no Node server. In `quarkus:dev`, Quinoa starts `ng serve` and proxies port 4200 for hot reload.

Structural rule: one question, one screen, its variants as tabs (`?onglet=`) or views (`?vue=`) in the URL, loaded on demand. You do not add a section to an existing page. The menu ([`shell/nav-groups.ts`](repo:src/main/webui/src/app/shell/nav-groups.ts)) is the same for everyone and holds nine entries in the order of an edition's cycle, a new screen becoming a page or a tab of one of them; a route can be served without a menu entry (Compare two versions, Help), the Ctrl+K palette finds it. The services in `core/` carry the shared state and the HTTP calls; components do not call `fetch`.

State flows in one direction only: the Calculate tab of the Planning page pushes the solved schedule, the calendars reread it read-only and never start a solve.

## Redeploying without breaking open browsers

Each frontend page is loaded on demand, under a name that changes with its content (`chunk-*.js`): a redeployment replaces the whole batch. A browser that keeps the old shell in cache would then request files that no longer exist, and every menu link would fail silently, on mobile as on desktop.

Two mechanisms avoid having to ask users to "clear their cache":

- the server serves everything that has a stable name with `Cache-Control: no-cache`: `index.html`, the `/i18n/*.json` catalogues, but also the favicon, `robots.txt`, the logos and the fonts, which the Angular build copies as is from `public/`. *Revalidate before reuse*: a conditional request answered `304` as long as nothing has changed. The hashed files, for their part, stay cached for a long time without risk (`SpaCacheControlFilter`);
- if a stale shell runs anyway (a tab left open during the redeployment), the first click whose chunk has disappeared triggers **a full reload to the requested page** instead of failing silently (`core/stale-chunk-reload.ts` on the frontend side).

No setting: redeploying is enough, browsers recover on the next visit or the first click.

To diagnose, remember this detail. SPA routing being active (`quarkus.quinoa.enable-spa-routing`), a missing chunk does not give a `404` but a `200` with the current `index.html`. It is the wrong MIME type that makes the dynamic import fail. In the browser console, look for *failed to fetch dynamically imported module* (or its Firefox and WebKit equivalent), not an HTTP error code.

## Three reads before `bootstrapApplication()`

[`main.ts`](repo:src/main/webui/src/main.ts) loads in parallel the English translation catalogue (only when English is the chosen language), `/api/config` and `/api/branding`, before bootstrapping the application. The tab title and the logo decide the first frame: no screen should have to wait for a round trip to know what it is called. If the English catalogue fails to load, the application falls back to French rather than staying blank.

**Runtime translation.** French is written directly in the templates, `loadTranslations()` loads `messages.en.json`. There is only one build, with no bundle per language, hence no extra Quinoa configuration. The writing rules (the two halves of a string, `$localize` never at module level) are in [the repository conventions](conventions-du-depot.md).

**Branding.** An empty `logoUrl` means "show nothing", never "show the default logo": an instance serves one client, and none inherits another's brand. A limit worth knowing: `mat.theme()` compiles the whole tonal palette into the bundle, and the configurable accent colour (the `accent` key of `BRANDING_COLORS`) only feeds `--app-accent`. Recolouring the Material components requires a recompilation, not an environment variable.

## Light or dark theme

**Every colour lives in one file**, [`styles/tokens.css`](repo:src/main/webui/src/styles/tokens.css): each one is a `light-dark(light, dark)` pair there, and `material-theme.scss` brings every `--mat-sys-*` system colour back to it. The look keeps the azure blue and the original layout: the page is a white sheet with rounded corners laid on the faintly blue ground of the shell, under the blue band; the font is Inter, self-hosted under the SIL OFL licence; headings are set in weight 600, buttons are pills and cards have rounded corners. `npm run colour-tokens-check` refuses a colour written in any other stylesheet and measures at 4.5:1 at least, in both schemes, the text/background pairs the file declares.

`mat.theme()` compiles both palettes at once: each `--mat-sys-*` colour is a `light-dark(light, dark)` pair, and the CSS `color-scheme` property of the root element decides which one is painted. There is no second theme or parallel stylesheet, nothing to recompile. The application writes `light dark` ("follow the machine", the default), `light` or `dark` on `<html>`, and keeps the preference in `localStorage` with the other interface preferences. `main.ts` sets it before any network call, so as not to paint a frame in the wrong theme.

Two colours escape `mat.theme()` and carry their own `light-dark()` pairs:

- the categorical palette of the game categories, read by `styles/typologie-colors.css` from the token file: eight hues that no `--mat-sys-*` provides;
- `--app-accent`, when the `accent` key of `BRANDING_COLORS` fills it in (otherwise it equals `--mat-sys-primary`, already a pair). It serves as a text colour on `--mat-sys-surface` and as a focus ring; [`core/branding.ts`](repo:src/main/webui/src/app/core/branding.ts) therefore sets it as a pair, each half bounded in OKLCH at constant hue: lightness capped in light, bounded from below in dark (with a chroma ceiling).

Three surfaces deliberately stay outside the theme:

- the brand toolbar (administration, staff espace) keeps its signage colour: an identity that changes with the time of day is no longer one. By default it is the `#007eb2` band under white text (4.54:1), the `--color-band` / `--color-band-ink` tokens, identical in both schemes. It carries text, so the `--app-toolbar-foreground` / `--app-toolbar-background` pair a deployment substitutes (`styles/branding.css`) is measured like any colour written by the repository;
- the maps display OpenStreetMap tiles, content and not chrome; darkening them would require another tile provider.
- the PDFs are composed server-side to be printed: they follow the brand, never the browser's theme.

The toggle button lives only in the administration bar. The login page and the staff espace follow the preference saved by this browser, failing that the system's.

## The poll is not a leftover

The "a solver is running" state is never stored in the browser: it is read from the server, so that a solve started from another window also locks the buttons here.

It is read in two ways, on purpose. The SSE stream `/api/jobs/stream` gives the latency: a solve started elsewhere locks in one second instead of thirty. The polling loop underneath is the safety net, because SSE fails silently and the interface would stay frozen on a stale state without signalling anything, which is worse than a poll, which repairs itself at the next tick.

The two halves are two files. [`core/solver-stream.ts`](repo:src/main/webui/src/app/core/solver-stream.ts) holds the `EventSource` connection, its watchdog and its backoff, with no business state. [`core/solver-job.service.ts`](repo:src/main/webui/src/app/core/solver-job.service.ts) holds the poll and the jobs' state, and routes what the stream pushes through the same body as a poll tick: this is what makes the fallback honest.

## A single global keyboard listener

[`core/keyboard-shortcuts.service.ts`](repo:src/main/webui/src/app/core/keyboard-shortcuts.service.ts) carries the only `keydown` set on the document for shortcuts (Ctrl+K, `g` then a letter, `/`, `?`, Ctrl+Enter). It is armed and disarmed with the administration shell: `/login` and the staff espace have neither the palette nor these destinations. Do not add a second one: two global listeners fight over the same keystroke without anything signalling it. The only deliberate exception is the shell's Konami code, a sequence with its own state.

The arrows of the calendars, of the Planning grid and of the data tables are not global listeners: they are set on the component's element, consume only the keys they use and let the rest bubble up to the global listener, which stops on an already consumed event. This is how you add a keyboard behaviour. Escape is written nowhere: no dialog uses `disableClose`, `MatDialog` already closes the topmost dialog and returns focus.

The table of `g`+letter and the palette labels live in `core/keyboard-shortcuts.ts`, and the destinations are derived from `app.routes.ts`: a page added tomorrow is reachable by keyboard without anyone having thought of registering it.

### The data tables

The roving `tabindex` of the five reference tables, and of the manual adjustments and locks tables (a single row reachable by Tab, arrows, Home/End, Enter to open, Space to tick), is shared in [`core/table-navigation.ts`](repo:src/main/webui/src/app/core/table-navigation.ts), next to `core/table-selection.ts` which it drives.

- You enter the table through the filter. The row that carries `tabindex="0"` sits behind the "select all" checkbox and behind one stop per sortable header: the number of Tab presses would change each time a column becomes sortable, and a gesture you have to guess does not exist. The documented gesture is therefore: "/" focuses the page's filter, Down arrow enters it. The timeslots page, with no quick filter, keeps entry by Tab alone.
- Enter and Space are consumed only if something opens or gets ticked. A table with no selection gives Space back to the page; the timeslots refuse to open while a solve locks the edition, and the key goes on its way, the lock banner already saying why.

The two-axis Planning grid (by stand, by person) keeps its own navigation: its geometry is not that of a list.

## Leaflet stays out of the initial bundle

Two places display a map: the "Locations" tab of `/stands` (all the locations, a marker dragged with the mouse that saves its position, entering a point in a location's form) and the "Map" view of `/journee`. The first is in a `@defer` block, the location form is loaded by an `import()` when a stand offers "New location…", the second in a page `@defer`. Leaflet alone weighs a 150 kB chunk: nothing loaded at startup must import it, otherwise this weight goes into everyone's bundle, the login page included.

## The only place where the frontend reimplements domain logic

`app/core/horaire-stand.ts` resolves a stand's hours rules into day-by-day windows, to preview a rule without a round trip. The server no longer stores any rule since 4.0 ([decision 0104](repo:docs/decisions/0104-les-horaires-d-un-stand-sont-une-liste-de-plages-datees.md)): the rules this editor saves (the recurring model of the stand fiche) are kept as the model and converted into plages by the server, over the days of the event; the plage list of the same fiche writes the plages typed by hand through their routes. Its Java counterpart is `HorairesRecurrents`, for the migration and the old files ([stand hours and windows](horaires-et-fenetres-des-stands.md)).

## CSS

[`src/styles.css`](repo:src/main/webui/src/styles.css) is only an aggregator of `@import`s, with one partial file per screen under `src/styles/`. `branding.css` is imported first: all the others read `--app-accent`.
