@@ -30,7 +30,6 @@ import kotlinx.coroutines.flow.combine
3030import kotlinx.coroutines.flow.debounce
3131import kotlinx.coroutines.flow.distinctUntilChanged
3232import kotlinx.coroutines.flow.filter
33- import kotlinx.coroutines.flow.filterIsInstance
3433import kotlinx.coroutines.flow.launchIn
3534import kotlinx.coroutines.flow.map
3635import kotlinx.coroutines.flow.onEach
@@ -58,11 +57,6 @@ class HomeViewModel @Inject constructor(
5857 private val _addSearchQuery : MutableStateFlow <String > = MutableStateFlow (" " )
5958 val addSearchQuery: StateFlow <String > = _addSearchQuery .asStateFlow()
6059
61- /* *
62- * The list of queried places retrieved from the route repository, as a StateFlow.
63- */
64- val placeQueryFlow: StateFlow <ApiResponse <List <Place >>> = routeRepository.placeFlow
65-
6660 /* *
6761 * The current UI state of the search bar, as a MutableStateFlow
6862 */
@@ -119,8 +113,12 @@ class HomeViewModel @Inject constructor(
119113 )
120114
121115 private val homeQueryFlow: StateFlow <String > = searchBarUiState
122- .filterIsInstance<SearchBarUIState .Query >()
123- .map { it.queryText }
116+ .map { state ->
117+ when (state) {
118+ is SearchBarUIState .Query -> state.queryText
119+ is SearchBarUIState .RecentAndFavorites -> " "
120+ }
121+ }
124122 .distinctUntilChanged()
125123 .stateIn(
126124 scope = viewModelScope,
@@ -262,11 +260,9 @@ class HomeViewModel @Inject constructor(
262260 }
263261 }.launchIn(viewModelScope)
264262
265- searchBarUiState
263+ homeQueryFlow
266264 .debounce(300L )
267- .filterIsInstance<SearchBarUIState .Query >()
268- .map { it.queryText }
269- .distinctUntilChanged()
265+ .filter { it.isNotBlank() }
270266 .onEach {
271267 routeRepository.makeSearch(it)
272268 }.launchIn(viewModelScope)
0 commit comments