Commit 137221c5 authored by Jakob Moser's avatar Jakob Moser
Browse files

Adapt main file to restructuring

parent dc14ea34
Loading
Loading
Loading
Loading
+13 −19
Changes for static/js/yalikejazz.mjs: 13 added lines, 19 removed lines.
Original line number Diff line number Diff line
import { currentState } from "./state.mjs"
import { exercises } from "./exercises.mjs"
import { getHandInToken } from "./snakeoil.mjs"
import { createCard, setCardHoverTitle } from "./cards.mjs"
import { createElementWithClass } from "./util.mjs"
import { createExerciseCard, displayAsSolved, displayAsNonCurrent, displayAsCurrent } from "./exercises.cards.mjs"

function findNextIncompleteExerciseIndex(currentExerciseIndex) {
    if(currentState.completedExercises.length == exercises.length) {
@@ -18,27 +17,22 @@ function findNextIncompleteExerciseIndex(currentExerciseIndex) {
}

/**
 * Create a DOM card for the given exercise
 * Create a DOM card for the given exercise, displays is as solved if solved and inits event listeners
 * @param {Exercise} exercise The exercise
 * @param {Number} exerciseIndex The index of the exercise
 * @returns The DOM card
 */
function createExerciseCard(exercise, exerciseIndex) {
    const cardEl = createCard(
        exercise.name,
        currentState.completedExercises.includes(exerciseIndex) ? "bi-check-square" : "bi-square",  // Checked checkbox if solved, empty otherwise
        "#"+exerciseIndex
    )

    cardEl.classList.add("collapsed")
    const descriptionEl = createElementWithClass("p", "description")
    const actionsEl = createElementWithClass("div", "actions")
    cardEl.querySelector(".content").append(descriptionEl, actionsEl)
    cardEl.querySelector(".actions").append(...createExerciseCardActionButtons(
        exercise.manuallyConfirm.bind(exercise)
    ))
function createAndInitExerciseCard(exercise, exerciseIndex) {
    const cardEl = createExerciseCard(exercise, exerciseIndex, () => {
        if(!currentState.completedExercises.includes(exerciseIndex) && currentState.exercise !== exerciseIndex) {
            // Only skip to exercises that are not solved and aren't itself
            startExercise(exerciseIndex)
        }
    })

    // To programmatically access the index of the exercise this card represents later
    cardEl.dataset.exerciseIndex = exerciseIndex
    if(currentState.completedExercises.includes(exerciseIndex)) {
        displayAsSolved(cardEl)
    }

    return cardEl
}