Browse Source

Keep workouts in order when updating them.
Save a copy of the html text to file on dev.

Lee Morgan 1 year ago
parent
commit
f3927ea0f1
5 changed files with 12 additions and 7 deletions
  1. 0 0
      build.html
  2. 4 0
      createHtml.js
  3. 1 1
      package.json
  4. 0 0
      testHtml.html
  5. 7 6
      views/js/pages/home.js

File diff suppressed because it is too large
+ 0 - 0
build.html


+ 4 - 0
createHtml.js

@@ -32,5 +32,9 @@ export default async ()=>{
     data = data.replace('<script src="/index.js"></script>', `<script>${js}</script>`);
     data = data.replace('<link rel="stylesheet" href="/index.css">', `<style>${css}</style>`);
 
+    if(process.env.NODE_ENV !== "process"){
+        fs.writeFile(`${import.meta.dirname}/build.html`, data);
+    }
+
     return data;
 }

+ 1 - 1
package.json

@@ -16,7 +16,7 @@
   "main": "app.js",
   "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1",
-    "dev": "nodemon app.js --ignore views/build/ --ext js,css,html"
+    "dev": "nodemon app.js --ignore views/build/ --ignore build.html --ext js,css,html"
   },
   "dependencies": {
     "bcrypt": "^6.0.0",

File diff suppressed because it is too large
+ 0 - 0
testHtml.html


+ 7 - 6
views/js/pages/home.js

@@ -60,19 +60,21 @@ export default {
         }
 
         for(let i = 0; i < workouts.length; i++){
-            this.addWorkout(workouts[i]);
+            this.workoutList.appendChild(this.createWorkoutElem(workouts[i]));
         }
     },
 
     handleUpdate: function(update){
         switch(update.type){
-            case "new": this.addWorkout(update.workout); break;
+            case "new":
+                this.workoutList.appendChild(this.createWorkoutElem(update.workout));
+                break;
             case "remove": this.removeWorkout(update.workout); break;
             case "replace": this.replaceWorkout(update.workout); break;
         }
     },
 
-    addWorkout: function(workout){
+    createWorkoutElem: function(workout){
         const button = document.createElement("button");
         button.workoutId = workout.id;
         button.classList.add("button");
@@ -80,7 +82,7 @@ export default {
         button.addEventListener("click", ()=>{
             changePage("workoutMenu", workout);
         });
-        this.workoutList.appendChild(button);
+        return button;
     },
 
     removeWorkout: function(workoutId){
@@ -97,8 +99,7 @@ export default {
         const workouts = this.workoutList.children;
         for(let i = 0; i < workouts.length; i++){
             if(workouts[i].workoutId === workout.id){
-                this.workoutList.removeChild(workouts[i]);
-                this.addWorkout(workout);
+                workouts[i].replaceWith(this.createWorkoutElem(workout));
                 break;
             }
         }

Some files were not shown because too many files changed in this diff