Skip to content

fix: persist Inbox 'Show unread only' toggle across sessions - #3682

Open
iroiro147 wants to merge 1 commit into
block:mainfrom
iroiro147:fix/persist-unread-only-toggle
Open

fix: persist Inbox 'Show unread only' toggle across sessions#3682
iroiro147 wants to merge 1 commit into
block:mainfrom
iroiro147:fix/persist-unread-only-toggle

Conversation

@iroiro147

Copy link
Copy Markdown

Problem

The Inbox's Show unread only toggle resets to off whenever the Inbox view is remounted. Users who prefer an unread-only Inbox have to enable it again after navigating away, reopening the Inbox, or restarting Buzz.

Closes #3669

Root Cause

The unreadOnly state in HomeView.tsx was a plain React.useState(false) with no persistence layer — every remount starts fresh.

Solution

Introduced usePersistentBoolean — a small localStorage-backed hook that follows the same versioned-key pattern already used by useFeedItemState in this codebase (e.g. buzz-home-feed-done.v1).

  • On mount, reads the stored value from localStorage. If absent, falls back to false.
  • On every state change, writes the new value back to localStorage.
  • SSR-safe (typeof window guard) and degrades silently if storage is unavailable.

Changes

File Change
desktop/src/features/home/usePersistentBoolean.ts New hook (40 lines)
desktop/src/features/home/ui/HomeView.tsx Replace useState(false) with usePersistentBoolean (2 lines changed)
desktop/src/features/home/usePersistentBoolean.test.mjs 7 tests covering default, restore true/false, toggle, key convention

Acceptance Criteria

  • Enabling Show unread only remains effective after navigating away from and back to the Inbox
  • The enabled state is restored after restarting Buzz
  • Disabling the toggle updates the saved preference so it remains disabled on subsequent visits
  • Users without a saved preference retain the current default of off
  • Automated coverage verifies preference restoration and the default/fallback behavior

Test Plan

cd desktop
node --test src/features/home/usePersistentBoolean.test.mjs

All 7 tests pass:

  • default is false when no stored value exists
  • stored true is restored as true
  • stored false is restored as false
  • writing true then reading returns true
  • writing false then reading returns false
  • toggling from true to false persists the new value
  • storage key uses versioned prefix matching existing buzz-home patterns

The 'Show unread only' toggle in the Inbox reset to off every time the
view was remounted (navigation away/back, app restart). This was because
the state was held in a plain React.useState(false) with no persistence.

This change introduces usePersistentBoolean — a small localStorage-backed
hook that follows the same versioned-key pattern as useFeedItemState
(buzz-home-*.v1). The unreadOnly toggle now reads its initial value from
localStorage on mount and writes back on every change.

Acceptance criteria met:
- Enabling 'Show unread only' persists across navigation away/back
- The enabled state is restored after restarting Buzz
- Disabling the toggle updates the saved preference
- Users without a saved preference retain the default of off
- Automated tests verify preference restoration and default/fallback

Closes block#3669
@iroiro147
iroiro147 requested a review from a team as a code owner July 30, 2026 04:16
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.

Persist Inbox "Show unread only" toggle across visits

1 participant