fixed quick ingredient import in recipe editor

This commit is contained in:
vabene1111 2023-06-29 17:13:53 +02:00
parent 8e81512735
commit ce02a23dbb

View File

@ -1254,23 +1254,28 @@ export default {
ing_list.forEach((ing) => { ing_list.forEach((ing) => {
if (ing.trim() !== "") { if (ing.trim() !== "") {
promises.push(this.genericPostAPI("api_ingredient_from_string", {text: ing}).then((result) => { promises.push(this.genericPostAPI("api_ingredient_from_string", {text: ing}).then((result) => {
let unit = null let unit = null
if (result.data.unit !== "" && result.data.unit !== null) { if (result.data.unit !== "" && result.data.unit !== null) {
unit = {name: result.data.unit} unit = {name: result.data.unit}
} }
parsed_ing_list.push({ let new_ingredient = {
amount: result.data.amount, amount: result.data.amount,
unit: unit, unit: unit,
food: {name: result.data.food}, food: {name: result.data.food},
note: result.data.note, note: result.data.note,
original_text: ing, original_text: ing,
}) }
console.log(ing, new_ingredient)
parsed_ing_list.push(new_ingredient)
})) }))
} }
}) })
Promise.allSettled(promises).then(() => { Promise.allSettled(promises).then(() => {
ing_list.forEach(ing => { ing_list.forEach(ing => {
if(ing.trim() !== ""){
step.ingredients.push(parsed_ing_list.find(x => x.original_text === ing)) step.ingredients.push(parsed_ing_list.find(x => x.original_text === ing))
}
}) })
}) })
}, },