Skip to content

Commit

Permalink
always reload saved-search & reset filter list when click on saved-se…
Browse files Browse the repository at this point in the history
…arch
  • Loading branch information
cuong-tran committed Nov 9, 2024
1 parent 1e229d4 commit faf5d95
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -540,23 +540,34 @@ open class BrowseSourceScreenModel(
// KMK <--

// EXH -->
/** Show a dialog to enter name for new saved search */
fun onSaveSearch() {
screenModelScope.launchIO {
val names = state.value.savedSearches.map { it.name }.toImmutableList()
mutableState.update { it.copy(dialog = Dialog.CreateSavedSearch(names)) }
}
}

/** Open a saved search */
fun onSavedSearch(
search: EXHSavedSearch,
// KMK -->
loadedSearch: EXHSavedSearch,
// KMK <--
onToast: (StringResource) -> Unit,
) {
// KMK -->
resetFilters()
// KMK <--
screenModelScope.launchIO {
// KMK -->
val source = source
// KMK <--
if (source !is CatalogueSource) return@launchIO

// KMK -->
val search = getExhSavedSearch.awaitOne(loadedSearch.id, source::getFilterList) ?: loadedSearch
// KMK <--

if (search.filterList == null && state.value.filters.isNotEmpty()) {
withUIContext {
onToast(SYMR.strings.save_search_invalid)
Expand Down Expand Up @@ -587,10 +598,12 @@ open class BrowseSourceScreenModel(
}
}

/** Show dialog to delete saved search */
fun onSavedSearchPress(search: EXHSavedSearch) {
mutableState.update { it.copy(dialog = Dialog.DeleteSavedSearch(search.id, search.name)) }
}

/** Save a search */
fun saveSearch(
name: String,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,11 @@ open class SourceFeedScreenModel(
}
}

/** Open a saved search */
fun onSavedSearch(
search: EXHSavedSearch,
// KMK -->
loadedSearch: EXHSavedSearch,
// KMK <--
onBrowseClick: (query: String?, searchId: Long) -> Unit,
onToast: (StringResource) -> Unit,
) {
Expand All @@ -323,6 +326,10 @@ open class SourceFeedScreenModel(
// KMK <--
if (source !is CatalogueSource) return
screenModelScope.launchIO {
// KMK -->
val search = getExhSavedSearch.awaitOne(loadedSearch.id, source::getFilterList) ?: loadedSearch
// KMK <--

if (search.filterList == null && state.value.filters.isNotEmpty()) {
withUIContext {
onToast(SYMR.strings.save_search_invalid)
Expand Down

0 comments on commit faf5d95

Please sign in to comment.