@@ -27,6 +76,61 @@ export default function RecipeFinder() {
if (!user) return null;
+ const handleLogout = () => {
+ logout();
+ router.replace("/");
+ }
+ const handleProfil = () => {
+ setOpen(false);
+ console.log("Profil ansehen");
+ router.push("/profile");
+ };
+
+ const handleAdd = (ingredient: IngredientInput) => {
+ setIngredients(prev => [...prev, ingredient]);
+ };
+
+ const handleRemoveIngredient = (name: string) => {
+ setIngredients(prev => prev.filter(z => z.name !== name));
+ }
+
+ const handleEditSave = (name: string) => {
+ const amountNum = parseFloat(editAmount);
+ if (!editAmount || isNaN(amountNum) || amountNum <= 0) return;
+ setIngredients(prev => prev.map(i =>
+ i.name === name ? { ...i, amount: amountNum, unit: editUnit } : i
+ ));
+ setEditingIngredient(null);
+ };
+
+ const handleEditStart = (i: IngredientInput) => {
+ setEditingIngredient(i.name);
+ setEditAmount(String(i.amount));
+ setEditUnit(i.unit);
+ };
+
+ const handleSearch = async () => {
+ if (ingredients.length === 0) {
+ setSearchError("Bitte mindestens eine Zutat hinzufügen.");
+ return;
+ }
+ setSearchError("");
+ setSearching(true);
+ try {
+ const res = await fetchWithAuth('/recipes/search', {
+ method: "POST",
+ headers: {"Content-Type": "application/json"},
+ body: JSON.stringify({zutaten: ingredients, servings}),
+ });
+ const data = await res.json();
+ setResults(data.rezepte ?? []);
+ } catch {
+ setSearchError("Suche fehlgeschlagen.");
+ } finally {
+ setSearching(false);
+ }
+ };
+
return (
{/* Navbar */}
@@ -38,41 +142,146 @@ export default function RecipeFinder() {
-
Hallo, {user.name}
-
+
+
+
+ {open && (
+
+
+
+
+ )}
+
- {/* Dashboard Content */}
-