|
|
@@ -3,6 +3,7 @@ export default {
|
|
|
|
|
|
render: function(){
|
|
|
if(!this.rendered){
|
|
|
+ this.getWorkouts();
|
|
|
this.buttons();
|
|
|
this.rendered = true;
|
|
|
}
|
|
|
@@ -27,5 +28,42 @@ export default {
|
|
|
document.getElementById("homeNewWorkout").addEventListener("click", ()=>{
|
|
|
changePage("newWorkout");
|
|
|
});
|
|
|
+ },
|
|
|
+
|
|
|
+ getWorkouts: function(){
|
|
|
+ fetch("/workout", {
|
|
|
+ method: "get",
|
|
|
+ headers: {
|
|
|
+ "Content-Type": "application/json"
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .then(r=>r.json())
|
|
|
+ .then((response)=>{
|
|
|
+ if(response.error){
|
|
|
+ notify("error", response.error.message);
|
|
|
+ }else{
|
|
|
+ this.renderWorkouts(response);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((err)=>{
|
|
|
+ notify("error", "ERROR: Unable to retrieve workouts");
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ renderWorkouts: function(workouts){
|
|
|
+ const workoutList = document.getElementById("workoutList");
|
|
|
+ while(workoutList.children.length > 0){
|
|
|
+ workoutList.removeChild(workoutList.firstChild);
|
|
|
+ }
|
|
|
+
|
|
|
+ for(let i = 0; i < workouts.length; i++){
|
|
|
+ const button = document.createElement("button");
|
|
|
+ button.classList.add("button");
|
|
|
+ button.textContent = workouts[i].name;
|
|
|
+ button.addEventListener("click", ()=>{
|
|
|
+ changePage("workout", workouts[i]);
|
|
|
+ });
|
|
|
+ workoutList.appendChild(button);
|
|
|
+ }
|
|
|
}
|
|
|
}
|