fix(ui): prevent whitespace-only filter and add product count debug hint
Build Android app / Build (push) Has been cancelled
Build iOS app / Build (push) Has been cancelled
Template Cleanup / Template Cleanup (push) Has been cancelled

This commit is contained in:
xiaobai committed 2026-03-04 17:56:58 +08:00
1 parent f0184b94a3
commit 23dce047b4
1 file changed
+16 -3
@@ -100,10 +100,15 @@ fun App() {
LaunchedEffect(Unit) { loadProducts() }
val filteredProducts = remember(products, query) {
val normalizedQuery = remember(query) { query.trim() }
val filteredProducts = remember(products, normalizedQuery) {
if (normalizedQuery.isBlank()) {
products
} else {
products.filter {
it.title.contains(query, ignoreCase = true) ||
it.description.contains(query, ignoreCase = true)
it.title.contains(normalizedQuery, ignoreCase = true) ||
it.description.contains(normalizedQuery, ignoreCase = true)
}
}
}
@@ -178,6 +183,7 @@ fun App() {
loading = loading,
error = loadError,
products = filteredProducts,
totalProducts = products.size,
query = query,
quantityOf = { id -> cartItems.firstOrNull { it.productId == id }?.quantity ?: 0 },
onQueryChange = { query = it },
@@ -217,6 +223,7 @@ private fun ProductListScreen(
loading: Boolean,
error: String?,
products: List<Product>,
totalProducts: Int,
query: String,
quantityOf: (String) -> Int,
onQueryChange: (String) -> Unit,
@@ -239,6 +246,12 @@ private fun ProductListScreen(
placeholder = { Text("输入标题或描述") }
)
Text(
text = "共 $totalProducts 条 · 当前显示 ${products.size} 条",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
when {
loading -> EmptyState("⏳ 加载中...")
error != null -> {