Skip to content

feat(ui): persist the dark-mode choice via the per-user settings store#204

Merged
smunini merged 3 commits into
mainfrom
feat/197-theme-user-settings
Jul 8, 2026
Merged

feat(ui): persist the dark-mode choice via the per-user settings store#204
smunini merged 3 commits into
mainfrom
feat/197-theme-user-settings

Conversation

@angela-helios

Copy link
Copy Markdown
Contributor

Wires the topbar theme toggle to the /_user/settings document from #151, so the dark-mode preference roams across devices. Implements #197.

Stacked PR — depends on #151. Base is feat/user-ui-settings; merge #151 first, then this (the first commit merges main to bring in the crates/ui UI crate, so the diff shrinks once the base catches up).

How it works (theme.js)

  • First paint unchanged and synchronous: localStorage cache → OS preference → light. No flash-of-light, no network on the critical path.
  • Reconcile on load: an async GET /_user/settings; a valid roamed theme from another device wins over the local cache and refreshes it.
  • On toggle: apply + cache immediately, then persist with an RFC 7386 merge-patch ({"theme":"dark"}) so no other settings key is touched.
  • Hardening: server values are validated (light|dark) before applying — the settings document is opaque by design, so a corrupted value (e.g. {"theme":"purple"}, which the store happily accepts) cannot break the UI. Any fetch failure degrades to today's cache-only behavior.

Tests

  • helios-rest/tests/user_settings.rs: the exact UI round-trip — merge-patch as the first write (document created on the fly), unrelated keys preserved, toggle back; plus the brand-new-user case.
  • helios-ui: smoke-guard that the embedded theme.js keeps the settings wiring and the cache key.

Verified against the running server

GET{} (W/"0") → PATCH {"theme":"dark"}GET{"theme":"dark"}PATCH {"theme":"light"} → round-trip clean; non-object PATCH body → 400; served theme.js carries the wiring. (The in-browser localStorage/fetch behavior itself is smoke-tested only — a Playwright-style browser test would be the follow-up if we want it covered.)

Closes #197.

#197)

Wire the topbar theme toggle to the /_user/settings document from #151
so the preference roams across devices instead of living only in
per-device localStorage:

- theme.js: first paint stays synchronous from the localStorage cache
  (cache -> OS preference -> light, no flash); an async GET then
  reconciles with the server document — a roamed choice from another
  device wins and refreshes the cache. On toggle, apply + cache
  immediately and persist with an RFC 7386 merge-patch
  ({"theme":"dark"}) so no other settings key is touched.
- Server values are validated (light|dark) before applying — the
  settings document is opaque by design, so a corrupted value must not
  break the UI. Fetch failures degrade to the old cache-only behavior.
- rest tests: the exact UI round-trip (merge-patch as first write with
  and without a pre-existing document, unrelated keys preserved,
  toggle back).
- ui test: smoke-guard that the embedded theme.js keeps the settings
  wiring and the localStorage cache.
@claude

claude Bot commented Jul 6, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Base automatically changed from feat/user-ui-settings to main July 8, 2026 12:53
@smunini smunini merged commit 3c34364 into main Jul 8, 2026
1 check passed
@smunini smunini deleted the feat/197-theme-user-settings branch July 8, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web UI: persist dark-mode preference via per-user settings store (#151)

2 participants