Commit c8925969 authored by Jakob Moser's avatar Jakob Moser
Browse files

Add more state-dependent methods to Exercise and use them

parent 33521224
Loading
Loading
Loading
Loading
+14 −0
Changes for static/js/exercises.api.mjs: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -78,6 +78,20 @@ class Exercise {
    isCurrent(currentState) {
        return currentState.exerciseIndex === this.index
    }

    /**
     * Marks this exercise as solved, modifying the given current state
     */
    markAsSolved(currentState) {
        currentState.markAsSolved(this.index)
    }

    /**
     * Marks this exercise as current, modifying the given current state
     */
    markAsCurrent(currentState) {
        currentState.exerciseIndex = this.index
    }
}

/**
+2 −2
Changes for static/js/yalikejazz.mjs: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -39,12 +39,12 @@ function initExerciseList() {
function startExercise(exercise) {
    const cardEl = document.querySelector(`.exercise[data-exercise-index='${exercise.index}']`)

    currentState.exerciseIndex = exercise.index
    exercise.markAsCurrent(currentState)
    exercise.onDescribed(description => cardEl.querySelector(".description").textContent = description)
    exercise.onVerified(
        success => {
            if (success) {
                currentState.markAsSolved(exercise.index)
                exercise.markAsSolved(currentState)
                displayAsSolved(cardEl)

                const nextExercise = currentTest.getNextUnsolvedExercise(currentState)