diff --git a/frontend/api/class-interfaces/recipes.ts b/frontend/api/class-interfaces/recipes.ts index 83549e5a242e..ca271dc0c0e0 100644 --- a/frontend/api/class-interfaces/recipes.ts +++ b/frontend/api/class-interfaces/recipes.ts @@ -10,6 +10,7 @@ const routes = { recipesCreateUrl: `${prefix}/recipes/create-url`, recipesCreateFromZip: `${prefix}/recipes/create-from-zip`, recipesCategory: `${prefix}/recipes/category`, + recipesParseIngredients: `${prefix}/parse/ingredient`, recipesRecipeSlug: (recipe_slug: string) => `${prefix}/recipes/${recipe_slug}`, recipesRecipeSlugZip: (recipe_slug: string) => `${prefix}/recipes/${recipe_slug}/zip`, @@ -81,4 +82,8 @@ export class RecipeAPI extends BaseCRUDAPI { async deleteComment(slug: string, id: number) { return await this.requests.delete(routes.recipesSlugCommentsId(slug, id)); } + + async parseIngredients(ingredients: Array) { + return await this.requests.post(routes.recipesParseIngredients, { ingredients }); + } } diff --git a/frontend/components/Domain/Recipe/RecipeIngredientEditor.vue b/frontend/components/Domain/Recipe/RecipeIngredientEditor.vue index 4992b738e38b..6e659c156f09 100644 --- a/frontend/components/Domain/Recipe/RecipeIngredientEditor.vue +++ b/frontend/components/Domain/Recipe/RecipeIngredientEditor.vue @@ -59,6 +59,9 @@ + @@ -92,6 +95,7 @@ import RecipeIngredientFoodDialog from "./RecipeIngredientFoodDialog.vue"; import { useFoods } from "~/composables/use-recipe-foods"; import { useUnits } from "~/composables/use-recipe-units"; import { validators } from "~/composables/use-validators"; +import { RecipeIngredientFood } from "~/types/api-types/recipe"; export default defineComponent({ components: { RecipeIngredientUnitDialog, RecipeIngredientFoodDialog }, @@ -115,6 +119,20 @@ export default defineComponent({ showTitle: false, }); + function checkForUnit(unit: RecipeIngredientFood) { + if (units.value && unit?.name) { + return units.value.some((u) => u.name === unit.name); + } + return false; + } + + function checkForFood(food: RecipeIngredientFood) { + if (foods.value && food?.name) { + return foods.value.some((f) => f.name === food.name); + } + return false; + } + function toggleTitle() { if (value.title) { state.showTitle = false; @@ -125,7 +143,17 @@ export default defineComponent({ } } - return { workingUnitData, unitActions, validators, foods, units, ...toRefs(state), toggleTitle }; + return { + workingUnitData, + unitActions, + validators, + foods, + units, + ...toRefs(state), + toggleTitle, + checkForUnit, + checkForFood, + }; }, }); diff --git a/frontend/components/Domain/Recipe/RecipeIngredientParserMenu.vue b/frontend/components/Domain/Recipe/RecipeIngredientParserMenu.vue new file mode 100644 index 000000000000..9dc903e7968b --- /dev/null +++ b/frontend/components/Domain/Recipe/RecipeIngredientParserMenu.vue @@ -0,0 +1,84 @@ + + + diff --git a/frontend/pages/recipe/_slug.vue b/frontend/pages/recipe/_slug.vue index dd6f4ba711ce..6ac2107bc2fd 100644 --- a/frontend/pages/recipe/_slug.vue +++ b/frontend/pages/recipe/_slug.vue @@ -110,8 +110,9 @@ />
- - {{ $t("general.new") }} + + {{ $t("general.new") }} +
@@ -252,6 +253,7 @@ import RecipeNotes from "~/components/Domain/Recipe/RecipeNotes.vue"; import RecipeImageUploadBtn from "~/components/Domain/Recipe/RecipeImageUploadBtn.vue"; import RecipeSettingsMenu from "~/components/Domain/Recipe/RecipeSettingsMenu.vue"; import RecipeIngredientEditor from "~/components/Domain/Recipe/RecipeIngredientEditor.vue"; +import RecipeIngredientParserMenu from "~/components/Domain/Recipe/RecipeIngredientParserMenu.vue"; import { Recipe } from "~/types/api-types/recipe"; import { useStaticRoutes } from "~/composables/api"; @@ -271,6 +273,7 @@ export default defineComponent({ RecipeSettingsMenu, RecipeIngredientEditor, RecipeTimeCard, + RecipeIngredientParserMenu, VueMarkdown, draggable, }, diff --git a/frontend/types/api-types/recipe.ts b/frontend/types/api-types/recipe.ts index 02b9b5855dca..4fc7bfdd90f9 100644 --- a/frontend/types/api-types/recipe.ts +++ b/frontend/types/api-types/recipe.ts @@ -80,12 +80,12 @@ export interface Recipe { comments?: CommentOut[]; } export interface RecipeIngredient { - title?: string; - note?: string; - unit?: RecipeIngredientUnit; - food?: RecipeIngredientFood; - disableAmount?: boolean; - quantity?: number; + title: string; + note: string; + unit: RecipeIngredientUnit; + food: RecipeIngredientFood; + disableAmount: boolean; + quantity: number; } export interface RecipeIngredientUnit { name?: string;