From d68a89a32ca808cad36d51823c8118637ed16e01 Mon Sep 17 00:00:00 2001 From: smilerz Date: Wed, 16 Feb 2022 14:07:56 -0600 Subject: [PATCH] catch empty lines in paste_ingredients --- .../apps/RecipeEditView/RecipeEditView.vue | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/vue/src/apps/RecipeEditView/RecipeEditView.vue b/vue/src/apps/RecipeEditView/RecipeEditView.vue index 1eb9c494..973b5768 100644 --- a/vue/src/apps/RecipeEditView/RecipeEditView.vue +++ b/vue/src/apps/RecipeEditView/RecipeEditView.vue @@ -969,23 +969,24 @@ export default { appendIngredients: function () { let ing_list = this.paste_ingredients.split(/\r?\n/) let step = this.recipe.steps.findIndex((x) => x.id == this.paste_step) - let order = 0 + let order = Math.max(...this.recipe.steps[step].ingredients.map((x) => x.order)) + 1 this.recipe.steps[step].ingredients_visible = true ing_list.forEach((ing) => { - this.genericPostAPI("api_ingredient_from_string", { text: ing }).then((result) => { - let unit = null - if (result.data.unit !== "") { - unit = { name: result.data.unit } - } - this.recipe.steps[step].ingredients.push({ - amount: result.data.amount, - unit: unit, - food: { name: result.data.food }, - note: result.data.note, - order: order, + if (ing.trim() !== "") { + this.genericPostAPI("api_ingredient_from_string", { text: ing }).then((result) => { + let unit = null + if (result.data.unit !== "") { + unit = { name: result.data.unit } + } + this.recipe.steps[step].ingredients.splice(order, 0, { + amount: result.data.amount, + unit: unit, + food: { name: result.data.food }, + note: result.data.note, + }) }) - }) - order++ + order++ + } }) }, },