From d070b7dcf71b873fc6e143376617a6e90c5085d9 Mon Sep 17 00:00:00 2001 From: jableader Date: Wed, 17 Jan 2024 23:18:33 +1100 Subject: [PATCH] Editing ingredients shouldn't kill the product --- src/components/EditRecipePage.vue | 10 ++++++++-- src/components/IngredientLine.vue | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/EditRecipePage.vue b/src/components/EditRecipePage.vue index b56204f..ba4a4e0 100644 --- a/src/components/EditRecipePage.vue +++ b/src/components/EditRecipePage.vue @@ -136,11 +136,17 @@ export default { } }, async updateProduct(ingredient, product_link) { - ingredient.product = await data.parseProduct(ingredient, product_link); + const product = await data.parseProduct(ingredient, product_link); + this.recipe.ingredients = this.recipe.ingredients.map(i => i.name == ingredient.name ? { ...i, product } : i); }, async updateIngredient(ingredient, line) { const newIngredients = await data.parseIngredients([line]); - this.recipe.ingredients = this.recipe.ingredients.map(i => i == ingredient ? newIngredients[0] : i); + const newIngredient = newIngredients[0]; + if (!newIngredient?.product) { + newIngredient.product = ingredient.product; + } + + this.recipe.ingredients = this.recipe.ingredients.map(i => i == ingredient ? newIngredient : i); }, deleteIngredient(ingredient) { this.recipe.ingredients = this.recipe.ingredients.filter(i => i != ingredient); diff --git a/src/components/IngredientLine.vue b/src/components/IngredientLine.vue index 075f9fa..50761c3 100644 --- a/src/components/IngredientLine.vue +++ b/src/components/IngredientLine.vue @@ -29,8 +29,8 @@ export default { watch: { ingredient: { handler: function (newIngredient) { - this.ingredientText = newIngredient?.line ?? ""; - this.productLink = newIngredient.product?.link ?? ""; + this.ingredientText = newIngredient?.line ?? this.ingredientText; + this.productLink = newIngredient.product?.link ?? this.productLink; }, deep: true, },