Skip to content

Feat/settings reset to defaults#473

Merged
Baskarayelu merged 5 commits into
CredenceOrg:mainfrom
directorfloo:feat/settings-reset-to-defaults
Jun 29, 2026
Merged

Feat/settings reset to defaults#473
Baskarayelu merged 5 commits into
CredenceOrg:mainfrom
directorfloo:feat/settings-reset-to-defaults

Conversation

@directorfloo

Copy link
Copy Markdown

Closes #438

Title: feat(settings): add "Reset to defaults" action with confirmation and toast

Summary
Adds a guarded "Reset to defaults" action on the Settings page that restores the persisted credence:settings payload to the defined defaults and shows a success toast. Uses the existing ConfirmDialog for destructive confirmation and restores focus to the trigger after close.

Why
Users need a one-click, guarded way to return settings to a known-good baseline (theme system, network public, address display short, toasts enabled, 5s auto-dismiss). Keeps behavior consistent with other destructive flows (ConfirmDialog + toast + focus restoration).

Key changes

  • Implement resetToDefaults() and expose it on SettingsState in SettingsContext.tsx.
  • Add a "Reset to defaults" action button to Settings.tsx that opens ConfirmDialog.
  • On confirm: call resetToDefaults(), persist to credence:settings, show success toast "Settings reset to defaults.", and restore focus to the trigger button.
  • Add/adjust unit tests validating reset behavior, persistence, toast, and focus restoration.

Files touched

  • SettingsContext.tsx — add resetToDefaults() and extend SettingsState
  • Settings.tsx — add Reset button, dialog wiring, returnFocusRef
  • SettingsContext.test.tsx (and/or) src/pages/Settings.test.tsx — tests for reset flow

Implementation notes

  • Uses existing storage key credence:settings (no new keys).
  • resetToDefaults() sets in-memory values to defaultPersistedSettings then persists via existing save path.
  • ConfirmDialog already implements focus trap and supports returnFocusRef.
  • Toast uses existing toast API; message: "Settings reset to defaults."

Testing (local)
Unit:

  • Run:
npx vitest run --config vite.config.ts src/context/SettingsContext.test.tsx
npx vitest run --config vite.config.ts src/pages/Settings.test.tsx
  • Assert:
    • localStorage.getItem('credence:settings') equals defaultPersistedSettings JSON after confirm.
    • document.documentElement theme attribute reflects defaults.
    • Success toast shown with text "Settings reset to defaults."
    • Focus returns to the Reset button after dialog closes.

Manual:

  1. Open Settings, change settings away from defaults.
  2. Click "Reset to defaults".
  3. Confirm.
  4. Verify toast, settings equal defaults, and focus restored to the button.

Review checklist

  • resetToDefaults() implemented and exported via SettingsState.
  • Settings UI contains the Reset button and ConfirmDialog wiring.
  • Toast fires with message "Settings reset to defaults."
  • Focus restoration verified.
  • Uses only credence:settings storage key.
  • Tests added/updated and passing.
  • TypeScript strict and lint checks pass.

Release notes

  • UI: Added "Reset to defaults" button on Settings page (guarded by confirmation).

Optional follow-ups

  • Add an "Undo" action on the toast to restore previous settings.
  • Add telemetry for reset usage.

Want me to open the PR on GitHub (I’ll need your approval to push the branch + create the PR), or paste this as-is into a new PR for you?

@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@directorfloo Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Add a Settings reset-to-defaults action with a ConfirmDialog and toast confirmation

2 participants