From a01037f4ee3488dad24b1c78301e009c0865f45e Mon Sep 17 00:00:00 2001 From: S Plotnikov Date: Mon, 29 Jun 2026 18:26:36 +0200 Subject: [PATCH] feat: add Missing items entry to navigation drawer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DrawerViewModel now computes the count of mandatory products at zero quantity across all households in the same refresh loop (no extra API calls). The drawer item shows the count inline ("Missing items · 3") and renders in error color when non-zero; navigates to Dashboard which already surfaces the warning card. --- .../dev/scuttle/inventory/MainActivity.kt | 4 ++++ .../dev/scuttle/inventory/ui/app/AppDrawer.kt | 24 +++++++++++++++++++ .../inventory/ui/app/DrawerViewModel.kt | 11 ++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/dev/scuttle/inventory/MainActivity.kt b/app/src/main/java/dev/scuttle/inventory/MainActivity.kt index ccfeb41..7ee9008 100644 --- a/app/src/main/java/dev/scuttle/inventory/MainActivity.kt +++ b/app/src/main/java/dev/scuttle/inventory/MainActivity.kt @@ -136,6 +136,10 @@ private fun InventoryNavHost( closeDrawer() navController.navigate(Routes.HOUSEHOLDS) { launchSingleTop = true } }, + onNavigateMissingItems = { + closeDrawer() + navController.navigate(Routes.DASHBOARD) { launchSingleTop = true } + }, onNavigateLocation = { householdId, locationId -> closeDrawer() navController.navigate(Routes.location(householdId, locationId)) { diff --git a/app/src/main/java/dev/scuttle/inventory/ui/app/AppDrawer.kt b/app/src/main/java/dev/scuttle/inventory/ui/app/AppDrawer.kt index a66201f..844dbb0 100644 --- a/app/src/main/java/dev/scuttle/inventory/ui/app/AppDrawer.kt +++ b/app/src/main/java/dev/scuttle/inventory/ui/app/AppDrawer.kt @@ -18,6 +18,7 @@ import androidx.compose.material.icons.filled.People import androidx.compose.material.icons.filled.Search import androidx.compose.material.icons.filled.Settings import androidx.compose.material.icons.filled.Star +import androidx.compose.material.icons.filled.Warning import androidx.compose.material3.DrawerDefaults import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon @@ -38,6 +39,7 @@ fun AppDrawer( onNavigateDashboard: () -> Unit, onNavigateSearch: (householdId: Long) -> Unit, onNavigateHouseholds: () -> Unit, + onNavigateMissingItems: () -> Unit, onNavigateLocation: (householdId: Long, locationId: Long) -> Unit, onNavigateSettings: () -> Unit, ) { @@ -93,6 +95,28 @@ fun AppDrawer( modifier = Modifier.padding(horizontal = 12.dp), ) + val missingCount = state.missingItemCount + NavigationDrawerItem( + icon = { + Icon( + Icons.Default.Warning, + contentDescription = null, + tint = if (missingCount > 0) MaterialTheme.colorScheme.error + else MaterialTheme.colorScheme.onSurfaceVariant, + ) + }, + label = { + Text( + text = if (missingCount > 0) "Missing items · $missingCount" else "Missing items", + color = if (missingCount > 0) MaterialTheme.colorScheme.error + else MaterialTheme.colorScheme.onSurfaceVariant, + ) + }, + selected = false, + onClick = onNavigateMissingItems, + modifier = Modifier.padding(horizontal = 12.dp), + ) + HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp, horizontal = 12.dp)) // Scrollable middle section — takes all remaining space diff --git a/app/src/main/java/dev/scuttle/inventory/ui/app/DrawerViewModel.kt b/app/src/main/java/dev/scuttle/inventory/ui/app/DrawerViewModel.kt index 1411933..e0a2768 100644 --- a/app/src/main/java/dev/scuttle/inventory/ui/app/DrawerViewModel.kt +++ b/app/src/main/java/dev/scuttle/inventory/ui/app/DrawerViewModel.kt @@ -24,6 +24,7 @@ data class HouseholdWithLocations( data class DrawerUiState( val entries: List = emptyList(), val locationWarnings: Map = emptyMap(), + val missingItemCount: Int = 0, val loading: Boolean = false, ) @@ -43,11 +44,19 @@ class DrawerViewModel @Inject constructor( _state.update { it.copy(loading = true) } runCatching { val households = householdRepository.list() + var missingItemCount = 0 val entries = households.map { hh -> val locations = runCatching { locationRepository.list(hh.id) }.getOrDefault(emptyList()) + for (location in locations) { + val shelves = runCatching { shelfRepository.list(hh.id, location.id) }.getOrDefault(emptyList()) + for (shelf in shelves) { + val products = runCatching { productRepository.list(hh.id, shelf.id) }.getOrDefault(emptyList()) + missingItemCount += products.count { it.is_mandatory && it.quantity == 0 } + } + } HouseholdWithLocations(hh.id, hh.name, locations) } - _state.update { it.copy(entries = entries, loading = false) } + _state.update { it.copy(entries = entries, missingItemCount = missingItemCount, loading = false) } }.onFailure { _state.update { it.copy(loading = false) } }