Skip to content

fix(browse): stop the library sort resetting to its default - #237

Merged
Quick104 merged 2 commits into
mainfrom
claude/browse-sort-reset-bug-dddcb8
Aug 18, 2026
Merged

Quick104 merged 2 commits into
mainfrom
claude/browse-sort-reset-bug-dddcb8

Conversation

@Quick104

@Quick104 Quick104 commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #236.

The reported symptom — "SORT goes back to default so have to start from scratch" — turned out to be two independent defects, one per client. Filters survive in both cases; only the sort is lost.

Android TV — sort lost on Back from item detail

TvLibraryDetailScreen re-issues the committed cascade section every time it re-enters composition:

LaunchedEffect(sectionRequestNonce, initialSection) { initialSection?.let(viewModel::onTabSelected) }

The ViewModel survives the Back (verified with a temporary log — same instance either side), but onTabSelected guarded with if (state.selectedTab == tab && !filterChanged) return. On re-entry the tab is unchanged and filterChanged is true precisely because the viewer customised the sort, so the guard fell through and forTab(Browse) reset sort and facets to Title A–Z.

Re-selecting the already-active tab is now a no-op. A genuine tab change still applies the new tab's defaults, and forTab / onAudiobookGroupCleared are untouched.

Android phone — sort lost on relaunch

LibrariesViewModel kept the sort in LibrariesUiState.browseSort, outside the CatalogFilterState that BrowsePrefsStore persists — so "Preserve sort & filters" restored the chips while the sort snapped back to Recently Added.

The sort now rides the persisted filter state, the way BrowseViewModel already does it, and is derived back out on restore via LibraryBrowseSort.fromFilterState. applyFilterState keeps the sort already committed here and takes only the facet/match parts from its argument: the Reset control changes the sort and clears the facets off the same composition frame, so trusting the incoming state's sort would reinstate the one just cleared.

Verified

On the local phone and TV emulators against the dev server, with builds from this branch:

  • TV: Movies → Browse → sort Year → open a title → Back → chip still reads Sort · Year Newest, grid still 2026-first. Before the fix it returned to Title A–Z.
  • Phone: Library subtab → sort Title + filter Unwatched → force-stop → relaunch → chip reads Title, grid alphabetical, Unwatched restored. Persisted state now carries the sort: {"selections":{"WatchStatus":["unwatched"]},"sort":"title","order":"asc"}.
  • Phone Reset still clears both — sort back to Recently Added, chips gone, saved state {}.
  • ./gradlew :androidApp:assembleDebug :androidTvApp:assembleDebug and :androidApp:testDebugUnitTest :androidTvApp:testDebugUnitTest pass.

Tests

One focused regression test per app, in the existing files. Each was confirmed to fail with its fix reverted, so neither is vacuous. LibrariesViewModelTest now runs under Robolectric because BrowsePrefsStore writes through real SharedPreferences (precedent: ReaderViewModelReaderTargetSourceTest, WatchTogetherEntryViewModelTest); all pre-existing tests in the file still pass.

Behavioural deltas worth a reviewer's eye

  • TV: re-selecting Authors/Series while drilled into an audiobook group no longer clears the group as a side effect. Exiting a drill-in now relies solely on onAudiobookGroupCleared, which has its own dedicated UI affordance (onClearAudiobookGroup), so nothing is trapped.
  • Phone: selectLibrary previously carried the previous library's sort across a library switch. Sort now travels with the per-library persisted state, so switching to a library with nothing saved lands on Recently Added.
  • TV sort still lives only in memory — it survives Back and in-session navigation, but not an app restart. The phone's per-library persistence has no TV counterpart; left as-is rather than widened into this fix.
  • Two comments in TvLibraryDetailScreen.kt (the sectionRequestNonce doc and the LaunchedEffect comment) still claim re-committing the same pill "re-applies the section rather than being a silent no-op". That is now false when the tab is already selected — which is the fix. Left alone to keep the diff to the defect; happy to update them here if preferred.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Library browsing now restores selected sort and filter settings when reopening a library or restarting the app.
    • Sort and filter changes are saved together and applied when the catalog reloads.
  • Bug Fixes

    • Re-selecting the active TV browsing tab no longer resets sorting or triggers an unnecessary catalog reload.

TV: backing out of item detail returned to a surviving library
ViewModel, but re-entering the screen re-issues the committed cascade
section, and onTabSelected re-applied the tab's default filter whenever
the viewer had customised it — the guard only skipped when the filter
was ALSO unchanged. Re-selecting the already-active tab is now a no-op;
only a genuine tab change applies the new tab's defaults.

Phone: the browse sort lived outside the persisted CatalogFilterState,
so "Preserve sort & filters" restored the facet chips while the sort
snapped back to Recently Added on relaunch. The sort now rides the
persisted filter state (as BrowseViewModel already does) and is derived
back out on restore. applyFilterState keeps the committed sort so the
Reset control, which changes the sort and clears facets off the same
composition frame, cannot reinstate the old one.

Verified on both emulators: TV keeps Year/Newest across Back, phone
keeps Title across a force-stop relaunch, and Reset still clears both.

Co-Authored-By: Claude Opus 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6352b876-c7ff-43da-b13b-44a52b2cbaec

📥 Commits

Reviewing files that changed from the base of the PR and between c7dc2f0 and 706103a.

📒 Files selected for processing (1)
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/library/TvLibraryDetailScreen.kt

Included review availability: 1 review is currently available. Based on recent review activity, included reviews refill at 3 per hour.


📝 Walkthrough

Walkthrough

The Android phone now persists and restores browse sort with filters. The Android TV no longer reapplies default browse filters when the active tab is selected again.

Changes

Android phone browse sort persistence

Layer / File(s) Summary
Persist and restore library browse sort
androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/libraries/LibrariesScreen.kt, androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/libraries/LibrariesViewModelTest.kt
LibraryBrowseSort resolves persisted sort values. Library selection and fresh view models restore sort and filter state. Filter and sort changes persist the combined state before catalog reloads. Tests verify persistence across view models.

Android TV browse tab preservation

Layer / File(s) Summary
Prevent active-tab reset and reload
androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/library/TvLibraryDetailViewModel.kt, androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/library/TvLibraryDetailScreen.kt, androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/library/TvLibrarySubdestinationViewModelTest.kt
Selecting the active tab is now a no-op. Screen comments describe repeated section application. The regression test verifies that release-date sorting remains selected and no additional catalog request occurs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 70610

The change preserves customized library sorting across navigation and relaunch while keeping reset behavior intact; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: rxwatcher

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.54% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the browse sort reset fix, which is the primary change in the pull request.
Linked Issues check ✅ Passed The changes address issue #236 by preserving TV sort on tab re-selection and persisting and restoring phone sort with filter state.
Out of Scope Changes check ✅ Passed All implementation, test, and documentation changes directly support the browse sort preservation objectives in issue #236.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/browse-sort-reset-bug-dddcb8

Comment @coderabbitai help to get the list of available commands.

Both comments asserted the behaviour the guard change removes —
re-committing the same pill "re-applies the section rather than being a
silent no-op". That is now exactly what must not happen, and these are
the comments the next person reads when debugging this area.

Co-Authored-By: Claude Opus 5 <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c7dc2f0414

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// re-applying `forTab` here would reset the viewer's customised sort
// and facets back to the tab's defaults (Title A–Z). Only a genuine
// tab CHANGE applies the new tab's defaults.
if (state.selectedTab == tab) return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reapply explicitly recommitted TV library sections

When a viewer customizes the active Browse/Genres/A-Z section and then explicitly commits that same pill again from the Skyline cascade, the shell increments sectionRequestNonce specifically to reapply the section defaults, but this unconditional early return now discards the commit and leaves the custom sort and facets active. TvLibraryDetailScreen still invokes onTabSelected for every nonce change, so return-trip preservation needs to be distinguished from a genuine recommit rather than treating every same-tab selection as a no-op.

Useful? React with 👍 / 👎.

@Quick104
Quick104 merged commit 5670f05 into main Aug 18, 2026
3 checks passed
@Quick104
Quick104 deleted the claude/browse-sort-reset-bug-dddcb8 branch August 18, 2026 13:24
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.

Browse sort resets to the default after opening a title (TV) or relaunching (phone)

1 participant