fix(ui): prevent whitespace-only filter and add product count debug hint
This commit is contained in:
1 parent
f0184b94a3
commit
23dce047b4
1 file changed
+17
-4
@@ -100,10 +100,15 @@ fun App() {
|
||||
|
||||
LaunchedEffect(Unit) { loadProducts() }
|
||||
|
||||
val filteredProducts = remember(products, query) {
|
||||
products.filter {
|
||||
it.title.contains(query, ignoreCase = true) ||
|
||||
it.description.contains(query, ignoreCase = true)
|
||||
val normalizedQuery = remember(query) { query.trim() }
|
||||
val filteredProducts = remember(products, normalizedQuery) {
|
||||
if (normalizedQuery.isBlank()) {
|
||||
products
|
||||
} else {
|
||||
products.filter {
|
||||
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 -> {
|
||||
|
||||
Reference in new issue
Block a user