diff --git a/src/components/exams/answer-sheet-view.tsx b/src/components/exams/answer-sheet-view.tsx index a5d358c..0ddd85e 100644 --- a/src/components/exams/answer-sheet-view.tsx +++ b/src/components/exams/answer-sheet-view.tsx @@ -1,14 +1,15 @@ -import { For, Show, Suspense, createResource, createSignal } from "solid-js"; +import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; import { ApiError } from "@/api/client"; import { getExamQuestions } from "@/api/exams"; import { getStudentAnswers, getStudentAnswerImage } from "@/api/exams"; -import { getStudentAttempts, getStudentAttemptAnswers, getStudentAttemptAnswerImage, getStudentMarksHistory } from "@/api/exams"; +import { getStudentAttempts, getStudentAttemptAnswers, getStudentAttemptAnswerImage } from "@/api/exams"; import type { StudentAnswerSheet } from "@/api/client"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { IconCheck, IconDownload, IconX } from "@/components/ui/icons"; import { PageSpinner } from "@/components/ui/page-spinner"; import { ReplayableImage } from "@/components/ui/replayable-image"; +import { DropdownSelect } from "@/components/ui/select"; import { cn } from "@/lib/cn"; import { joinAnswerSheet } from "@/lib/answer-sheet"; import { personLabelWithId } from "@/lib/person"; @@ -33,18 +34,6 @@ export function AnswerSheetView(props: { examId: string; userId: string }) { } }, ); - const [marks] = createResource( - () => [props.examId, props.userId] as const, - async ([examId, userId]) => { - try { - return await getStudentMarksHistory(examId, userId); - } catch (err) { - if (err instanceof ApiError && err.status === 404) return []; - throw err; - } - }, - ); - const latestSeq = () => { const a = attempts(); return a && a.length ? a[a.length - 1] : null; @@ -55,7 +44,14 @@ export function AnswerSheetView(props: { examId: string; userId: string }) { const s = activeSeq(); return s == null || s === latestSeq(); }; - const markForSeq = (seq: number) => marks()?.[seq - 1]?.mark ?? null; + // Dropdown options, newest sitting first (a student may have many). Just the + // sitting label; the latest is tagged as the current one. Per-sitting stats + // live in the sheet header for the selected sitting, not in the dropdown. + const attemptOptions = () => + [...(attempts() ?? [])].reverse().map((seq) => ({ + value: seq, + label: `${t("exams.attemptN", { n: seq })}${seq === latestSeq() ? ` (${t("exams.currentAttempt")})` : ""}`, + })); const answerImageUrl = (questionId: string) => { const seq = activeSeq(); @@ -97,32 +93,45 @@ export function AnswerSheetView(props: { examId: string; userId: string }) { }, ); + // Per-sitting answer breakdown for the viewed attempt's header. `is_correct` + // is only set for auto-gradable (choice) questions: right = got it, wrong = + // missed it, empty = no answer given; answered text questions fall in none + // (a human grades those). `pending` surfaces those so the counts stay honest. + const sheetStats = createMemo(() => { + const rows = data()?.rows ?? []; + const answered = (a: (typeof rows)[number]["answer"]) => + !!a && (a.selected != null || !!a.text || !!a.answer_image); + let right = 0; + let wrong = 0; + let empty = 0; + let pending = 0; + for (const r of rows) { + if (!answered(r.answer)) empty++; + else if (r.answer?.is_correct === true) right++; + else if (r.answer?.is_correct === false) wrong++; + else pending++; + } + return { right, wrong, empty, pending, total: rows.length }; + }); + return ( - }> + // The picker stays OUTSIDE the Suspense: switching attempts re-fetches + // `data`, and if the dropdown lived inside the suspending subtree it would + // unmount and its portalled menu would flash unpositioned (top-left) on + // every select. Only the answer sheet suspends. +
1}> -
+
{t("exams.previousAttempts")} - - {(seq) => ( - - )} - + setSelectedSeq(v)} + triggerClass="w-full sm:w-auto" + />
+ }> {(d) => (
@@ -132,9 +141,25 @@ export function AnswerSheetView(props: { examId: string; userId: string }) {

{personLabelWithId(d().sheet.user)}

0} fallback={{t("exams.notStarted")}}> - - {t("exams.autoScore")}: {d().sheet.auto_score.earned}/{d().sheet.auto_score.possible} - +
+ + {t("exams.answersRight")}: {sheetStats().right} + + + {t("exams.answersWrong")}: {sheetStats().wrong} + + + {t("exams.answersEmpty")}: {sheetStats().empty} + + 0}> + + {t("exams.answersPending")}: {sheetStats().pending} + + + + {t("exams.autoScore")}: {d().sheet.auto_score.earned}/{d().sheet.auto_score.possible} + +
@@ -225,6 +250,7 @@ export function AnswerSheetView(props: { examId: string; userId: string }) {
)}
-
+ +
); } diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index e4ffc52..3c822b1 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -659,6 +659,10 @@ export type MessageKey = | "exams.lastActivity" | "exams.answerSheet" | "exams.autoScore" + | "exams.answersRight" + | "exams.answersWrong" + | "exams.answersEmpty" + | "exams.answersPending" | "exams.earned" | "exams.possible" | "exams.isCorrect" @@ -1489,6 +1493,10 @@ const en: Dict = { "exams.lastActivity": "Last activity", "exams.answerSheet": "Answer Sheet", "exams.autoScore": "Auto-score", + "exams.answersRight": "Correct", + "exams.answersWrong": "Wrong", + "exams.answersEmpty": "Empty", + "exams.answersPending": "Ungraded", "exams.earned": "Earned", "exams.possible": "Possible", "exams.isCorrect": "Correct", @@ -2313,6 +2321,10 @@ const tr: Dict = { "exams.lastActivity": "Son hareket", "exams.answerSheet": "Cevap Kâğıdı", "exams.autoScore": "Otomatik puan", + "exams.answersRight": "Doğru", + "exams.answersWrong": "Yanlış", + "exams.answersEmpty": "Boş", + "exams.answersPending": "Değerlendirilmedi", "exams.earned": "Alınan", "exams.possible": "Mümkün", "exams.isCorrect": "Doğru",