- {recipeWorkingCopy.ingredients.map((ing, i) => (
- -
- {ing.amount} {ing.unit ?? ""} {ing.name}
-
+
{/* Instructions */}
Zubereitung
- {recipeWorkingCopy.instructions}
+ {recipe.instructions}
{/* Action buttons */}
diff --git a/frontend/src/components/RecipeEditor.tsx b/frontend/src/components/RecipeEditor.tsx
index dec8f64..be32a18 100644
--- a/frontend/src/components/RecipeEditor.tsx
+++ b/frontend/src/components/RecipeEditor.tsx
@@ -1,7 +1,7 @@
import { useState } from "react"
import type { Recipe } from "../types/recipe"
-import type { Ingredient } from "../types/ingredient"
-import {IngredientListEditor} from "./IngredientListEditor"
+import type { IngredientGroup } from "../types/ingredientGroup"
+import { IngredientGroupListEditor } from "./IngredientGroupListEditor"
type RecipeEditorProps = {
recipe: Recipe
@@ -12,6 +12,7 @@ type RecipeEditorProps = {
/**
* Editor component for managing a recipe, including title,
* ingredients (with amount, unit, name), instructions, and image URL.
+ * @todo adapt to ingredientGroups!
*/
export default function RecipeEditor({ recipe, onSave, onCancel }: RecipeEditorProps) {
/** draft of the new recipe */
@@ -23,8 +24,8 @@ export default function RecipeEditor({ recipe, onSave, onCancel }: RecipeEditorP
* Update ingredients
* @param ingredients new ingredients
*/
- const updateIngredients = (ingredients: Ingredient[]) => {
- setDraft({ ...draft, ingredients })
+ const updateIngredientGroupList = (ingredientGroupList: IngredientGroup[]) => {
+ setDraft({ ...draft, ingredientGroupList })
}
/**
* Validate recipe
@@ -40,7 +41,7 @@ export default function RecipeEditor({ recipe, onSave, onCancel }: RecipeEditorP
// the incredient list must not be empty
// @todo enhance validation and visualization of ingredient errors
- if (!draft.ingredients || draft.ingredients.length === 0) {
+ if (!draft.ingredientGroupList || draft.ingredientGroupList.length === 0) {
newErrors.ingredients = true
}
@@ -99,9 +100,9 @@ export default function RecipeEditor({ recipe, onSave, onCancel }: RecipeEditorP
{/* Ingredient List - @todo better visualization of errors! */}
-
diff --git a/frontend/src/mock_data/recipes.ts b/frontend/src/mock_data/recipes.ts
index 48b6747..350ab67 100644
--- a/frontend/src/mock_data/recipes.ts
+++ b/frontend/src/mock_data/recipes.ts
@@ -9,10 +9,14 @@ export const recipes: Recipe[] = [
id: "1",
title: "Spaghetti Bolognese",
servings: { amount: 1, unit: "Person"},
- ingredients: [
- { name: "Spaghetti", amount: 200, unit: "g" },
- { name: "Ground Beef", amount: 300, unit: "g" },
- { name: "Tomato Sauce", amount: 400, unit: "ml" }
+ ingredientGroupList: [
+ {
+ ingredientList: [
+ { name: "Spaghetti", amount: 200, unit: "g" },
+ { name: "Ground Beef", amount: 300, unit: "g" },
+ { name: "Tomato Sauce", amount: 400, unit: "ml" }
+ ]
+ }
],
instructions: "Cook pasta. Prepare sauce. Mix together. Serve hot.",
//imageUrl: "https://source.unsplash.com/400x300/?spaghetti"
@@ -21,15 +25,39 @@ export const recipes: Recipe[] = [
id: "2",
title: "Spaghetti Carbonara",
servings: { amount: 4, unit: "Persons"},
- ingredients: [
- { name: "Spaghetti", amount: 500, unit: "g" },
- { name: "Bacon", amount: 150, unit: "g" },
- { name: "Cream", amount: 200, unit: "ml" },
- { name: "Onion", amount: 1},
- { name: "Parmesan cheese", amount: 200, unit: "g"},
- { name: "Olives", amount: 100, unit: "g"}
+ ingredientGroupList: [
+ {
+ ingredientList:[
+ { name: "Spaghetti", amount: 500, unit: "g" },
+ { name: "Bacon", amount: 150, unit: "g" },
+ { name: "Cream", amount: 200, unit: "ml" },
+ { name: "Onion", amount: 1},
+ { name: "Parmesan cheese", amount: 200, unit: "g"},
+ { name: "Olives", amount: 100, unit: "g"}
+ ]
+ }
],
instructions: "Cook pasta. Prepare sauce. Mix together. Serve hot.",
//imageUrl: "https://source.unsplash.com/400x300/?spaghetti"
},
+{ id: "3",
+ title: "Apfelkuchen Edeltrud",
+ servings: { amount: 1, unit: "Kuchen"},
+ ingredientGroupList:[
+ {
+ title: "Fuer den Teig",
+ ingredientList: [
+ { name: "Mehl", amount: 400, unit: "g" }
+ ]
+ },
+ {
+ title: "Fuer die Fuellung",
+ ingredientList:[
+ {name: "Aepfel", amount: 4},
+ {name: "Rosinen", amount: 1, unit: "Hand voll"}
+ ]
+ }
+ ],
+ instructions: "Einen Muerbteig von 400 g Mehl zubereiten"
+}
]
diff --git a/frontend/src/types/ingredientGroup.ts b/frontend/src/types/ingredientGroup.ts
new file mode 100644
index 0000000..b5c89cd
--- /dev/null
+++ b/frontend/src/types/ingredientGroup.ts
@@ -0,0 +1,18 @@
+import type { Ingredient } from "./ingredient"
+/**
+ * A group of ingredients
+ * Consisting of title and ingredient list, this interface is used to group
+ * the ingredients for a specific part of the dish, e.g., dough, filling and
+ * icing of a cake
+ */
+
+export interface IngredientGroup {
+ /**
+ * Title of the group describing its purpose
+ * The title is optional as recipes consisting of a single ingredient group usually don't
+ * supply a title
+ */
+ title? : string
+ /** Ingredients */
+ ingredientList : Ingredient[]
+}
\ No newline at end of file
diff --git a/frontend/src/types/recipe.ts b/frontend/src/types/recipe.ts
index 6589e58..1329fff 100644
--- a/frontend/src/types/recipe.ts
+++ b/frontend/src/types/recipe.ts
@@ -1,4 +1,4 @@
-import type { Ingredient } from "./ingredient"
+import type { IngredientGroup } from "./ingredientGroup"
import type { Servings } from "./servings"
/**
@@ -18,8 +18,8 @@ export interface Recipe {
/** Title of the recipe */
title: string
- /** List of ingredients with amount + unit */
- ingredients: Ingredient[]
+ /** List of ingredients groups containing the ingredients of the recipe */
+ ingredientGroupList: IngredientGroup[]
/** Preparation instructions */
instructions: string