Editing ingredients shouldn't kill the product
This commit is contained in:
parent
8f5355844c
commit
d070b7dcf7
2 changed files with 10 additions and 4 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue