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

Merge branch 'frontend/refactor/long-method' into 'master'

Short down length of methods

See merge request !32
parents d920b8d3 abc7f445
Pipeline #129586 passed with stages
in 3 minutes and 18 seconds
function setColumnVisibility(table, column, visible) {
table.querySelectorAll("tr").forEach((row) => {
const cell = row.children[column];
if (visible) {
cell.classList.remove("hidden");
} else {
cell.classList.add("hidden");
}
});
}
function compareScore(a, b) {
if (a.score < b.score) {
return 1;
}
if (b.score < a.score) {
return -1;
}
return 0;
}
function compareUnits(a, b) {
if (a.units < b.units) {
return 1;
}
if (b.units < a.units) {
return -1;
}
return 0;
}
async function fetchHighscores(exerciseId = undefined) {
const withExercise = exerciseId && exerciseId > -1;
const endpoint = withExercise
......@@ -14,22 +45,6 @@ async function fetchHighscores(exerciseId = undefined) {
const rowTemplate = document.getElementById("template-highscore-row");
const rankByUnits = document.getElementById("rank-by-units");
const compareScore = (a, b) =>
a.score < b.score ? 1 : b.score < a.score ? -1 : 0;
const compareUnits = (a, b) =>
a.units < b.units ? 1 : b.units < a.units ? -1 : 0;
const setColumnVisibility = (column, visible) => {
table.querySelectorAll("tr").forEach((row) => {
const cell = row.children[column];
if (visible) {
cell.classList.remove("hidden");
} else {
cell.classList.add("hidden");
}
});
};
const renderHighscores = () => {
container.innerText = "";
const compareFunc = rankByUnits.checked
......@@ -45,7 +60,7 @@ async function fetchHighscores(exerciseId = undefined) {
cells[3].textContent = highscore.units ? highscore.units : "";
container.appendChild(row);
});
setColumnVisibility(3, withExercise);
setColumnVisibility(table, 3, withExercise);
};
rankByUnits.addEventListener("change", () => renderHighscores());
......
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