Share the search's mapping of the list state (#95)

This commit is contained in:
makiolaj committed 2026-11-20 12:59:45 +01:00
1 parent 05c0199647
commit 64646ffa7b
1 file changed
+5 -3
@@ -428,8 +428,10 @@ class TaskListViewModel @Inject constructor(
private var searchReceiptTimer: Job? = null
/** The searchable tasks, but only once [state] is for the filter now bound. */
private fun searchable(): List<Task> =
(state.value as? TaskListUiState.Content)?.takeIf { it.filter == filter.value }?.searchable.orEmpty()
private fun searchable(): List<Task> = searchableIn(state.value)
private fun searchableIn(state: TaskListUiState): List<Task> =
(state as? TaskListUiState.Content)?.takeIf { it.filter == filter.value }?.searchable.orEmpty()
/** The list search for the current query (#95); idle while the query is blank. */
val search: StateFlow<ListSearchResult> =
@@ -441,7 +443,7 @@ class TaskListViewModel @Inject constructor(
flowOf(ListSearchResult.Empty)
} else {
val tasks = state
.map { st -> (st as? TaskListUiState.Content)?.takeIf { it.filter == filter.value }?.searchable.orEmpty() }
.map(::searchableIn)
.distinctUntilChanged { a, b -> a === b }
combine(tasks, pendingAdds.titlesFlow) { list, pending -> TaskSearch.inList(list, q, pending) }
}