Skip to content

Commit da169fd

Browse files
committed
Add finishment for challenges
1 parent 2f357fc commit da169fd

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

templates/components/challenge_area.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
confetti.addConfetti()
111111
// passedState has defined in challenge_sidebar.html
112112
passedState.setPassed(level, name);
113+
document.getElementById(`${level}-${name}`).parentNode.classList.add('passed');
113114
}
114115
setTimeout(() => {
115116
document.getElementById('answer-link').style.display = 'block';
@@ -153,8 +154,8 @@
153154
}
154155

155156
// Make sure the current challenge is visible to user.
156-
activeChallengeInList = document.getElementById(`${level}-${name}`);
157-
activeChallengeInList.classList.add('active-challenge'); // Highlight
157+
let activeChallengeInList = document.getElementById(`${level}-${name}`);
158+
activeChallengeInList.parentNode.classList.add('active-challenge'); // Highlight
158159
}
159160

160161
codeUnderTest = {{code_under_test | tojson}};

templates/components/challenge_sidebar.html

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010
flex-direction: column;
1111
}
1212

13-
.challenge-nav ul li {
14-
padding: 0px 8px;
15-
}
16-
17-
.challenge-nav ul li:not(:first-of-type) a {
18-
padding: 8px 10px;
19-
}
20-
2113
.challenge-nav .challenge-level {
2214
width: fit-content;
2315
border-bottom: 1px dashed hsl(240, 2%, 90%);
@@ -36,6 +28,22 @@
3628
display: none;
3729
}
3830

31+
.passed {
32+
position: relative;
33+
}
34+
35+
.passed::after {
36+
/* iconify: https://icon-sets.iconify.design/lets-icons/done-ring-round */
37+
content: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cg fill="none" stroke="%2366ba6f" stroke-linecap="round" stroke-width="2"%3E%3Cpath d="m9 10l3.258 2.444a1 1 0 0 0 1.353-.142L20 5"%2F%3E%3Cpath d="M21 12a9 9 0 1 1-6.67-8.693"%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E');
38+
display: inline-block;
39+
position: absolute;
40+
width: 24px;
41+
height: 24px;
42+
top: 50%;
43+
right: 0;
44+
transform: translate(-50%, -50%);
45+
transition: all 1.5s ease-out;
46+
}
3947

4048
@media only screen and (max-width: 800px) {
4149
.sidebar-toggle {
@@ -141,7 +149,7 @@ <h5 class="challenge-level">{{ level }}</h5>
141149
* @param {Event} event - The click event.
142150
*/
143151
function removeHighlight(event) {
144-
previousActiveChallenges = document.getElementsByClassName("active-challenge");
152+
let previousActiveChallenges = document.getElementsByClassName("active-challenge");
145153
for (c of previousActiveChallenges) {
146154
// Remove previously highlighted challenge in the list.
147155
c.classList.remove('active-challenge');
@@ -151,4 +159,14 @@ <h5 class="challenge-level">{{ level }}</h5>
151159
const initialState = {{ challenges_groupby_level | tojson }};
152160
const passedState = new PassedState();
153161
passedState.init(initialState);
162+
163+
// Highlight the passed challenges when the page is loaded.
164+
let ids = Object.keys(passedState.get()).forEach(level => {
165+
passedState.get()[level].forEach(challenge => {
166+
let id = `#${level}-${challenge.name}`;
167+
if (challenge.passed) {
168+
document.querySelector(id).parentNode.classList.add('passed');
169+
}
170+
})
171+
})
154172
</script>

0 commit comments

Comments
 (0)