Skip to content

Commit 4fe82cf

Browse files
RXWatcherclaude
andcommitted
fix(tv): Back from detail returned to library main, not browse (issue #66)
The library's A-Z/browse sub-view and filter are in-screen ViewModel state, not a nav destination. The section-apply effect (LaunchedEffect(sectionRequestNonce, initialSection)) re-runs on every re-entry into composition — including returning from ItemDetail — and re-applied the initial section, resetting the user's tab/filter back to the library's main (Recommended) view. Gate the apply on the commit nonce in the ViewModel (which survives the detail round-trip) so a bare re-entry is a no-op while a genuine cascade re-commit still re-applies. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent d8d8dcb commit 4fe82cf

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/library/TvLibraryDetailViewModel.kt‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ class TvLibraryDetailViewModel(
165165
private var loadedAudiobookGroupBy: String? = null
166166
private var audiobookGroupsGeneration = 0
167167

168+
// Last cascade-commit nonce whose section we applied. The screen's
169+
// section-apply effect re-runs on every re-entry into composition —
170+
// including returning from ItemDetail/Player — and this ViewModel survives
171+
// that round-trip, so without gating on the nonce a bare re-entry would
172+
// re-apply the initial section and throw away the user's in-screen tab /
173+
// A-Z filter (issue #66: Back from a movie returned to the library's main
174+
// view instead of the browse list). Only a genuine new commit bumps the
175+
// nonce, so we apply then and no-op on re-entry.
176+
private var lastAppliedSectionNonce: Int? = null
177+
168178
init {
169179
// Only the default Recommended tab loads eagerly. Filters (the genre
170180
// rail) are fetched lazily when Browse is first opened — the
@@ -173,6 +183,18 @@ class TvLibraryDetailViewModel(
173183
loadRecommended()
174184
}
175185

186+
/**
187+
* Applies a section committed from the Skyline cascade, but only once per
188+
* distinct commit nonce (see [lastAppliedSectionNonce]) so a plain
189+
* re-entry into composition — e.g. returning from a detail screen — does
190+
* not clobber the user's current tab/filter.
191+
*/
192+
fun applyCommittedSection(tab: TvLibraryTab, nonce: Int) {
193+
if (nonce == lastAppliedSectionNonce) return
194+
lastAppliedSectionNonce = nonce
195+
onTabSelected(tab)
196+
}
197+
176198
fun onTabSelected(tab: TvLibraryTab) {
177199
val state = _uiState.value
178200
val nextFilter = state.browseFilter.forTab(tab)

0 commit comments

Comments
 (0)