Mehdi commited on
Commit
ff2dbd5
·
1 Parent(s): 490c5f1

fix: MCQ double-count — remove duplicate onclick handler in showMCQ

Browse files

wireButtons() already registers addEventListener on MCQ buttons (once,
guarded by _pp). showMCQ() was also setting btn.onclick, causing
handleMCQAnswer to fire twice per click and push two history entries.
Remove the onclick assignment and add mcqAnswered guard for safety.

Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -558,7 +558,7 @@ BRIDGE_JS = """() => {
558
 
559
  // ── MCQ display ────────────────────────────────────────────────────────────
560
  function showMCQ(data) {
561
- S.mcqData = data; S.waitingMCQ = false;
562
  const qt = $('q-text'), ql = $('q-loading'), nq = $('new-q-btn');
563
  const es = $('empty-state'), qa = $('question-area'), eb = $('end-btn');
564
  if (es) es.classList.add('hidden');
@@ -573,7 +573,7 @@ BRIDGE_JS = """() => {
573
  if (txt) txt.textContent = (data.choices && data.choices[l]) || '';
574
  if (btn) {
575
  btn.className = 'mcq-btn'; btn.disabled = false;
576
- btn.onclick = ((letter) => () => handleMCQAnswer(letter))(l);
577
  }
578
  }
579
  $('mcq-options')?.classList.remove('hidden');
@@ -585,7 +585,8 @@ BRIDGE_JS = """() => {
585
  // ── MCQ answer handler (client-side — no LLM call needed) ─────────────────
586
  function handleMCQAnswer(letter) {
587
  const data = S.mcqData;
588
- if (!data || !data.correct || S.waitingMCQ) return;
 
589
  const correct = data.correct;
590
  const isCorrect = letter === correct;
591
  for (const l of ['A','B','C','D']) {
 
558
 
559
  // ── MCQ display ────────────────────────────────────────────────────────────
560
  function showMCQ(data) {
561
+ S.mcqData = data; S.waitingMCQ = false; S.mcqAnswered = false;
562
  const qt = $('q-text'), ql = $('q-loading'), nq = $('new-q-btn');
563
  const es = $('empty-state'), qa = $('question-area'), eb = $('end-btn');
564
  if (es) es.classList.add('hidden');
 
573
  if (txt) txt.textContent = (data.choices && data.choices[l]) || '';
574
  if (btn) {
575
  btn.className = 'mcq-btn'; btn.disabled = false;
576
+ btn.onclick = null;
577
  }
578
  }
579
  $('mcq-options')?.classList.remove('hidden');
 
585
  // ── MCQ answer handler (client-side — no LLM call needed) ─────────────────
586
  function handleMCQAnswer(letter) {
587
  const data = S.mcqData;
588
+ if (!data || !data.correct || S.waitingMCQ || S.mcqAnswered) return;
589
+ S.mcqAnswered = true;
590
  const correct = data.correct;
591
  const isCorrect = letter === correct;
592
  for (const l of ['A','B','C','D']) {