mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-24 07:15:24 -07:00
fix create missing food/unit
This commit is contained in:
parent
22183d4969
commit
01cd146592
1 changed files with 15 additions and 10 deletions
|
@ -118,7 +118,7 @@
|
||||||
v-if="errors[index].unitError && errors[index].unitErrorMessage !== ''"
|
v-if="errors[index].unitError && errors[index].unitErrorMessage !== ''"
|
||||||
color="warning"
|
color="warning"
|
||||||
size="small"
|
size="small"
|
||||||
@click="createUnit(ing.ingredient.unit!, index)"
|
@click="createUnit(errors[index].unitName, index)"
|
||||||
>
|
>
|
||||||
{{ errors[index].unitErrorMessage }}
|
{{ errors[index].unitErrorMessage }}
|
||||||
</BaseButton>
|
</BaseButton>
|
||||||
|
@ -126,7 +126,7 @@
|
||||||
v-if="errors[index].foodError && errors[index].foodErrorMessage !== ''"
|
v-if="errors[index].foodError && errors[index].foodErrorMessage !== ''"
|
||||||
color="warning"
|
color="warning"
|
||||||
size="small"
|
size="small"
|
||||||
@click="createFood(ing.ingredient.food!, index)"
|
@click="createFood(errors[index].foodName, index)"
|
||||||
>
|
>
|
||||||
{{ errors[index].foodErrorMessage }}
|
{{ errors[index].foodErrorMessage }}
|
||||||
</BaseButton>
|
</BaseButton>
|
||||||
|
@ -162,8 +162,10 @@ import type { Parser } from "~/lib/api/user/recipes/recipe";
|
||||||
|
|
||||||
interface Error {
|
interface Error {
|
||||||
ingredientIndex: number;
|
ingredientIndex: number;
|
||||||
|
unitName: string;
|
||||||
unitError: boolean;
|
unitError: boolean;
|
||||||
unitErrorMessage: string;
|
unitErrorMessage: string;
|
||||||
|
foodName: string;
|
||||||
foodError: boolean;
|
foodError: boolean;
|
||||||
foodErrorMessage: string;
|
foodErrorMessage: string;
|
||||||
}
|
}
|
||||||
|
@ -229,12 +231,14 @@ export default defineNuxtComponent({
|
||||||
const unitError = !checkForUnit(ing.ingredient.unit!);
|
const unitError = !checkForUnit(ing.ingredient.unit!);
|
||||||
const foodError = !checkForFood(ing.ingredient.food!);
|
const foodError = !checkForFood(ing.ingredient.food!);
|
||||||
|
|
||||||
|
const unit = ing.ingredient.unit?.name || i18n.t("recipe.parser.no-unit");
|
||||||
|
const food = ing.ingredient.food?.name || i18n.t("recipe.parser.no-food");
|
||||||
|
|
||||||
let unitErrorMessage = "";
|
let unitErrorMessage = "";
|
||||||
let foodErrorMessage = "";
|
let foodErrorMessage = "";
|
||||||
|
|
||||||
if (unitError) {
|
if (unitError) {
|
||||||
if (ing?.ingredient?.unit?.name) {
|
if (ing?.ingredient?.unit?.name) {
|
||||||
const unit = ing.ingredient.unit.name || i18n.t("recipe.parser.no-unit");
|
|
||||||
ing.ingredient.unit = undefined;
|
ing.ingredient.unit = undefined;
|
||||||
unitErrorMessage = i18n.t("recipe.parser.missing-unit", { unit }).toString();
|
unitErrorMessage = i18n.t("recipe.parser.missing-unit", { unit }).toString();
|
||||||
}
|
}
|
||||||
|
@ -242,7 +246,6 @@ export default defineNuxtComponent({
|
||||||
|
|
||||||
if (foodError) {
|
if (foodError) {
|
||||||
if (ing?.ingredient?.food?.name) {
|
if (ing?.ingredient?.food?.name) {
|
||||||
const food = ing.ingredient.food.name || i18n.t("recipe.parser.no-food");
|
|
||||||
ing.ingredient.food = undefined;
|
ing.ingredient.food = undefined;
|
||||||
foodErrorMessage = i18n.t("recipe.parser.missing-food", { food }).toString();
|
foodErrorMessage = i18n.t("recipe.parser.missing-food", { food }).toString();
|
||||||
}
|
}
|
||||||
|
@ -251,8 +254,10 @@ export default defineNuxtComponent({
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ingredientIndex: index,
|
ingredientIndex: index,
|
||||||
|
unitName: unit,
|
||||||
unitError,
|
unitError,
|
||||||
unitErrorMessage,
|
unitErrorMessage,
|
||||||
|
foodName: food,
|
||||||
foodError,
|
foodError,
|
||||||
foodErrorMessage,
|
foodErrorMessage,
|
||||||
} as Error;
|
} as Error;
|
||||||
|
@ -325,24 +330,24 @@ export default defineNuxtComponent({
|
||||||
return !!food?.id;
|
return !!food?.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createFood(food: CreateIngredientFood | undefined, index: number) {
|
async function createFood(foodName: string, index: number) {
|
||||||
if (!food) {
|
if (!foodName) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foodData.data.name = food.name;
|
foodData.data.name = foodName;
|
||||||
parsedIng.value[index].ingredient.food = await foodStore.actions.createOne(foodData.data) || undefined;
|
parsedIng.value[index].ingredient.food = await foodStore.actions.createOne(foodData.data) || undefined;
|
||||||
errors.value[index].foodError = false;
|
errors.value[index].foodError = false;
|
||||||
|
|
||||||
foodData.reset();
|
foodData.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createUnit(unit: CreateIngredientUnit | undefined, index: number) {
|
async function createUnit(unitName: string | undefined, index: number) {
|
||||||
if (!unit) {
|
if (!unitName) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unitData.data.name = unit.name;
|
unitData.data.name = unitName;
|
||||||
parsedIng.value[index].ingredient.unit = await unitStore.actions.createOne(unitData.data) || undefined;
|
parsedIng.value[index].ingredient.unit = await unitStore.actions.createOne(unitData.data) || undefined;
|
||||||
errors.value[index].unitError = false;
|
errors.value[index].unitError = false;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue