Reload saved-searches when screen is navigated back to

This commit is contained in:
Cuong-Tran 2024-10-21 18:30:47 +07:00
parent 1ebbbdb344
commit 7f082b9c97
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
2 changed files with 19 additions and 4 deletions

View file

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.browse.source.feed
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.compose.animation.Crossfade import androidx.compose.animation.Crossfade
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@ -76,6 +77,11 @@ class SourceFeedScreen(val sourceId: Long) : Screen() {
} }
} }
LaunchedEffect(navigator.lastItem) {
// Reload saved-searches when screen is navigated back to
screenModel.reloadSavedSearches()
}
val bulkFavoriteScreenModel = rememberScreenModel { BulkFavoriteScreenModel() } val bulkFavoriteScreenModel = rememberScreenModel { BulkFavoriteScreenModel() }
val bulkFavoriteState by bulkFavoriteScreenModel.state.collectAsState() val bulkFavoriteState by bulkFavoriteScreenModel.state.collectAsState()
val showingFeedOrderScreen = rememberSaveable { mutableStateOf(false) } val showingFeedOrderScreen = rememberSaveable { mutableStateOf(false) }

View file

@ -99,10 +99,9 @@ open class SourceFeedScreenModel(
// KMK <-- // KMK <--
setFilters(source.getFilterList()) setFilters(source.getFilterList())
screenModelScope.launchIO { // KMK -->
val searches = loadSearches() reloadSavedSearches()
mutableState.update { it.copy(savedSearches = searches) } // KMK <--
}
getFeedSavedSearchBySourceId.subscribe(source.id) getFeedSavedSearchBySourceId.subscribe(source.id)
.onEach { .onEach {
val items = getSourcesToGetFeed(it) val items = getSourcesToGetFeed(it)
@ -266,6 +265,16 @@ open class SourceFeedScreenModel(
} }
} }
} }
// KMK -->
fun reloadSavedSearches() {
screenModelScope.launchIO {
val searches = loadSearches()
mutableState.update { it.copy(savedSearches = searches) }
}
}
// KMK <--
private suspend fun loadSearches() = private suspend fun loadSearches() =
getExhSavedSearch.await(source.id, (source as CatalogueSource)::getFilterList) getExhSavedSearch.await(source.id, (source as CatalogueSource)::getFilterList)
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, EXHSavedSearch::name)) .sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, EXHSavedSearch::name))