// The review tab (חזרה): every wrong answer waits here as a card, grouped by skill. A card is answered in place: a right answer marks it done and removes // it; a wrong one keeps it and names the mistake and its tip, never the right choice, and offers "נסו שוב". Practice only: no mastery and no grade change. import { api } from "./api.js"; import { figures } from "./figures.js"; import { esc, fmt } from "./math.js"; import { shuffled, tabs } from "./ui.js"; const SOURCE = { practice: "תרגול", quiz: "בוחן", exercise_test: "מבחן תרגול", simulation: "מבחן סימולציה" }; const counter = n => n === 0 ? "אין שאלות שמחכות" : n === 1 ? "שאלה אחת מחכה" : `${n} שאלות מחכות`; const cardsWord = n => n === 1 ? "כרטיס אחד" : `${n} כרטיסים`; const card = c => `

מ${SOURCE[c.source] || "תרגול"}

${fmt(c.question)}

${figures(c)}
${shuffled(c.choices).map(x => ``).join("")}
`; const group = g => `

${fmt(g.skill.name)} ${cardsWord(g.cards.length)}

${fmt(g.lesson.name)}

${g.cards.map(card).join("")}
`; function draw(view, data) { view(`${tabs("review")}

חזרה

${counter(data.count)}

${data.groups.length ? data.groups.map(group).join("") : `

אין מה לחזור עליו. כל תשובה שגויה תופיע כאן, ותצא מהרשימה כשתענו עליה נכון.

`}
`); document.getElementById("review").addEventListener("click", event => { const choice = event.target.closest(".ex-choice"); if (choice && !choice.disabled) answer(choice.closest(".review-card"), choice); const again = event.target.closest("[data-again]"); if (again) retry(again.closest(".review-card")); }); } function retry(cardEl) { cardEl.querySelectorAll(".ex-choice").forEach(b => { b.disabled = false; b.classList.remove("wrong"); }); cardEl.querySelector(".review-feedback").innerHTML = ""; } async function answer(cardEl, button) { const buttons = [...cardEl.querySelectorAll(".ex-choice")]; const feedback = cardEl.querySelector(".review-feedback"); buttons.forEach(b => { b.disabled = true; }); let got; try { got = await api("/api/review/answer", { method: "POST", body: { key: cardEl.dataset.key, choice: Number(button.dataset.i) } }); } catch (error) { buttons.forEach(b => { b.disabled = false; }); feedback.innerHTML = ``; return; } const page = document.getElementById("review"), groupEl = cardEl.closest(".review-group"); page.dataset.count = got.count; document.getElementById("review-count").textContent = counter(got.count); button.classList.add(got.correct ? "right" : "wrong"); // the picked choice only: the right one is never marked if (got.correct) { cardEl.classList.add("done"); feedback.innerHTML = `

נכון! השאלה יצאה מהרשימה.

`; groupEl.querySelector(".review-skill-count").textContent = cardsWord(got.skill_count); if (got.skill_count === 0) groupEl.querySelectorAll("h3, .review-lesson").forEach(el => { el.hidden = true; }); // nothing waits on this skill: its heading goes (the done cards stay until the page is left) if (got.count === 0) page.insertAdjacentHTML("beforeend", `

אין מה לחזור עליו. כל הכבוד!

`); return; } const m = got.mistake; feedback.innerHTML = `

לא נכון. השאלה נשארת ברשימה.

${m ? `
${fmt(m.name)}

${fmt(m.tip)}

${m.back ? `

כדאי לתרגל: ${fmt(m.back_name || "")}

` : ""}
` : ""}

`; } export async function show(view) { draw(view, await api("/api/review")); }