mirror of
https://github.com/Komediruzecki/token-circles.git
synced 2026-10-20 09:46:43 +02:00
Three features, plus fixes for four defects found reviewing them. Dark mode now resolves as explicit user choice -> system prefers-color-scheme -> dark default, both in the pre-paint stamp and the theme store, and follows live OS changes while no choice is pinned. Unknown hash routes render a 404 page. Dashboard, Transactions and Budgets show shaped placeholders instead of the bare "Loading..." text they rendered before. What the review corrected: 1. The skeletons printed "Loading..." on screen. Every block ended with a `<span class="sr-only">` and no .sr-only rule exists anywhere in this app, so the text rendered plainly right beside the placeholder meant to replace it. The accessible name carries the announcement now. 2. `#logs` and `#reset-password` hit the 404 page — a regression. Settings drives its diagnostics panel from `#logs` and the reset screen owns `#reset-password`, so "View Logs" landed on the error page and finishing a password reset stranded the user there. Resolution moved to core/hashRoute.ts, which declares those routes so the catch-all only catches genuinely unknown fragments. That also settles a drift between the two copies App.tsx carried: the initial parse sent an empty hash to the dashboard while the hashchange listener ignored it. 3. Following the system theme worked exactly once. The matchMedia listener applied changes through setTheme, which persists, so the first OS switch was read back forever after as an explicit choice. Applying and persisting are now separate. 4. Skeletons were invisible on the light theme — --skeleton-base and --skeleton-shine were referenced but defined in no theme, leaving white at 4-8% opacity — and one chart bar computed to -7.5%, not a valid length, so it never drew. Also: props are read through accessors rather than frozen at setup (a Solid body runs once); SkeletonPage composes the same blocks instead of duplicating their markup and is the single live region; Budgets keeps the `loading-state` test id three other pages key on. 21 tests added where the branch had none; the eight covering the defects above fail against the previous code. Full E2E run locally against the real stack: 504 passed, 1 skipped.
21 lines
902 B
JavaScript
21 lines
902 B
JavaScript
// Stamp the theme before first paint so the boot loader (and the app behind
|
|
// it) never flashes the wrong theme. Resolution order:
|
|
// 1. Explicit user choice in localStorage
|
|
// 2. System prefers-color-scheme media query
|
|
// 3. Default: dark
|
|
// Kept as an external file — not inline — because the self-hosted Express
|
|
// deployment enforces `script-src 'self'` (helmet CSP), which blocks inline
|
|
// scripts.
|
|
try {
|
|
var saved = localStorage.getItem('finance-theme')
|
|
if (saved === 'light' || saved === 'dark') {
|
|
document.documentElement.setAttribute('data-theme', saved)
|
|
} else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
|
|
document.documentElement.setAttribute('data-theme', 'light')
|
|
} else {
|
|
document.documentElement.setAttribute('data-theme', 'dark')
|
|
}
|
|
} catch (e) {
|
|
document.documentElement.setAttribute('data-theme', 'dark')
|
|
}
|