Jelajahi Sumber

Ignore previous commit. Add validation for new ingredients

Lee Morgan 6 tahun lalu
induk
melakukan
35c1c7964d

+ 1 - 1
views/merchantSetupPage/merchantSetup.ejs

@@ -50,7 +50,7 @@
                 <tbody></tbody>
             </table>
             <button onclick="newIngredientField()">+</button>
-            <button onclick="updateState(1)">Create Ingredients</button>
+            <button onclick="createIngredientsList()">Create Ingredients</button>
             <button onclick="updateState(-1)">Back</button>
         </div>
 

+ 8 - 4
views/merchantSetupPage/merchantSetup.js

@@ -19,6 +19,8 @@ for(let recipe of recipes.elements){
     )
 }
 
+//refactor
+//buttons should run a function which should call the state update, not the other way around
 let updateState = (num)=>{
     state += num;
     if(state === 0){
@@ -30,10 +32,9 @@ let updateState = (num)=>{
         newIngredients.style.display = "flex";
         createRecipes.style.display = "none";
     }else if(state === 2){
-        // addIngredients.style.display = "none";
-        // newIngredients.style.display = "none";
-        // createRecipes.style.display = "flex";
-        createIngredientsList();
+        addIngredients.style.display = "none";
+        newIngredients.style.display = "none";
+        createRecipes.style.display = "flex";
     }
 }
 
@@ -135,6 +136,8 @@ let removeRow = (row)=>{
     row.parentNode.removeChild(row);
 }
 
+//refactor
+//nothin should run unless everything is valid
 let createIngredientsList = ()=>{
     data.ingredients = [];
     for(let ingredient of existingIngredientElements){
@@ -190,6 +193,7 @@ let createIngredientsList = ()=>{
                     data.ingredients.push(newIngredient);
                 }
                 banner.createNotification("All ingredients have been created and added to your inventory");
+                updateState(1);
                 showRecipe();
             })
             .catch((err)=>{