From 26cf158ec51f42c78fb365074d2157f1b561cb5f Mon Sep 17 00:00:00 2001 From: David Katrinka Date: Sun, 6 Jul 2025 11:20:45 +0200 Subject: [PATCH] TIST-22: added single recipe submit page and new ingredient modal --- .../Controllers/SingleSubmitController.php | 21 +++++ apps/Recipes/Templates/single-submit.php | 90 +++++++++++++++++++ apps/Recipes/urls.php | 1 + assets/css/style.css | 35 ++++++++ assets/js/single-submit.js | 55 ++++++++++++ 5 files changed, 202 insertions(+) create mode 100644 apps/Recipes/Controllers/SingleSubmitController.php create mode 100644 apps/Recipes/Templates/single-submit.php create mode 100644 assets/js/single-submit.js diff --git a/apps/Recipes/Controllers/SingleSubmitController.php b/apps/Recipes/Controllers/SingleSubmitController.php new file mode 100644 index 0000000..b4f2203 --- /dev/null +++ b/apps/Recipes/Controllers/SingleSubmitController.php @@ -0,0 +1,21 @@ + + +
+
+

Submit a Recipe

+
+
+ * +
+ +
+ * +
+ +
+ + * + + + + +
+ select 2 goes here +
+ + * +
+ +
+ + * +
+ +
+ + * +
+ +
+ * +
+ + + + +
+ + +
+
+ + + \ No newline at end of file diff --git a/apps/Recipes/urls.php b/apps/Recipes/urls.php index cfb9f0e..d185c4a 100644 --- a/apps/Recipes/urls.php +++ b/apps/Recipes/urls.php @@ -9,4 +9,5 @@ $recipes_urls = [ new Path('/catalog', new Controllers\CatalogController(), 'catalog'), new Path('/daily-meals', new Controllers\DailyMealsController, 'daily-meals'), new Path('/favorites', new Controllers\FavoritesController(), 'favorites'), + new Path('/submit', new Controllers\SingleSubmitController(), 'single-submit'), ]; diff --git a/assets/css/style.css b/assets/css/style.css index f5bfadc..7a63042 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -1217,7 +1217,42 @@ label { font-family: var(--common-font); } +.submit-recipe { + margin-top: 46px; +} +.submit-recipe .title{ + text-align: start; +} + +.input-file{ + margin-bottom: 20px; +} + +.add-ingredient-btn{ + margin-bottom: 25px; +} + +.single-submit-form span{ + color: #015847; + font-weight: bold; +} + +.ing-modal{ + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + background: #fff; + padding: 20px; + border-radius: 10px; + box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3); + z-index: 9999; +} @media (max-width: 768px) { diff --git a/assets/js/single-submit.js b/assets/js/single-submit.js new file mode 100644 index 0000000..61a3664 --- /dev/null +++ b/assets/js/single-submit.js @@ -0,0 +1,55 @@ +const addIngredientBtn = document.getElementById('add-ingredient-btn'); +const overlay = document.getElementById('overlay'); +const ingModal = document.getElementById('ingredient-modal'); + +addIngredientBtn.addEventListener('click', () => { + ingModal.classList.remove('hidden'); + overlay.classList.remove('hidden'); +}); + + +document.addEventListener('click', (e) => { + if (!ingModal.contains(e.target) && !addIngredientBtn.contains(e.target)) { + ingModal.classList.add('hidden'); + overlay.classList.add('hidden'); + } +}); + +const ingredientSubmitBtn = document.getElementById('new-ingredient-submit'); +const ingredientName = document.getElementById('ing-name-input'); +const ingredientUnit = document.getElementById('ing-unit-input'); + +ingredientSubmitBtn.addEventListener('click', async (e) => { + + const name = ingredientName.value.trim(); + const unit = ingredientUnit.value.trim(); + + if (!name || !unit) { + showToastify('Please fill in all fields.', 'error'); + return; + } + + const formData = new FormData(); + formData.append('action', 'create_ingredient'); + formData.append('name', name); + formData.append('unit', unit); + + const response = await fetch('/ajax', { + method: 'POST', + body: formData + }); + + const json = await response.json(); + + if (!response.ok) { + const message = json.error; + showToastify(message, 'error'); + return; + } + + showToastify(json.success, 'success'); + ingredientName.value = ''; + ingredientUnit.value = ''; + ingModal.classList.add('hidden'); + overlay.classList.add('hidden'); +}); \ No newline at end of file