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
Laden...
; if (!recipe) return null; const sourceUrl = recipe.source_url || recipe.tiktok_url; const sourceType = recipe.source || 'tiktok'; let videoId = null; let embedUrl = null; if (sourceUrl) { const ttMatch = sourceUrl.match(/video\/(\d+)/); if (ttMatch) { videoId = ttMatch[1]; embedUrl = `https://www.tiktok.com/embed/v2/${videoId}`; } } const author = recipe.source_author || recipe.tiktok_author; return (
← Zurück
{embedUrl && (