Commit 30f92729 authored by Jakob Moser's avatar Jakob Moser
Browse files

Back don't show again with localStorage

parent 2a4ac3b1
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
import { findParent } from "./util.mjs";

/**
 * Show (or hide) a dialog.
 * The dialog is not shown if the user has configured the dialog to not be shown again.
@@ -17,3 +19,19 @@ export function setDialogShown(id, shown) {
        document.body.classList.remove(DIALOG_SHOWN);
    }
}

/**
 * Initializes the "don't show this dialog again feature"
 */
export function initDontShowAgain() {
    document.querySelectorAll(".dialog .dont-show-again").forEach(el => {
        const dialog = findParent(el, ".dialog")
        const storageItemId = `${dialog.id}.dont-show-again`
        const storedStatus = localStorage.getItem(storageItemId) || false
        el.checked = storedStatus

        el.onchange = () => {
            localStorage.setItem(storageItemId, el.checked)
        }
    })
}
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ import { createExerciseCard, displayAsSolved, displayAsNonCurrent, displayAsCurr
import { Exercise } from "./exercises.api.mjs"
import { isVmLoading, onCopyOrPasteHotkey, setAutoFocusEnabled } from "./jslinux.api.mjs"
import { findParent, waitFor } from "./util.mjs"
import { setDialogShown } from "./dialogs.mjs"
import { initDontShowAgain, setDialogShown } from "./dialogs.mjs"

const testId = new URLSearchParams(location.search).get("id")
const currentTest = tests[testId]
@@ -181,6 +181,7 @@ export async function main() {
    initExerciseList()
    setExerciseActionButtonsEnabled(false)
    initActionLinks()
    initDontShowAgain()

    startExercise(currentTest.getNextUnsolvedExercise(currentState))