diff --git a/api/save_recipe.php b/api/save_recipe.php index 8ec93b3..3ca3016 100644 --- a/api/save_recipe.php +++ b/api/save_recipe.php @@ -71,8 +71,8 @@ try { $imageUrl = $existing['image_url']; } - $stmt = $pdo->prepare("UPDATE recipes SET name = ?, guests = ?, category = ?, image_url = ?, user_id = ? WHERE id = ?"); - $stmt->execute([$data['name'], $data['guests'], $category, $imageUrl, $userId, $recipeId]); + $stmt = $pdo->prepare("UPDATE recipes SET name = ?, guests = ?, category = ?, image_url = ?, instructions = ?, user_id = ? WHERE id = ?"); + $stmt->execute([$data['name'], $data['guests'], $category, $imageUrl, $data['instructions'] ?? null, $userId, $recipeId]); // Easiest way to handle ingredients is to delete old ones and insert new ones $stmt = $pdo->prepare("DELETE FROM ingredients WHERE recipe_id = ?"); @@ -81,8 +81,8 @@ try { } else { // Insert new recipe $category = !empty($data['category']) ? $data['category'] : 'No category'; - $stmt = $pdo->prepare("INSERT INTO recipes (name, guests, category, image_url, user_id) VALUES (?, ?, ?, ?, ?)"); - $stmt->execute([$data['name'], $data['guests'], $category, $imageUrl, $userId]); + $stmt = $pdo->prepare("INSERT INTO recipes (name, guests, category, image_url, instructions, user_id) VALUES (?, ?, ?, ?, ?, ?)"); + $stmt->execute([$data['name'], $data['guests'], $category, $imageUrl, $data['instructions'] ?? null, $userId]); $recipeId = $pdo->lastInsertId(); } diff --git a/api/scan_recipe.php b/api/scan_recipe.php index 37ef9ca..25cc334 100644 --- a/api/scan_recipe.php +++ b/api/scan_recipe.php @@ -28,6 +28,7 @@ Provide the information in JSON format IN ENGLISH: - name: Ingredient name - quantity: Numeric quantity (float) - unit: Unit of measurement (e.g., 'g', 'kg', 'ml', 'l', 'pcs', 'pack') +- instructions: A string containing clear, step-by-step cooking instructions. Use newlines (\n) between steps. - guests: Default number of guests/portions (integer) Important: @@ -71,6 +72,7 @@ Provide the information in JSON format IN ENGLISH: - name: Ingredient name - quantity: Numeric quantity (float) - unit: Unit of measurement (e.g., 'g', 'kg', 'ml', 'l', 'pcs', 'pack') +- instructions: A string containing clear, step-by-step cooking instructions. Use newlines (\n) between steps. - guests: Default number of guests/portions (integer) Important: diff --git a/assets/images/recipes/697d352c8634d-Screenshot 2026-01-30 at 23.47.21.png b/assets/images/recipes/697d352c8634d-Screenshot 2026-01-30 at 23.47.21.png new file mode 100644 index 0000000..8747ff5 Binary files /dev/null and b/assets/images/recipes/697d352c8634d-Screenshot 2026-01-30 at 23.47.21.png differ diff --git a/assets/js/main.js b/assets/js/main.js index 407f56b..40a60e3 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -394,6 +394,7 @@ const app = { clearForm() { app.dom.recipeIdInput.value = ''; app.dom.recipeNameInput.value = ''; + app.dom.recipeInstructionsInput.value = ''; app.dom.recipeCategoryInput.value = ''; app.dom.recipeImage.value = ''; app.dom.guestCountInput.value = '1'; @@ -409,6 +410,7 @@ const app = { app.dom.recipeIdInput.value = recipe.id; app.dom.recipeNameInput.value = recipe.name; + app.dom.recipeInstructionsInput.value = recipe.instructions || ''; app.dom.recipeCategoryInput.value = recipe.category || ''; app.dom.guestCountInput.value = recipe.guests; @@ -450,6 +452,7 @@ const app = { recipe.category === 'Dinner' ? 'Lunch/Dinner' : recipe.category === 'Appetizers' ? 'Appetizers' : 'No category'; document.getElementById('view-recipe-guests').textContent = recipe.guests; + document.getElementById('view-recipe-instructions').textContent = recipe.instructions || 'No instructions provided.'; const ingredientsList = document.getElementById('view-recipe-ingredients'); ingredientsList.innerHTML = ''; @@ -467,6 +470,7 @@ const app = { }, getRecipeDataFromForm() { const recipeName = app.dom.recipeNameInput.value.trim(); + const instructions = app.dom.recipeInstructionsInput.value.trim(); const guests = parseInt(app.dom.guestCountInput.value, 10) || 0; const category = app.dom.recipeCategoryInput.value; @@ -486,7 +490,7 @@ const app = { }); if (recipeName && guests > 0 && ingredients.length > 0) { - return { name: recipeName, guests, ingredients, category }; + return { name: recipeName, instructions, guests, ingredients, category }; } return null; }, @@ -607,6 +611,7 @@ const app = { if (result.success) { const data = result.data; if (data.name) app.dom.recipeNameInput.value = data.name; + if (data.instructions) app.dom.recipeInstructionsInput.value = data.instructions; if (data.category) app.dom.recipeCategoryInput.value = data.category; if (data.guests) app.dom.guestCountInput.value = data.guests; @@ -657,6 +662,7 @@ const app = { const formData = new FormData(); formData.append('name', recipeData.name); + formData.append('instructions', recipeData.instructions); formData.append('guests', recipeData.guests); formData.append('category', recipeData.category); formData.append('ingredients', JSON.stringify(recipeData.ingredients)); @@ -943,6 +949,7 @@ const app = { init() { app.dom = { recipeNameInput: document.getElementById('recipeName'), + recipeInstructionsInput: document.getElementById('recipeInstructions'), guestCountInput: document.getElementById('guestCount'), portionsPerGuestInput: document.getElementById('portionsPerGuest'), ingredientsContainer: document.getElementById('ingredients-container'), diff --git a/db/migrations/008_add_instructions_to_recipes.sql b/db/migrations/008_add_instructions_to_recipes.sql new file mode 100644 index 0000000..df63dbb --- /dev/null +++ b/db/migrations/008_add_instructions_to_recipes.sql @@ -0,0 +1,2 @@ +-- Add instructions column to recipes table +ALTER TABLE `recipes` ADD COLUMN `instructions` TEXT DEFAULT NULL; diff --git a/index.php b/index.php index 74cafba..f6b4895 100644 --- a/index.php +++ b/index.php @@ -76,15 +76,11 @@
Guest count: