Skip to content

fix: persist preferences to localStorage - #98

Open
interview35 wants to merge 1 commit into
OpenNSWM-Lab:mainfrom
interview35:fix/preferences-persistence
Open

fix: persist preferences to localStorage#98
interview35 wants to merge 1 commit into
OpenNSWM-Lab:mainfrom
interview35:fix/preferences-persistence

Conversation

@interview35

Copy link
Copy Markdown

Summary

The Preferences page at /settings/preferences showed a "Preferences saved locally (mock)" toast when clicking Save, but never actually persisted anything. All settings (density, table row height, line numbers, notifications, auto-save) were lost on every page refresh.

What this PR does

  • Consolidates the five separate useState calls into a single PreferencesData object managed by one useState
  • Adds loadPreferences() which reads from localStorage under the key faros.preferences, with a try-catch fallback to defaults if the stored data is corrupted
  • Initializes state from loadPreferences() so preferences survive page refreshes
  • Updates handleSave to serialize the preferences object to localStorage before showing the toast
  • Removes "(mock)" from the toast message since it now actually saves
  • Adds a typed updatePref helper to keep the setter calls clean and type-safe

File changed

frontend/src/pages/Settings/Preferences.tsx — no other files touched.

Verification

  • Reviewed the diff carefully to confirm all five preference controls (density, tableRowSize, showLineNumbers, enableNotifications, autoSaveDrafts) read from and write to the unified prefs state
  • Confirmed loadPreferences merges with defaults so adding new preference fields later won't crash on old stored data
  • Confirmed the handleSave try-catch handles localStorage being unavailable (private browsing, quota exceeded)
  • The theme preference is intentionally left to useTheme's own persistence mechanism — this PR only covers the five preferences that had no persistence at all

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.

1 participant