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, },