refactor(library): Combine category filter changes into a single flow (#1093)

This commit is contained in:
Cuong-Tran 2025-08-12 14:37:49 +07:00 committed by GitHub
parent 865db12b78
commit ddfdd9588e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -367,27 +367,28 @@ class LibraryScreenModel(
// SY <--
// KMK -->
libraryPreferences.filterCategories().changes()
combine(
libraryPreferences.filterCategories().changes(),
libraryPreferences.filterCategoriesInclude().changes(),
libraryPreferences.filterCategoriesExclude().changes(),
) { filter, included, excluded ->
Triple(
filter,
included.mapNotNull(String::toLongOrNull).toImmutableSet(),
excluded.mapNotNull(String::toLongOrNull).toImmutableSet(),
)
}
.distinctUntilChanged()
.onEach {
.onEach { (filter, included, excluded) ->
mutableState.update { state ->
state.copy(filterCategory = it)
state.copy(
filterCategory = filter,
includedCategories = included,
excludedCategories = excluded,
)
}
}.launchIn(screenModelScope)
libraryPreferences.filterCategoriesInclude().changes()
.distinctUntilChanged()
.onEach {
mutableState.update { state ->
state.copy(includedCategories = it.mapNotNull(String::toLongOrNull).toImmutableSet())
}
}.launchIn(screenModelScope)
libraryPreferences.filterCategoriesExclude().changes()
.distinctUntilChanged()
.onEach {
mutableState.update { state ->
state.copy(excludedCategories = it.mapNotNull(String::toLongOrNull).toImmutableSet())
}
}.launchIn(screenModelScope)
}
.launchIn(screenModelScope)
screenModelScope.launchIO {
getCategories