fix(search): rebuild the results pager only when the dictionary set changes
Background metadata loading rewrote the dictionaries flow several times after startup, and every emission recreated the Pager: the results list visibly collapsed and refilled. Distinct on the index paths that paging actually uses, and seed the state synchronously instead of an empty list.
This commit is contained in:
1 parent
9dac7507ed
commit
e9706ab12a
1 file changed
+3
-1
@@ -70,10 +70,12 @@ class SearchViewModel(
|
|||||||
private val activeDictionaries: StateFlow<List<com.example.research.core.domain.model.Dictionary>> =
|
private val activeDictionaries: StateFlow<List<com.example.research.core.domain.model.Dictionary>> =
|
||||||
repository.dictionaries.map { dictList ->
|
repository.dictionaries.map { dictList ->
|
||||||
dictList.filter { it.isActive }
|
dictList.filter { it.isActive }
|
||||||
|
}.distinctUntilChanged { previous, current ->
|
||||||
|
previous.map { it.indexPath } == current.map { it.indexPath }
|
||||||
}.stateIn(
|
}.stateIn(
|
||||||
scope = viewModelScope,
|
scope = viewModelScope,
|
||||||
started = SharingStarted.WhileSubscribed(5000),
|
started = SharingStarted.WhileSubscribed(5000),
|
||||||
initialValue = emptyList()
|
initialValue = repository.dictionaries.value.filter { it.isActive }
|
||||||
)
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|||||||
Reference in new issue
Block a user