Commit e0915b03 authored by Andreas Rimolsrønning's avatar Andreas Rimolsrønning
Browse files

Merge branch 'frontend/refactor/touched-files/comments' into 'master'

Refactor front end comments

See merge request !35
parents 1167dfca 96cf7898
Pipeline #129169 passed with stages
in 3 minutes and 5 seconds
......@@ -13,7 +13,6 @@ function isUserAuthenticated() {
function updateNavBar() {
const nav = document.querySelector("nav");
// Emphasize link to current page
if (
window.location.pathname == "/" ||
window.location.pathname == "/index.html"
......@@ -102,7 +101,6 @@ async function sendRequest(
let response = await fetch(myRequest);
if (response.status == 401 && getCookieValue("refresh")) {
// access token not accepted. getting refresh token
myHeaders = new Headers({
"Content-Type": "application/json; charset=UTF-8",
});
......@@ -114,7 +112,6 @@ async function sendRequest(
response = await fetch(myRequest);
if (response.ok) {
// refresh successful, received new access token
const data = await response.json();
setCookie("access", data.access, 86400, "/");
......
......@@ -21,12 +21,11 @@ async function retrieveWorkout(id) {
const input = form.querySelector(selector);
let newVal = workoutData[key];
if (key == "date") {
// Creating a valid datetime-local string with the correct local time
let date = new Date(newVal);
date = new Date(
date.getTime() - date.getTimezoneOffset() * 60 * 1000
).toISOString(); // get ISO format for local time
newVal = date.substring(0, newVal.length - 1); // remove Z (since this is a local time, not UTC)
).toISOString();
newVal = date.substring(0, newVal.length - 1);
}
if (key != "files") {
input.value = newVal;
......@@ -35,7 +34,7 @@ async function retrieveWorkout(id) {
const input = form.querySelector("select:disabled");
input.value = workoutData.visibility;
// files
const filesDiv = document.querySelector("#uploaded-files");
for (const file of workoutData.files) {
const a = document.createElement("a");
......@@ -46,9 +45,6 @@ async function retrieveWorkout(id) {
filesDiv.appendChild(a);
}
// create exercises
// fetch exercise types
const exerciseTypes = await fetchAllExercises();
// TODO: This should be in its own method.
......@@ -131,7 +127,7 @@ function handleEditWorkoutButtonClick() {
const removeExerciseButton = document.querySelector("#btn-remove-exercise");
setReadOnly(false, "#form-workout");
document.querySelector("#inputOwner").readOnly = true; // owner field should still be readonly
document.querySelector("#inputOwner").readOnly = true;
editWorkoutButton.className += " hide";
okWorkoutButton.className = okWorkoutButton.className.replace(" hide", "");
......@@ -199,7 +195,6 @@ function generateWorkoutForm() {
submitForm.append("notes", formData.get("notes"));
submitForm.append("visibility", formData.get("visibility"));
// adding exercise instances
const exerciseInstances = [];
const exerciseInstancesTypes = formData.getAll("type");
const exerciseInstancesSets = formData.getAll("sets");
......@@ -213,7 +208,7 @@ function generateWorkoutForm() {
}
submitForm.append("exercise_instances", JSON.stringify(exerciseInstances));
// adding files
for (const file of formData.getAll("files")) {
submitForm.append("files", file);
}
......
......@@ -33,14 +33,14 @@ async function fetchWorkouts(ordering) {
const rows = table.querySelectorAll("tr");
rows[0].querySelectorAll(
"td"
)[1].textContent = localDate.toLocaleDateString(); // Date
)[1].textContent = localDate.toLocaleDateString();
rows[1].querySelectorAll(
"td"
)[1].textContent = localDate.toLocaleTimeString(); // Time
)[1].textContent = localDate.toLocaleTimeString();
rows[2].querySelectorAll("td")[1].textContent =
workout.owner_username; // Owner
workout.owner_username;
rows[3].querySelectorAll("td")[1].textContent =
workout.exercise_instances.length; // Exercises
workout.exercise_instances.length;
container.appendChild(aWorkout);
});
......@@ -86,7 +86,7 @@ window.addEventListener("DOMContentLoaded", async () => {
} ${ordering.replace("-", "")}`;
const currentUser = await getCurrentUser();
// grab username
if (ordering.includes("owner")) {
ordering += "__username";
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment