From 504bf41b9c7311aa6b7afff1eb3fb10a1672fdb1 Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Fri, 10 Jun 2022 21:17:51 -0500 Subject: [PATCH] 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 --- frontend/pages/recipe/_slug/ingredient-parser.vue | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frontend/pages/recipe/_slug/ingredient-parser.vue b/frontend/pages/recipe/_slug/ingredient-parser.vue index 30485aedb95b..45179efdbad4 100644 --- a/frontend/pages/recipe/_slug/ingredient-parser.vue +++ b/frontend/pages/recipe/_slug/ingredient-parser.vue @@ -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) => {