import React, { useState } from 'react'; import { addRecipe } from "../services/frontendApi.js"; import { useNavigate } from "react-router-dom"; import AddBulkIngredients from "../components/AddBulkIngredients.tsx" import AddIngredientsForm from "../components/AddIngredientsForm.tsx" function AddRecipe() { const [newRecipeId, setNewRecipeId] = useState(null); const navigate = useNavigate(); const [ingredients, setIngredients] = useState<{ quantity: number; unit: string; name: string }[]>([]); const [showBulkForm, setShowBulkForm] = useState(true); const addRecipeForm = async (event: React.FormEvent) => { event.preventDefault(); const nameElement = document.getElementById('ar-name') as HTMLInputElement | null; const cuisineElement = document.getElementById('ar-cuisine') as HTMLInputElement | null; if (nameElement && cuisineElement) { const recipeData = { name: nameElement.value, cuisine: cuisineElement.value, ingredients: ingredients, steps: { 1: 'step 1', 2: 'step 2' } } console.log(recipeData) const data = await addRecipe(recipeData); setNewRecipeId(data.id); } }; React.useEffect(() => { if (newRecipeId !== null) { navigate(`/recipe/${newRecipeId}`); } }, [newRecipeId, navigate]); return (
{showBulkForm ? : }
    {ingredients.map((ing, index) => (
  • {`${ing.quantity} ${ing.unit} ${ing.name}`}
  • ))}
) } export default AddRecipe