-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathchallenge.js
57 lines (48 loc) · 1.92 KB
/
challenge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// This file is loaded by every challenge's HTML, it listens to events on the
// verify button and provides the file-chooser dialog when the challenge needs.
//
var path = require('path')
var userData = require(path.normalize(path.join(__dirname, 'user-data.js')))
var selectDirBtn = document.getElementById('select-directory')
var currentChallenge = window.currentChallenge
var selectDirectory = function (path) {
document.getElementById('path-required-warning').classList.remove('show')
document.getElementById('directory-path').innerText = path
}
if (selectDirBtn) {
var ipc = require('electron').ipcRenderer
selectDirBtn.addEventListener('click', function clickedDir (event) {
ipc.send('open-file-dialog')
})
ipc.on('selected-directory', function (event, path) {
selectDirectory(path[0])
userData.updateCurrentDirectory(path)
})
}
var currentDirectory = userData.getSavedDir().contents.savedDir
var challengeCompleted = userData.getData().contents
if (currentChallenge === 'forks_and_clones') {
// on this challenge clear out the saved dir because it should change
userData.updateCurrentDirectory(null)
} else if (selectDirBtn && currentDirectory && !challengeCompleted[currentChallenge].completed) {
selectDirectory(currentDirectory)
selectDirBtn.innerHTML = 'CHANGE DIRECTORY'
}
// Handle verify challenge click
document.getElementById('verify-challenge').addEventListener('click', function clicked (event) {
var verifyChallenge = require('../lib/verify/' + currentChallenge + '.js')
// If a directory is needed
if (selectDirBtn) {
var path = document.getElementById('directory-path').innerText
if (path === '') {
document.getElementById('path-required-warning').classList.add('show')
} else {
document.getElementById('verify-list').innerHTML = ''
verifyChallenge(path)
}
} else {
document.getElementById('verify-list').innerHTML = ''
verifyChallenge()
}
})