Skip to content

Commit 573d654

Browse files
yammesickaorronai
andauthored
fix: simple javascript errors (#220)
* fix: Don't crash when the directory is already exists. * fix: Few JS lints & undefined error. * fix: Fix filetree alignment and hide badges on folders. Co-authored-by: Or Ronai <[email protected]>
1 parent f0c5fbf commit 573d654

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
},
66
globals: {
77
bootstrap: true,
8+
Dropzone: true,
89
},
910
extends: [
1011
'airbnb-base',

lms/static/my.css

+9
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,15 @@ button#share-action:hover {
271271
overflow-x: unset;
272272
}
273273

274+
.file-comments-count {
275+
width: 1em;
276+
height: 1.5em;
277+
display: flex;
278+
align-self: center;
279+
justify-self: center;
280+
margin: 0 0.25em;
281+
}
282+
274283
#files {
275284
list-style-type: none;
276285
text-align: left;

lms/static/my.js

+26-16
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ function trackDisableShareButton(solutionId, button) {
8181
function updateNotificationsBadge() {
8282
const dropdown = document.getElementById('navbarNavDropdown');
8383
const container = document.getElementById('notifications-list');
84+
if (dropdown === null || container === null) {
85+
return;
86+
}
87+
8488
const unread = container.querySelectorAll('.dropdown-item[data-read="false"]');
8589
const counter = dropdown.querySelector('#notification-count');
8690
const bgColor = (unread.length > 0) ? badColor : naturalColor;
@@ -95,6 +99,10 @@ function sendReadAllNotificationsRequest() {
9599
}
96100

97101
function trackReadAllNotificationsButton(button) {
102+
if (button === null) {
103+
return;
104+
}
105+
98106
button.addEventListener('click', () => {
99107
sendReadAllNotificationsRequest();
100108
const notifications = document.querySelectorAll('.dropdown-item[data-read="false"]');
@@ -105,20 +113,9 @@ function trackReadAllNotificationsButton(button) {
105113
});
106114
}
107115

108-
function getPostUploadMessage() {
109-
const myDropzone = Dropzone.forElement('#demo-upload');
110-
const feedbacks = document.getElementById('upload-feedbacks');
111-
const matchesSpan = document.getElementById('upload-matches');
112-
const missesSpan = document.getElementById('upload-misses');
113-
myDropzone.on('success', function() {
114-
const uploadStatus = Array.from(arguments).slice(1)[0];
115-
postUploadMessageUpdate(feedbacks, uploadStatus, matchesSpan, missesSpan);
116-
});
117-
}
118-
119116
function postUploadMessageUpdate(feedbacks, uploadStatus, matchesSpan, missesSpan) {
120-
const matches = uploadStatus['exercise_matches'];
121-
const misses = uploadStatus['exercise_misses'];
117+
const matches = uploadStatus.exercise_matches;
118+
const misses = uploadStatus.exercise_misses;
122119
if (!feedbacks.classList.contains('feedback-hidden')) {
123120
feedbacks.classList.add('feedback-hidden');
124121
}
@@ -131,19 +128,32 @@ function postUploadMessageUpdate(feedbacks, uploadStatus, matchesSpan, missesSpa
131128
missesSpan.classList.remove('feedback-hidden');
132129
}
133130
feedbacks.classList.add('feedback-transition');
134-
feedbacks.clientWidth; // Forces layout to ensure the transition
131+
feedbacks.clientWidth; // Forces layout to ensure the transition
135132
feedbacks.classList.remove('feedback-hidden');
136-
feedbacks.addEventListener('transitionend', function() {
133+
feedbacks.addEventListener('transitionend', () => {
137134
feedbacks.classList.remove('feedback-transition');
138135
});
139136
}
140137

138+
function getPostUploadMessage() {
139+
const myDropzone = Dropzone.forElement('#demo-upload');
140+
const feedbacks = document.getElementById('upload-feedbacks');
141+
const matchesSpan = document.getElementById('upload-matches');
142+
const missesSpan = document.getElementById('upload-misses');
143+
myDropzone.on('success', (...args) => {
144+
const uploadStatus = Array.from(args).slice(1)[0];
145+
if (uploadStatus !== null) {
146+
postUploadMessageUpdate(feedbacks, uploadStatus, matchesSpan, missesSpan);
147+
}
148+
});
149+
}
150+
141151
window.escapeUnicode = escapeUnicode;
142152

143153
window.addEventListener('load', () => {
144154
updateNotificationsBadge();
145155
trackReadAllNotificationsButton(document.getElementById('read-notifications'));
146-
const codeElement = document.getElementById('code-view')
156+
const codeElement = document.getElementById('code-view');
147157
if (codeElement !== null) {
148158
const codeElementData = codeElement.dataset;
149159
const solutionId = codeElementData.id;

0 commit comments

Comments
 (0)