catch empty lines in paste_ingredients

This commit is contained in:
smilerz 2022-02-16 14:07:56 -06:00
parent 8b94bf1333
commit d68a89a32c
No known key found for this signature in database
GPG Key ID: 39444C7606D47126

View File

@ -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++
}
})
},
},