Skip to content

Commit

Permalink
Wait until search actions are ready before presenting any results
Browse files Browse the repository at this point in the history
  • Loading branch information
MM2-0 committed Nov 19, 2022
1 parent b1077fa commit 838a696
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ internal class SearchServiceImpl(
websites: WebsiteSearchSettings,
wikipedia: WikipediaSearchSettings,
): Flow<ImmutableList<Searchable>> = channelFlow {
var searchActionsReady = false
supervisorScope {
val results = MutableStateFlow(SearchResults())
launch {
Expand Down Expand Up @@ -220,6 +221,7 @@ internal class SearchServiceImpl(
searchActionService.search(query)
.collectLatest { r ->
results.update {
searchActionsReady = true
it.copy(searchActions = r)
}
}
Expand All @@ -228,7 +230,7 @@ internal class SearchServiceImpl(
results
.map { it.toList().sortedBy { it as? SavableSearchable }.toImmutableList() }
.collectLatest {
send(it)
if (searchActionsReady) send(it)
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions ui/src/main/java/de/mm20/launcher2/ui/component/SearchBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.animation.core.updateTransition
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down Expand Up @@ -52,7 +53,7 @@ fun SearchBar(
reverse: Boolean = false,
darkColors: Boolean = false,
menu: @Composable RowScope.() -> Unit = {},
actions: @Composable () -> Unit = {},
actions: @Composable ColumnScope.() -> Unit = {},
) {

val transition = updateTransition(level, label = "Searchbar")
Expand Down Expand Up @@ -179,7 +180,7 @@ fun SearchBar(
menu()
}
}
actions()
this.actions()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.mm20.launcher2.ui.launcher.searchbar

import android.content.Intent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand All @@ -24,7 +25,7 @@ import de.mm20.launcher2.ui.component.SearchActionIcon
import de.mm20.launcher2.ui.settings.SettingsActivity

@Composable
fun SearchBarActions(
fun ColumnScope.SearchBarActions(
modifier: Modifier = Modifier,
actions: List<SearchAction>,
reverse: Boolean = false,
Expand Down

0 comments on commit 838a696

Please sign in to comment.