Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
faisalnjs committed Sep 26, 2024
1 parent b9b41c4 commit dd3f6cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/checker/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ document.getElementById("reorder-courses-button").addEventListener("click", () =
const fromHeight = current?.getBoundingClientRect().height;
document.querySelector('.course-reorder').style.display = 'flex';
document.querySelector('.course-selector').style.display = 'none';
document.getElementById('save-button').style.display = 'none';
const container = document.querySelector('.section');
const target = document.querySelector('.course-reorder');
const toHeight = target.getBoundingClientRect().height + calculateButtonHeights(target);
Expand All @@ -81,6 +82,7 @@ document.getElementById("cancel-reorder-courses-button").addEventListener("click
const current = document.querySelector('.course-reorder');
const fromHeight = current?.getBoundingClientRect().height;
document.querySelector('.course-selector').style.display = 'flex';
document.getElementById('save-button').style.display = '';
document.querySelector('.course-reorder').style.display = 'none';
const container = document.querySelector('.section');
const target = document.querySelector('.course-selector');
Expand All @@ -104,6 +106,7 @@ document.getElementById("save-course-order-button").addEventListener("click", ()
const current = document.querySelector('.course-reorder');
const fromHeight = current?.getBoundingClientRect().height;
document.querySelector('.course-selector').style.display = 'flex';
document.getElementById('save-button').style.display = '';
document.querySelector('.course-reorder').style.display = 'none';
const container = document.querySelector('.section');
const target = document.querySelector('.course-selector');
Expand Down Expand Up @@ -182,7 +185,7 @@ document.getElementById("save-course-order-button").addEventListener("click", ()
});

// Save
document.getElementById("save-button").addEventListener("click", () => {
document.getElementById("save-button").addEventListener("click", (e) => {
var updatedInfo = {
course: {
id: document.getElementById("period-input").value,
Expand All @@ -197,8 +200,12 @@ document.getElementById("save-button").addEventListener("click", () => {
},
body: JSON.stringify(updatedInfo)
});
e.target.disabled = true;
// Show submit confirmation
ui.modeless(`<i class="bi bi-check-lg"></i>`, "Saved!");
setTimeout(() => {
e.target.disabled = false;
}, 3000);
});

// Remove attention ring when user types in either input
Expand Down
13 changes: 10 additions & 3 deletions src/checker/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ let historyIndex = 0;
}

// Submit click
document.getElementById("submit-button").addEventListener("click", () => {
document.getElementById("submit-button").addEventListener("click", (e) => {
e.target.disabled = true;
const mode = ui.getButtonSelectValue(document.getElementById("answer-mode-selector"));
const segment = segmentInput.value?.trim();
const question = questionInput.value?.trim();
Expand Down Expand Up @@ -155,6 +156,9 @@ document.getElementById("submit-button").addEventListener("click", () => {
}
});
}
setTimeout(() => {
e.target.disabled = false;
}, 3000);
});

// Remove attention ring when user types in either input
Expand Down Expand Up @@ -207,10 +211,12 @@ function resetInputs() {

// Check answer
async function submitClick(code, segment, question, answer) {
window.scroll(0, 0);
var qA = storage.get("questionsAnswered") || [];
var alreadyAnswered = qA.find(q => q.segment == segment && q.question == question)
if (alreadyAnswered && alreadyAnswered.status == 'correct') return ui.modeless(`<i class="bi bi-exclamation-lg"></i>`, 'Already Submitted!');
if (alreadyAnswered && alreadyAnswered.status == 'Correct') {
window.scroll(0, 0);
return ui.modeless(`<i class="bi bi-exclamation-lg"></i>`, 'Already Submitted!');
}
await fetch(domain + '/check_answer', {
method: "POST",
headers: {
Expand All @@ -225,6 +231,7 @@ await fetch(domain + '/check_answer', {
})
.then(r => r.json())
.then(r => {
window.scroll(0, 0);
if (typeof r.correct != 'undefined') {
ui.modeless(`<i class="bi bi-${(r.correct) ? 'check' : 'x'}-lg"></i>`, (r.correct) ? 'Correct' : 'Try Again');
qA.push({ "segment": segment, "question": question, "status": (r.correct) ? 'Correct' : 'In Progress' });
Expand Down

0 comments on commit dd3f6cb

Please sign in to comment.