diff --git a/frontend/src/components/IngredientGroupListEditor.tsx b/frontend/src/components/IngredientGroupListEditor.tsx new file mode 100644 index 0000000..889fcc5 --- /dev/null +++ b/frontend/src/components/IngredientGroupListEditor.tsx @@ -0,0 +1,67 @@ +/** + * Editor for ingredient groups + */ + +import type { Ingredient } from "../types/ingredient" +import type { IngredientGroup } from "../types/ingredientGroup" +import { IngredientListEditor } from "./IngredientListEditor" + +type IngredientGroupListEditorProps = { + ingredientGroupList: IngredientGroup[] + onChange: (ingredientGroupList: IngredientGroup[]) => void +} + +export function IngredientGroupListEditor({ ingredientGroupList, onChange }: IngredientGroupListEditorProps) { + const handleUpdate = (index: number, field: keyof IngredientGroup, value: string|Ingredient[] ) => { + const updated = ingredientGroupList.map((ingGrp, i) => + i === index ? { ...ingGrp, [field]: value} : ingGrp + ) + onChange(updated) + } + const updateIngredientList = (index: number, ingredientList: Ingredient[]) => { + handleUpdate(index, "ingredientList", ingredientList) + } + + const handleAdd = () => { + onChange([...ingredientGroupList, { title: "", ingredientList: [] }]) + } + + const handleRemove = (index: number) => { + onChange(ingredientGroupList.filter((_, i) => i !== index)) + } + return ( +
+

Ingredient Groups

+ {ingredientGroupList.map((ingGrp, index) => ( +
+
+ handleUpdate(index, "title", e.target.value)} + /> + +
+ updateIngredientList(index,list)} + /> +
+ ))} + +
+ ) +} \ No newline at end of file diff --git a/frontend/src/components/IngredientListEditor.tsx b/frontend/src/components/IngredientListEditor.tsx index bbc2750..d0d4189 100644 --- a/frontend/src/components/IngredientListEditor.tsx +++ b/frontend/src/components/IngredientListEditor.tsx @@ -27,7 +27,6 @@ export function IngredientListEditor({ ingredients, onChange }: IngredientListEd return (
-

Ingredients

{ingredients.map((ing, index) => (
{recipeWorkingCopy.title} {/* Recipe image */} - {recipeWorkingCopy.imageUrl && ( + {recipe.imageUrl && ( {recipeWorkingCopy.title} )} @@ -71,17 +71,26 @@ export default function RecipeDetailView() {
{/* Ingredients */}

Zutaten

-