diff --git a/assets/js/main.js b/assets/js/main.js index e579970..ab5437f 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -242,7 +242,7 @@ const app = { buttonGroup.className = 'mt-auto pt-2 d-flex gap-2 justify-content-center w-100'; buttonGroup.innerHTML = ` - + `; @@ -496,20 +496,33 @@ const app = { 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 = ''; - if (recipe.ingredients) { - recipe.ingredients.forEach(ing => { - const li = document.createElement('li'); - li.className = 'list-group-item'; - li.textContent = `${ing.name} - ${ing.quantity} ${ing.unit}`; - ingredientsList.appendChild(li); - }); - } - - const viewRecipeModal = new bootstrap.Modal(modal); - viewRecipeModal.show(); - }, + const ingredientsList = document.getElementById('view-recipe-ingredients'); + + ingredientsList.innerHTML = ''; + + + + if (recipe.ingredients) { + + recipe.ingredients.forEach(ing => { + + const li = document.createElement('li'); + + li.className = 'list-group-item'; + + li.textContent = `${ing.name} - ${ing.quantity} ${ing.unit}`; + + ingredientsList.appendChild(li); + + }); + + } + + + + app.dom.viewRecipeModal.show(); + + }, getRecipeDataFromForm() { const recipeName = app.dom.recipeNameInput.value.trim(); const instructions = app.dom.recipeInstructionsInput.value.trim(); @@ -635,6 +648,34 @@ const app = { } }); + document.getElementById('add-recipe-options-modal').addEventListener('click', (e) => { + const btn = e.target.closest('.add-option-btn'); + if (!btn) return; + + const method = btn.dataset.method; + app.dom.addRecipeOptionsModal.hide(); + + if (method === 'scratch' || method === 'photo') { + app.ui.clearForm(); + app.dom.recipeFormModal.show(); + if (method === 'photo') { + setTimeout(() => app.dom.recipeImage.click(), 500); + } + } else if (method === 'web' || method === 'social') { + const url = prompt('Please enter the URL of the recipe:'); + if (url) { + alert('Analyzing recipe from URL... (Feature integration in progress)'); + // Here you would typically call an AI endpoint to scrape/analyze the URL + } + } else if (method === 'ingredients') { + const ingredients = prompt('What ingredients do you have? (comma separated)'); + if (ingredients) { + alert('Generating a recipe from: ' + ingredients + '... (Feature integration in progress)'); + // Here you would call an AI endpoint to generate a recipe + } + } + }); + app.dom.addIngredientBtn.addEventListener('click', () => app.ui.addIngredientRow()); app.dom.aiScanBtn.addEventListener('click', async function() { @@ -749,7 +790,7 @@ const app = { app.dom.recipeCardsContainer.addEventListener('click', function(e) { const target = e.target.closest('button'); const checkbox = e.target.closest('.select-recipe'); - const cardCol = e.target.closest('.col-12[data-id]'); + const cardCol = e.target.closest('[data-id]'); if (!cardCol) return; const recipeId = cardCol.getAttribute('data-id'); @@ -1042,12 +1083,14 @@ const app = { printShoppingListBtn: document.getElementById('print-shopping-list-btn'), recipeFormModal: new bootstrap.Modal(document.getElementById('recipe-form-modal')), + viewRecipeModal: new bootstrap.Modal(document.getElementById('view-recipe-modal')), addProductModal: new bootstrap.Modal(document.getElementById('add-product-modal')), addProductForm: document.getElementById('add-product-form'), productNameInput: document.getElementById('productName'), productQuantityInput: document.getElementById('productQuantity'), productCategoryWrapper: document.getElementById('product-category-wrapper'), productCategory: document.getElementById('productCategory'), + addRecipeOptionsModal: new bootstrap.Modal(document.getElementById('add-recipe-options-modal')), }; app.ui.loadCheckedItems(); diff --git a/index.php b/index.php index 74fa6b8..8ac5a78 100644 --- a/index.php +++ b/index.php @@ -167,7 +167,7 @@

All Recipes

-
@@ -211,6 +211,57 @@
+ + +