mirror of
https://github.com/bleackstorm/satiea.git
synced 2026-12-03 07:41:56 +01:00
feat(recipes): add Cook With Stock filter, step-by-step Cooking Mode with timers, and leftovers management
This commit is contained in:
1 parent
9b44e488fc
commit
7181ea58fc
7 files changed
+1077
-6
No files matched your search
@@ -28,6 +28,7 @@ import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.AutoAwesome
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Download
|
||||
import androidx.compose.material.icons.filled.Kitchen
|
||||
import androidx.compose.material.icons.filled.People
|
||||
import androidx.compose.material.icons.filled.Schedule
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
@@ -64,12 +65,15 @@ import com.example.data.model.CustomFoodEntry
|
||||
import com.example.data.model.FoodCategory
|
||||
import com.example.data.model.FoodPreferenceEntry
|
||||
import com.example.data.model.FoodPreferenceStatus
|
||||
import com.example.data.model.InventoryItem
|
||||
import com.example.data.model.MealType
|
||||
import com.example.data.model.RecipeCategoryTag
|
||||
import com.example.data.model.RecipeEntry
|
||||
import com.example.data.model.RecipeSuggestion
|
||||
import com.example.data.model.SuggestionUiState
|
||||
import com.example.domain.DailyBenchmarkGap
|
||||
import com.example.domain.RecipeStockMatch
|
||||
import com.example.domain.RecipeStockMatcher
|
||||
import com.example.ui.common.FoodCategoryColorDot
|
||||
import com.example.ui.common.badgeBorderColor
|
||||
import com.example.ui.common.badgeContainerColor
|
||||
@@ -85,6 +89,7 @@ private enum class RecipesSubTab(val label: String) {
|
||||
@Composable
|
||||
fun RecipesScreen(
|
||||
recipes: List<RecipeEntry>,
|
||||
inventoryItems: List<InventoryItem> = emptyList(),
|
||||
customFoods: List<CustomFoodEntry>,
|
||||
foodPreferences: List<FoodPreferenceEntry>,
|
||||
selectedIdeaMealType: MealType,
|
||||
@@ -105,20 +110,44 @@ fun RecipesScreen(
|
||||
var activeSubTab by rememberSaveable { mutableStateOf(RecipesSubTab.BOOK) }
|
||||
var searchQuery by rememberSaveable { mutableStateOf("") }
|
||||
var selectedTag by rememberSaveable { mutableStateOf<String?>(null) }
|
||||
var filterByStockOnly by rememberSaveable { mutableStateOf(false) }
|
||||
var cravingNote by rememberSaveable { mutableStateOf("") }
|
||||
|
||||
val customCategoriesLookup = remember(customFoods) {
|
||||
CustomFoodEntry.buildCategoriesLookup(customFoods)
|
||||
}
|
||||
|
||||
val filteredRecipes = remember(recipes, searchQuery, selectedTag) {
|
||||
val stockMatchesByRecipeId = remember(recipes, inventoryItems) {
|
||||
if (inventoryItems.isEmpty()) {
|
||||
emptyMap()
|
||||
} else {
|
||||
recipes.associate { recipe ->
|
||||
recipe.id to RecipeStockMatcher.evaluate(recipe, inventoryItems)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val stockReadyCount = remember(stockMatchesByRecipeId) {
|
||||
stockMatchesByRecipeId.values.count { it.isAlmostAvailable }
|
||||
}
|
||||
|
||||
val filteredRecipes = remember(recipes, searchQuery, selectedTag, filterByStockOnly, stockMatchesByRecipeId) {
|
||||
val query = searchQuery.trim().lowercase(Locale.FRENCH)
|
||||
recipes.filter { recipe ->
|
||||
val filtered = recipes.filter { recipe ->
|
||||
val matchesTag = selectedTag == null || recipe.categoryTag.equals(selectedTag, ignoreCase = true)
|
||||
val matchesQuery = query.isBlank() ||
|
||||
recipe.title.lowercase(Locale.FRENCH).contains(query) ||
|
||||
recipe.parsedIngredients().any { it.name.lowercase(Locale.FRENCH).contains(query) }
|
||||
matchesTag && matchesQuery
|
||||
val matchesStock = !filterByStockOnly || (stockMatchesByRecipeId[recipe.id]?.isAlmostAvailable == true)
|
||||
matchesTag && matchesQuery && matchesStock
|
||||
}
|
||||
if (filterByStockOnly) {
|
||||
filtered.sortedWith(
|
||||
compareBy<RecipeEntry> { stockMatchesByRecipeId[it.id]?.missingCount ?: Int.MAX_VALUE }
|
||||
.thenByDescending { stockMatchesByRecipeId[it.id]?.availableCount ?: 0 }
|
||||
)
|
||||
} else {
|
||||
filtered
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,10 +345,34 @@ fun RecipesScreen(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
if (inventoryItems.isNotEmpty()) {
|
||||
item {
|
||||
FilterChip(
|
||||
selected = filterByStockOnly,
|
||||
onClick = { filterByStockOnly = !filterByStockOnly },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Kitchen,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
},
|
||||
label = { Text("Avec mon stock ($stockReadyCount)") },
|
||||
colors = FilterChipDefaults.filterChipColors(
|
||||
selectedContainerColor = MaterialTheme.colorScheme.secondaryContainer,
|
||||
selectedLabelColor = MaterialTheme.colorScheme.onSecondaryContainer
|
||||
),
|
||||
modifier = Modifier.testTag("recipe_filter_stock")
|
||||
)
|
||||
}
|
||||
}
|
||||
item {
|
||||
FilterChip(
|
||||
selected = selectedTag == null,
|
||||
onClick = { selectedTag = null },
|
||||
selected = selectedTag == null && !filterByStockOnly,
|
||||
onClick = {
|
||||
selectedTag = null
|
||||
filterByStockOnly = false
|
||||
},
|
||||
label = { Text("Toutes") },
|
||||
colors = FilterChipDefaults.filterChipColors(
|
||||
selectedContainerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
@@ -373,6 +426,7 @@ fun RecipesScreen(
|
||||
onClick = {
|
||||
searchQuery = ""
|
||||
selectedTag = null
|
||||
filterByStockOnly = false
|
||||
}
|
||||
) {
|
||||
Text("Réinitialiser les filtres")
|
||||
@@ -384,6 +438,7 @@ fun RecipesScreen(
|
||||
items(filteredRecipes, key = { it.id }) { recipe ->
|
||||
RecipeCardItem(
|
||||
recipe = recipe,
|
||||
stockMatch = stockMatchesByRecipeId[recipe.id],
|
||||
customCategoriesLookup = customCategoriesLookup,
|
||||
onClick = { onRecipeClick(recipe) }
|
||||
)
|
||||
@@ -417,6 +472,7 @@ fun RecipesScreen(
|
||||
@Composable
|
||||
private fun RecipeCardItem(
|
||||
recipe: RecipeEntry,
|
||||
stockMatch: RecipeStockMatch? = null,
|
||||
customCategoriesLookup: Map<String, List<FoodCategory>>,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
@@ -498,6 +554,39 @@ private fun RecipeCardItem(
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
|
||||
val stockBadge = stockMatch?.badgeLabel()
|
||||
if (stockBadge != null) {
|
||||
Spacer(modifier = Modifier.height(6.dp))
|
||||
val (bg, fg) = when {
|
||||
stockMatch.isFullyAvailable -> MaterialTheme.colorScheme.secondaryContainer to MaterialTheme.colorScheme.onSecondaryContainer
|
||||
stockMatch.isAlmostAvailable -> MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.7f) to MaterialTheme.colorScheme.onPrimaryContainer
|
||||
else -> MaterialTheme.colorScheme.surfaceVariant to MaterialTheme.colorScheme.onSurfaceVariant
|
||||
}
|
||||
Surface(
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
color = bg
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.padding(horizontal = 8.dp, vertical = 3.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Kitchen,
|
||||
contentDescription = null,
|
||||
tint = fg,
|
||||
modifier = Modifier.size(13.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(5.dp))
|
||||
Text(
|
||||
text = stockBadge,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = fg
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
// Metadata chips (prep time, servings, ingredient count)
|
||||
|
||||
Reference in new issue
Block a user