fix: Ingredient sections lost after parsing (#1368)

* fixed bug where ingredient titles were lost after parsing

* added fallback in case of strange behavior during parsing

* removed unnecessary linebreak
This commit is contained in:
Michael Genson 2022-06-10 21:17:51 -05:00 committed by GitHub
parent 92ccbae657
commit 504bf41b9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -140,6 +140,16 @@ export default defineComponent({
const { data } = await api.recipes.parseIngredients(parser.value, raw);
if (data) {
// When we send the recipe ingredient text to be parsed, we lose the reference to the original unparsed ingredient.
// Generally this is fine, but if the unparsed ingredient had a title, we lose it; we add back the title for each ingredient here.
try {
for (let i = 0; i < recipe.value.recipeIngredient.length; i++) {
data[i].ingredient.title = recipe.value.recipeIngredient[i].title;
}
} catch (TypeError) {
console.error("Index Mismatch Error during recipe ingredient parsing; did the number of ingredients change?")
}
parsedIng.value = data;
errors.value = data.map((ing, index: number) => {