Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions lib/challenge-verify-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ document.addEventListener('DOMContentLoaded', () => {
})
}

// Only if button exists.
// Before enableVerifyButtons, due to checked selectedDirPath there.
if (selectDirButton) {
const savedDir = userData.getSavedDir(currentChallenge)

if (!savedDir) {
showSelectedDirDiv(false)
} else {
selectedDirPath.innerText = savedDir
showSelectedDirDiv(true)
}
}

const challengeUserData = userData.getChallengeData(currentChallenge)
if (challengeUserData.challengeComplete) {
enableVerifyButtons(false)
Expand All @@ -52,18 +65,6 @@ document.addEventListener('DOMContentLoaded', () => {
if (challengeUserData.verifyList.length > 0) {
printOutVerifyList(challengeUserData.verifyList)
}

// Only if button exists
if (selectDirButton) {
const savedDir = userData.getSavedDir(currentChallenge)

if (!savedDir) {
showSelectedDirDiv(false)
} else {
selectedDirPath.innerText = savedDir
showSelectedDirDiv(true)
}
}
})

/*
Expand All @@ -72,6 +73,7 @@ document.addEventListener('DOMContentLoaded', () => {
ipc.on('confirm-selectDir', (event, path) => {
selectedDirPath.innerText = path
showSelectedDirDiv(true)
enableVerifyButtons(true)
userData.updateSavedDir(currentChallenge, path)
})

Expand All @@ -80,9 +82,12 @@ ipc.on('confirm-selectDir', (event, path) => {
*/
async function handleVerifyClick () {
// If challenge with directory, but no path is selected
// Should normally not happen, as it is prevented already.
if (selectDirButton && !selectedDirPath?.innerText.length) {
console.log('No path selected!')
console.error('No path selected!')
showSelectedDirDiv(false)
// Buttons generally still enabled, but check verify-button against empty path again.
enableVerifyButtons(true)
return
}

Expand Down Expand Up @@ -161,11 +166,17 @@ function enableClearStatusButton (enabled) {
}

/*
* VerifyButton gets disabled or not.
* VerifyButtons get disabled or not.
* This includes the verify-button, as well as the select-dir button if available.
*/
function enableVerifyButtons (enabled) {
verifyButton.disabled = !enabled

if (selectDirButton) {
// Don't enable verifyButton, if no folder selected
if (selectedDirPath.innerText === '') {
verifyButton.disabled = true
}
selectDirButton.disabled = !enabled
}
}
Expand Down