import { useState, useEffect } from 'react'; import { useParams, useNavigate, Link } from 'react-router-dom'; import { fetchRecipe, updateRecipe, deleteRecipe } from '../api'; import { useAuth } from '../context/AuthContext'; import CategoryBadge from '../components/CategoryBadge'; import IngredientList from '../components/IngredientList'; import StepList from '../components/StepList'; const CATEGORIES = ['Frühstück', 'Hauptgericht', 'Dessert', 'Snack', 'Getränk', 'Sonstiges']; export default function RecipeDetail() { const { id } = useParams(); const navigate = useNavigate(); const { user } = useAuth(); const [recipe, setRecipe] = useState(null); const [loading, setLoading] = useState(true); const [editing, setEditing] = useState(false); const [form, setForm] = useState({}); useEffect(() => { load(); }, [id]); const load = async () => { try { const data = await fetchRecipe(id); setRecipe(data); setForm(data); } catch (e) { navigate('/'); } setLoading(false); }; const handleSave = async () => { await updateRecipe(id, { ...form, user_id: user?.id || null }); setRecipe(form); setEditing(false); }; const handleDelete = async () => { if (!confirm('Rezept wirklich löschen?')) return; await deleteRecipe(id); navigate('/'); }; const updateField = (field, value) => setForm(prev => ({ ...prev, [field]: value })); if (loading) return
{recipe.description}
)} {editing && (Quelle: @{author} (TikTok)
)}