health: fix recipe save crash and prevent duplicate saves
- Commit
4b70e8f3bd92b3380d1caeec4df703059af3af0c- Author
- Vayun Mathur <[email protected]>
- When
- 2026-08-04 17:00 UTC (4 months ago)
- Parents
a0a68fe
Diff
health/src/main/java/com/vayunmathur/health/ui/RecipeManagementPage.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/RecipeManagementPage.kt b/health/src/main/java/com/vayunmathur/health/ui/RecipeManagementPage.ktindex 7ac18a2699..c00fdb6eaf 100644--- a/health/src/main/java/com/vayunmathur/health/ui/RecipeManagementPage.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/RecipeManagementPage.kt@@ -201,6 +201,9 @@ fun RecipeEditorPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel, var showSearch by remember { mutableStateOf(false) } var editingIngredientData by remember { mutableStateOf<RecipeIngredientData?>(null) } var isAddingNewIngredient by remember { mutableStateOf(false) }+ // Guards against repeated taps launching multiple saves (which created+ // duplicate recipes and popped the back stack more than once).+ var saving by remember { mutableStateOf(false) } // Load existing recipe if editing LaunchedEffect(recipeId) {@@ -303,6 +306,8 @@ fun RecipeEditorPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel, Button( onClick = {+ if (saving) return@Button+ saving = true val items = recipeIngredients.map { HealthViewModel.RecipeIngredientLoad(it.ingredient, it.unit, it.quantity) }@@ -311,7 +316,7 @@ fun RecipeEditorPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel, } }, modifier = Modifier.fillMaxWidth(),- enabled = recipeName.isNotBlank() && recipeIngredients.isNotEmpty()+ enabled = recipeName.isNotBlank() && recipeIngredients.isNotEmpty() && !saving ) { Text(stringResource(R.string.save_recipe)) }