ui: show 'No results' when search returns empty (#309)

Updates tailscale/corp#18202

Signed-off-by: kari-ts <kari@tailscale.com>
pull/312/head
kari-ts 3 weeks ago committed by GitHub
parent 6a00880f61
commit c8d1b30918
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -40,6 +40,7 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@ -321,6 +322,7 @@ fun PeerList(
) {
val peerList = viewModel.peers.collectAsState(initial = emptyList<PeerSet>())
val searchTermStr by viewModel.searchTerm.collectAsState(initial = "")
val showNoResults = derivedStateOf { searchTermStr.isNotEmpty() && peerList.value.isEmpty() }.value
val netmap = viewModel.netmap.collectAsState()
val focusManager = LocalFocusManager.current
@ -364,6 +366,21 @@ fun PeerList(
LazyColumn(
modifier = Modifier.fillMaxSize().background(color = MaterialTheme.colorScheme.surface)) {
if (showNoResults) {
item {
Spacer(
Modifier.height(16.dp)
.fillMaxSize()
.background(color = MaterialTheme.colorScheme.surface))
Lists.SectionTitle(
stringResource(id = R.string.no_results),
bottomPadding = 8.dp,
style = MaterialTheme.typography.bodyMedium,
fontWeight = FontWeight.Light)
}
}
var first = true
peerList.value.forEach { peerSet ->
if (!first) {

@ -19,6 +19,7 @@
<string name="warning">Warning</string>
<string name="search">Search</string>
<string name="dismiss">Dismiss</string>
<string name="no_results">No results</string>
<!-- Strings for the about screen -->
<string name="app_name">Tailscale</string>

Loading…
Cancel
Save