♻️ exam answer sheet in SidePanel, course names, correct/wrong icons
Browse files at this commitfcfa59d46a5d722ba7c05d1390b10e66174afd9eParent: 7ba3576- fix
- ♻️ exam answer sheet in SidePanel, course names, correct/wrong icons
6 changed files +175 -176
- src/components/exams/answer-sheet-view.tsx +46 -10
- src/components/layout/app-shell.tsx +1 -1
- src/pages/exam-answer-sheet-page.tsx +0 -151
- src/pages/exam-detail-page.tsx +108 -3
- src/pages/exams-page.tsx +20 -3
- src/routes/router.tsx +0 -8
src/components/exams/answer-sheet-view.tsxmodified+46 -10
| @@ -1,8 +1,12 @@ | ||
| 1 | 1 | import { For, Show, Suspense, createResource } from "solid-js"; |
| 2 | +import { ApiError } from "@/api/client"; | |
| 2 | 3 | import { getExamQuestions } from "@/api/getExamQuestions"; |
| 3 | 4 | import { getStudentAnswers } from "@/api/getStudentAnswers"; |
| 5 | +import type { StudentAnswerSheet } from "@/api/types"; | |
| 4 | 6 | import { Badge } from "@/components/ui/badge"; |
| 7 | +import { IconCheck, IconX } from "@/components/ui/icons"; | |
| 5 | 8 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 9 | +import { cn } from "@/lib/cn"; | |
| 6 | 10 | import { joinAnswerSheet } from "@/lib/answer-sheet"; |
| 7 | 11 | import { personLabelWithId } from "@/lib/person"; |
| 8 | 12 | import { useT } from "@/stores/preferences-context"; |
| @@ -12,7 +16,22 @@ export function AnswerSheetView(props: { examId: string; userId: string }) { | ||
| 12 | 16 | const [data] = createResource( |
| 13 | 17 | () => [props.examId, props.userId] as const, |
| 14 | 18 | async ([examId, userId]) => { |
| 15 | - const [questions, sheet] = await Promise.all([getExamQuestions(examId), getStudentAnswers(examId, userId)]); | |
| 19 | + const questions = await getExamQuestions(examId); | |
| 20 | + let sheet: StudentAnswerSheet; | |
| 21 | + try { | |
| 22 | + sheet = await getStudentAnswers(examId, userId); | |
| 23 | + } catch (err) { | |
| 24 | + if (err instanceof ApiError && err.status === 404) { | |
| 25 | + sheet = { | |
| 26 | + exam: examId, | |
| 27 | + user: { id: userId, username: userId, display_name: null }, | |
| 28 | + answers: [], | |
| 29 | + auto_score: { earned: 0, possible: 0 }, | |
| 30 | + }; | |
| 31 | + } else { | |
| 32 | + throw err; | |
| 33 | + } | |
| 34 | + } | |
| 16 | 35 | return { sheet, rows: joinAnswerSheet(questions.items, sheet.answers) }; |
| 17 | 36 | }, |
| 18 | 37 | ); |
| @@ -24,9 +43,11 @@ export function AnswerSheetView(props: { examId: string; userId: string }) { | ||
| 24 | 43 | <div class="space-y-4"> |
| 25 | 44 | <div class="flex flex-wrap items-center justify-between gap-2 rounded-md border bg-muted/30 px-4 py-3"> |
| 26 | 45 | <p class="text-sm font-medium">{personLabelWithId(d().sheet.user)}</p> |
| 27 | - <Badge variant="secondary"> | |
| 28 | - {t("exams.autoScore")}: {d().sheet.auto_score.earned}/{d().sheet.auto_score.possible} | |
| 29 | - </Badge> | |
| 46 | + <Show when={d().sheet.answers.length > 0} fallback={<Badge variant="outline">{t("exams.notStarted")}</Badge>}> | |
| 47 | + <Badge variant="secondary"> | |
| 48 | + {t("exams.autoScore")}: {d().sheet.auto_score.earned}/{d().sheet.auto_score.possible} | |
| 49 | + </Badge> | |
| 50 | + </Show> | |
| 30 | 51 | </div> |
| 31 | 52 | |
| 32 | 53 | <For each={d().rows}> |
| @@ -35,11 +56,22 @@ export function AnswerSheetView(props: { examId: string; userId: string }) { | ||
| 35 | 56 | <div class="mb-2 flex flex-wrap items-center gap-2"> |
| 36 | 57 | <span class="text-xs font-semibold text-muted-foreground">#{idx() + 1}</span> |
| 37 | 58 | <Badge variant="outline">{row.question.points} {t("questions.points")}</Badge> |
| 38 | - <Badge variant={row.answer?.is_correct === true ? "default" : row.answer?.is_correct === false ? "destructive" : "outline"}> | |
| 39 | - {row.answer?.is_correct === true ? t("exams.isCorrect") : | |
| 40 | - row.answer?.is_correct === false ? "✗" : | |
| 41 | - row.question.kind === "text" ? t("questions.kind.text") : "—"} | |
| 42 | - </Badge> | |
| 59 | + <Show when={row.answer?.is_correct != null}> | |
| 60 | + <Badge variant="outline" class={cn( | |
| 61 | + "size-[22px] p-0 flex items-center justify-center", | |
| 62 | + row.answer?.is_correct ? "border-green-300 bg-green-50 text-green-700 dark:border-green-700 dark:bg-green-950/30 dark:text-green-400" : "border-red-300 bg-red-50 text-red-700 dark:border-red-700 dark:bg-red-950/30 dark:text-red-400", | |
| 63 | + )}> | |
| 64 | + <Show when={row.answer?.is_correct} fallback={<IconX class="h-3 w-3" />}> | |
| 65 | + <IconCheck class="h-3 w-3" /> | |
| 66 | + </Show> | |
| 67 | + </Badge> | |
| 68 | + </Show> | |
| 69 | + <Show when={row.answer?.is_correct == null && row.question.kind === "text"}> | |
| 70 | + <Badge variant="outline" class="text-[10px]">{t("questions.kind.text")}</Badge> | |
| 71 | + </Show> | |
| 72 | + <Show when={row.answer?.is_correct == null && row.question.kind !== "text"}> | |
| 73 | + <span class="text-xs text-muted-foreground">—</span> | |
| 74 | + </Show> | |
| 43 | 75 | </div> |
| 44 | 76 | <p class="mb-3 whitespace-pre-wrap text-sm font-medium">{row.question.text}</p> |
| 45 | 77 | |
| @@ -73,7 +105,11 @@ export function AnswerSheetView(props: { examId: string; userId: string }) { | ||
| 73 | 105 | <Show when={ci() === row.answer?.selected && ci() !== row.question.correct}> |
| 74 | 106 | <Badge variant="destructive" class="ml-auto text-[10px]">✗</Badge> |
| 75 | 107 | </Show> |
| 76 | - {ci() === row.question.correct && <Badge variant="outline" class="ml-auto text-[10px]">{t("questions.correct")}</Badge>} | |
| 108 | + {ci() === row.question.correct && ( | |
| 109 | + <Badge variant="outline" class="ml-auto border-green-300 bg-green-50 text-green-700 text-[10px] dark:border-green-700 dark:bg-green-950/30 dark:text-green-400"> | |
| 110 | + <IconCheck class="h-3 w-3" /> | |
| 111 | + </Badge> | |
| 112 | + )} | |
| 77 | 113 | </div> |
| 78 | 114 | )} |
| 79 | 115 | </For> |
src/components/layout/app-shell.tsxmodified+1 -1
| @@ -25,7 +25,7 @@ export function AppShell(props: ParentProps) { | ||
| 25 | 25 | const [celebiOpen, setCelebiOpen] = createSignal(false); |
| 26 | 26 | const collapsed = () => prefs.sidebarCollapsed(); |
| 27 | 27 | const location = useLocation(); |
| 28 | - const wide = () => location().pathname.startsWith("/exam-room/") || location().pathname.startsWith("/exam-answers/") || location().pathname === "/messages"; | |
| 28 | + const wide = () => location().pathname.startsWith("/exam-room/") || location().searchStr.includes("answerUser=") || location().pathname === "/messages"; | |
| 29 | 29 | const routeLabel = createMemo(() => { |
| 30 | 30 | const path = location().pathname; |
| 31 | 31 | if (path === "/") return t("nav.home"); |
src/pages/exam-answer-sheet-page.tsxdeleted+0 -151
| @@ -1,151 +0,0 @@ | ||
| 1 | -import { Link, useLocation } from "@tanstack/solid-router"; | |
| 2 | -import { Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; | |
| 3 | -import { getExamById } from "@/api/getExamById"; | |
| 4 | -import { getExamResults } from "@/api/getExamResults"; | |
| 5 | -import { postExamResult } from "@/api/postExamResult"; | |
| 6 | -import { formatApiError } from "@/api/client"; | |
| 7 | -import { AnswerSheetView } from "@/components/exams/answer-sheet-view"; | |
| 8 | -import { PageHeader } from "@/components/layout/page-header"; | |
| 9 | -import { RouteGuard } from "@/components/layout/route-guard"; | |
| 10 | -import { Alert } from "@/components/ui/alert"; | |
| 11 | -import { Button } from "@/components/ui/button"; | |
| 12 | -import { IconChevronLeft } from "@/components/ui/icons"; | |
| 13 | -import { Input } from "@/components/ui/input"; | |
| 14 | -import { Label } from "@/components/ui/label"; | |
| 15 | -import { PageSpinner } from "@/components/ui/page-spinner"; | |
| 16 | -import { createFlash } from "@/lib/flash"; | |
| 17 | -import { personId } from "@/lib/person"; | |
| 18 | -import { hasMinRole } from "@/lib/roles"; | |
| 19 | -import { useAuth } from "@/stores/auth-context"; | |
| 20 | -import { useT } from "@/stores/preferences-context"; | |
| 21 | - | |
| 22 | -export default function ExamAnswerSheetPage() { | |
| 23 | - return ( | |
| 24 | - <RouteGuard> | |
| 25 | - <ExamAnswerSheetContent /> | |
| 26 | - </RouteGuard> | |
| 27 | - ); | |
| 28 | -} | |
| 29 | - | |
| 30 | -function ExamAnswerSheetContent() { | |
| 31 | - const auth = useAuth(); | |
| 32 | - const location = useLocation(); | |
| 33 | - const t = useT(); | |
| 34 | - const [mark, setMark] = createSignal("0"); | |
| 35 | - const [error, setError] = createSignal(""); | |
| 36 | - const [pending, setPending] = createSignal(false); | |
| 37 | - const [flash, setFlash] = createFlash(); | |
| 38 | - const params = createMemo((prev: { examId: string; userId: string }) => { | |
| 39 | - const match = /^\/exam-answers\/([^/]+)\/([^/]+)$/.exec(location().pathname); | |
| 40 | - return match ? { examId: decodeURIComponent(match[1]), userId: decodeURIComponent(match[2]) } : prev; | |
| 41 | - }, { examId: "", userId: "" }); | |
| 42 | - const [exam] = createResource(() => params().examId, (examId) => getExamById(examId)); | |
| 43 | - const [result, { refetch: refetchResult }] = createResource( | |
| 44 | - () => params(), | |
| 45 | - async ({ examId, userId }) => { | |
| 46 | - if (!examId || !userId) return null; | |
| 47 | - const page = await getExamResults(examId, { limit: 500, offset: 0 }); | |
| 48 | - const row = page.items.find((item) => personId(item.user) === userId) ?? null; | |
| 49 | - setMark(row ? String(row.mark) : "0"); | |
| 50 | - return row; | |
| 51 | - }, | |
| 52 | - ); | |
| 53 | - const canView = () => { | |
| 54 | - const e = exam(); | |
| 55 | - const u = auth.user(); | |
| 56 | - if (!e || !u) return false; | |
| 57 | - return e.creator === u.id || hasMinRole(u.role, "manager"); | |
| 58 | - }; | |
| 59 | - const setClampedMark = (value: string) => { | |
| 60 | - if (value === "") { | |
| 61 | - setMark(value); | |
| 62 | - return; | |
| 63 | - } | |
| 64 | - const next = Math.max(0, Math.min(100, Number(value))); | |
| 65 | - setMark(Number.isNaN(next) ? "" : String(Math.trunc(next))); | |
| 66 | - }; | |
| 67 | - const submitMark = async (event: SubmitEvent) => { | |
| 68 | - event.preventDefault(); | |
| 69 | - const next = Number(mark()); | |
| 70 | - if (!Number.isInteger(next) || next < 0 || next > 100) { | |
| 71 | - setError(t("form.markRange")); | |
| 72 | - return; | |
| 73 | - } | |
| 74 | - setError(""); | |
| 75 | - setPending(true); | |
| 76 | - try { | |
| 77 | - await postExamResult(params().examId, { user_id: params().userId, mark: next }); | |
| 78 | - await refetchResult(); | |
| 79 | - setFlash(t("common.saved")); | |
| 80 | - } catch (err) { | |
| 81 | - setError(formatApiError(err)); | |
| 82 | - } finally { | |
| 83 | - setPending(false); | |
| 84 | - } | |
| 85 | - }; | |
| 86 | - | |
| 87 | - return ( | |
| 88 | - <Suspense fallback={<PageSpinner />}> | |
| 89 | - <Show | |
| 90 | - when={exam()?.id === params().examId ? exam() : undefined} | |
| 91 | - fallback={ | |
| 92 | - <Show when={exam.error} fallback={<PageSpinner />}> | |
| 93 | - <Alert variant="destructive">{formatApiError(exam.error)}</Alert> | |
| 94 | - </Show> | |
| 95 | - } | |
| 96 | - > | |
| 97 | - {(ex) => ( | |
| 98 | - <Show when={canView()} fallback={<Alert variant="destructive">{t("common.accessDenied")}</Alert>}> | |
| 99 | - <div class="space-y-5"> | |
| 100 | - <PageHeader | |
| 101 | - compact | |
| 102 | - accent="rose" | |
| 103 | - eyebrow={t("exams.answerSheet")} | |
| 104 | - title={ex().title} | |
| 105 | - description={ex().description || undefined} | |
| 106 | - actions={ | |
| 107 | - <Link to="/exams/$id" params={{ id: params().examId }}> | |
| 108 | - <Button variant="ghost" size="sm" class="w-full rounded-md sm:w-auto"> | |
| 109 | - <IconChevronLeft class="h-4 w-4" /> | |
| 110 | - {t("common.back")} | |
| 111 | - </Button> | |
| 112 | - </Link> | |
| 113 | - } | |
| 114 | - /> | |
| 115 | - <AnswerSheetView examId={params().examId} userId={params().userId} /> | |
| 116 | - <form class="rounded-xl border border-border bg-card p-4 shadow-sm" onSubmit={submitMark}> | |
| 117 | - <div class="flex flex-wrap items-end gap-3"> | |
| 118 | - <div class="min-w-36 flex-1 space-y-1.5"> | |
| 119 | - <Label for="answer-sheet-mark">{t("form.mark")}</Label> | |
| 120 | - <Input | |
| 121 | - id="answer-sheet-mark" | |
| 122 | - class="h-10 rounded-sm" | |
| 123 | - type="number" | |
| 124 | - min={0} | |
| 125 | - max={100} | |
| 126 | - step={1} | |
| 127 | - value={mark()} | |
| 128 | - onInput={(event) => setClampedMark(event.currentTarget.value)} | |
| 129 | - /> | |
| 130 | - </div> | |
| 131 | - <Button type="submit" class="h-10 rounded-sm" disabled={pending() || result.loading}> | |
| 132 | - {t("common.update")} | |
| 133 | - </Button> | |
| 134 | - </div> | |
| 135 | - <Show when={result()}> | |
| 136 | - {(row) => <p class="mt-2 text-xs text-muted-foreground">{t("form.mark")}: {row().mark}/100</p>} | |
| 137 | - </Show> | |
| 138 | - <Show when={flash()}> | |
| 139 | - {(msg) => <Alert variant="success" class="mt-3">{msg()}</Alert>} | |
| 140 | - </Show> | |
| 141 | - <Show when={error()}> | |
| 142 | - {(msg) => <p class="mt-3 text-sm text-destructive">{msg()}</p>} | |
| 143 | - </Show> | |
| 144 | - </form> | |
| 145 | - </div> | |
| 146 | - </Show> | |
| 147 | - )} | |
| 148 | - </Show> | |
| 149 | - </Suspense> | |
| 150 | - ); | |
| 151 | -} |
src/pages/exam-detail-page.tsxmodified+108 -3
| @@ -16,6 +16,7 @@ import { ApiError, formatApiError } from "@/api/client"; | ||
| 16 | 16 | import type { ExamResult } from "@/api/types"; |
| 17 | 17 | import { ExamForm } from "@/components/exams/exam-form"; |
| 18 | 18 | import { ExamQuestionsPanel } from "@/components/exams/exam-questions-panel"; |
| 19 | +import { AnswerSheetView } from "@/components/exams/answer-sheet-view"; | |
| 19 | 20 | import { ExamResultBadge } from "@/components/exams/exam-result-badge"; |
| 20 | 21 | import { GradeForm } from "@/components/exams/grade-form"; |
| 21 | 22 | import { RouteGuard } from "@/components/layout/route-guard"; |
| @@ -25,7 +26,8 @@ import { Badge } from "@/components/ui/badge"; | ||
| 25 | 26 | import { Button } from "@/components/ui/button"; |
| 26 | 27 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 27 | 28 | import { DataTable } from "@/components/ui/data-table"; |
| 28 | -import { IconChevronLeft, IconEdit, IconExam, IconEye, IconPlus, IconTrash } from "@/components/ui/icons"; | |
| 29 | +import { IconChevronDown, IconChevronLeft, IconEdit, IconExam, IconEye, IconPlus, IconTrash } from "@/components/ui/icons"; | |
| 30 | +import { Input } from "@/components/ui/input"; | |
| 29 | 31 | import { PaginationControls } from "@/components/ui/pagination-controls"; |
| 30 | 32 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 31 | 33 | import { SectionDisclosure } from "@/components/ui/section-disclosure"; |
| @@ -84,6 +86,11 @@ function ExamDetailContent() { | ||
| 84 | 86 | const [removeUserId, setRemoveUserId] = createSignal<string | null>(null); |
| 85 | 87 | const [gradeOpen, setGradeOpen] = createSignal(false); |
| 86 | 88 | const [resultPage, setResultPage] = createSignal(0); |
| 89 | + const [answerSheetUserId, setAnswerSheetUserId] = createSignal<string | null>(null); | |
| 90 | + const answerSheetOpen = () => answerSheetUserId() != null; | |
| 91 | + const [answerMark, setAnswerMark] = createSignal("0"); | |
| 92 | + const [answerError, setAnswerError] = createSignal(""); | |
| 93 | + const [answerPending, setAnswerPending] = createSignal(false); | |
| 87 | 94 | const [questionCreateOpen, setQuestionCreateOpen] = createSignal(false); |
| 88 | 95 | const [openSections, setOpenSections] = createSignal({ |
| 89 | 96 | schedule: false, |
| @@ -135,6 +142,17 @@ function ExamDetailContent() { | ||
| 135 | 142 | () => (hasCourseManagementRights() && gradeOpen() ? id() : null), |
| 136 | 143 | async (examId) => examId ? getExamResults(examId, { limit: 500, offset: 0 }) : null, |
| 137 | 144 | ); |
| 145 | + const [answerResult, { refetch: refetchAnswerResult }] = createResource( | |
| 146 | + () => (hasCourseManagementRights() && answerSheetOpen() ? [id(), answerSheetUserId()!] as const : null), | |
| 147 | + async (source) => { | |
| 148 | + if (!source) return null; | |
| 149 | + const [examId, userId] = source; | |
| 150 | + const page = await getExamResults(examId, { limit: 500, offset: 0 }); | |
| 151 | + const row = page.items.find((item) => personId(item.user) === userId) ?? null; | |
| 152 | + setAnswerMark(row ? String(row.mark) : "0"); | |
| 153 | + return row; | |
| 154 | + }, | |
| 155 | + ); | |
| 138 | 156 | const [stats] = createResource( |
| 139 | 157 | () => (hasCourseManagementRights() && openSections().statistics ? id() : null), |
| 140 | 158 | async (examId) => { |
| @@ -205,6 +223,36 @@ function ExamDetailContent() { | ||
| 205 | 223 | const isDraft = () => exam()?.draft === true; |
| 206 | 224 | const resultTotal = () => results()?.total ?? 0; |
| 207 | 225 | const resultTotalPages = () => Math.max(1, Math.ceil(resultTotal() / RESULT_PAGE_SIZE)); |
| 226 | + const setClampedAnswerMark = (value: string) => { | |
| 227 | + if (value === "") { | |
| 228 | + setAnswerMark(value); | |
| 229 | + return; | |
| 230 | + } | |
| 231 | + const next = Math.max(0, Math.min(100, Number(value))); | |
| 232 | + setAnswerMark(Number.isNaN(next) ? "" : String(Math.trunc(next))); | |
| 233 | + }; | |
| 234 | + const submitAnswerMark = async (event: SubmitEvent) => { | |
| 235 | + event.preventDefault(); | |
| 236 | + const userId = answerSheetUserId(); | |
| 237 | + if (!userId) return; | |
| 238 | + const mark = Number(answerMark()); | |
| 239 | + if (!Number.isInteger(mark) || mark < 0 || mark > 100) { | |
| 240 | + setAnswerError(t("form.markRange")); | |
| 241 | + return; | |
| 242 | + } | |
| 243 | + setAnswerError(""); | |
| 244 | + setAnswerPending(true); | |
| 245 | + try { | |
| 246 | + await postExamResult(id(), { user_id: userId, mark }); | |
| 247 | + await refetchAnswerResult(); | |
| 248 | + await refetchResults(); | |
| 249 | + setFlash(t("common.saved")); | |
| 250 | + } catch (err) { | |
| 251 | + setAnswerError(formatApiError(err)); | |
| 252 | + } finally { | |
| 253 | + setAnswerPending(false); | |
| 254 | + } | |
| 255 | + }; | |
| 208 | 256 | createEffect(() => { |
| 209 | 257 | if (resultPage() >= resultTotalPages()) setResultPage(resultTotalPages() - 1); |
| 210 | 258 | }); |
| @@ -249,12 +297,12 @@ function ExamDetailContent() { | ||
| 249 | 297 | { |
| 250 | 298 | label: t("exams.answerSheet"), |
| 251 | 299 | icon: <IconEye class="h-4 w-4" />, |
| 252 | - onSelect: () => void navigate({ to: "/exam-answers/$examId/$userId", params: { examId: id(), userId: personId(cell.row.original.user) } }), | |
| 300 | + onSelect: () => setAnswerSheetUserId(personId(cell.row.original.user)), | |
| 253 | 301 | }, |
| 254 | 302 | { |
| 255 | 303 | label: t("common.update"), |
| 256 | 304 | icon: <IconEdit class="h-4 w-4" />, |
| 257 | - onSelect: () => void navigate({ to: "/exam-answers/$examId/$userId", params: { examId: id(), userId: personId(cell.row.original.user) } }), | |
| 305 | + onSelect: () => setAnswerSheetUserId(personId(cell.row.original.user)), | |
| 258 | 306 | }, |
| 259 | 307 | ...(!isFinished() |
| 260 | 308 | ? [{ |
| @@ -386,6 +434,63 @@ function ExamDetailContent() { | ||
| 386 | 434 | </div> |
| 387 | 435 | </div> |
| 388 | 436 | |
| 437 | + <SidePanel | |
| 438 | + open={answerSheetOpen()} | |
| 439 | + onOpenChange={(open) => { if (!open) setAnswerSheetUserId(null); }} | |
| 440 | + title={t("exams.answerSheet")} | |
| 441 | + size="wide" | |
| 442 | + > | |
| 443 | + <Show when={answerSheetUserId()}> | |
| 444 | + {(userId) => { | |
| 445 | + const [markOpen, setMarkOpen] = createSignal(false); | |
| 446 | + return ( | |
| 447 | + <div class="space-y-4"> | |
| 448 | + <button | |
| 449 | + type="button" | |
| 450 | + onClick={() => setMarkOpen((v) => !v)} | |
| 451 | + class="flex w-full items-center justify-between gap-3 rounded-lg border border-border bg-card px-4 py-3 text-left text-sm shadow-sm transition-colors hover:bg-muted/40" | |
| 452 | + > | |
| 453 | + <span class="inline-flex items-center gap-2 font-medium"> | |
| 454 | + <IconEdit class="h-4 w-4" /> | |
| 455 | + <span>{t("form.mark")} {t("common.update")}</span> | |
| 456 | + </span> | |
| 457 | + <span class="inline-flex items-center gap-2"> | |
| 458 | + <Show when={answerResult()}> | |
| 459 | + {(row) => <span class="tabular-nums font-semibold">{row().mark}/100</span>} | |
| 460 | + </Show> | |
| 461 | + <IconChevronDown class={cn("h-4 w-4 text-muted-foreground transition-transform", markOpen() && "rotate-180")} /> | |
| 462 | + </span> | |
| 463 | + </button> | |
| 464 | + <Show when={markOpen()}> | |
| 465 | + <form class="space-y-3" onSubmit={submitAnswerMark}> | |
| 466 | + <div class="flex items-end gap-2"> | |
| 467 | + <Input | |
| 468 | + id="answer-sheet-mark" | |
| 469 | + class="h-10 flex-1 rounded-lg" | |
| 470 | + type="number" | |
| 471 | + min={0} | |
| 472 | + max={100} | |
| 473 | + step={1} | |
| 474 | + value={answerMark()} | |
| 475 | + onInput={(event) => setClampedAnswerMark(event.currentTarget.value)} | |
| 476 | + /> | |
| 477 | + <span class="pb-2 text-sm text-muted-foreground">/ 100</span> | |
| 478 | + <Button type="submit" class="h-10 rounded-lg shrink-0" disabled={answerPending() || answerResult.loading}> | |
| 479 | + {t("common.save")} | |
| 480 | + </Button> | |
| 481 | + </div> | |
| 482 | + <Show when={answerError()}> | |
| 483 | + {(msg) => <p class="text-sm text-destructive">{msg()}</p>} | |
| 484 | + </Show> | |
| 485 | + </form> | |
| 486 | + </Show> | |
| 487 | + <AnswerSheetView examId={id()} userId={userId()} /> | |
| 488 | + </div> | |
| 489 | + ); | |
| 490 | + }} | |
| 491 | + </Show> | |
| 492 | + </SidePanel> | |
| 493 | + | |
| 389 | 494 | <ConfirmDialog |
| 390 | 495 | open={deleteOpen()} |
| 391 | 496 | onOpenChange={setDeleteOpen} |
src/pages/exams-page.tsxmodified+20 -3
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal, onCleanup } from "solid-js"; |
| 2 | 2 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 3 | 3 | import { useNavigate } from "@tanstack/solid-router"; |
| 4 | +import { getCourseById } from "@/api/getCourseById"; | |
| 4 | 5 | import { getCourses } from "@/api/getCourses"; |
| 5 | 6 | import { getExamAttempt } from "@/api/getExamAttempt"; |
| 6 | 7 | import { getExams } from "@/api/getExams"; |
| @@ -75,8 +76,12 @@ function ExamsContent() { | ||
| 75 | 76 | visibleCourses().filter((course) => course.creator.id === auth.user()?.id || hasMinRole(auth.user()?.role, "manager")), |
| 76 | 77 | ); |
| 77 | 78 | const canCreate = () => hasMinRole(auth.user()?.role, "teacher") && manageableCourses().length > 0; |
| 78 | - const courseById = createMemo(() => new Map(visibleCourses().map((course) => [course.id, course]))); | |
| 79 | - const courseTitle = (courseId: string) => courseById().get(courseId)?.title ?? courseId; | |
| 79 | + const [courseMap, setCourseMap] = createSignal<Record<string, string>>({}); | |
| 80 | + const courseTitle = (courseId: string) => { | |
| 81 | + const cached = visibleCourses().find((c) => c.id === courseId); | |
| 82 | + if (cached) return cached.title; | |
| 83 | + return courseMap()[courseId] ?? courseId; | |
| 84 | + }; | |
| 80 | 85 | |
| 81 | 86 | const examStatus = (exam: Exam) => examDisplayStatus(exam, now(), attemptStatuses()[exam.id]); |
| 82 | 87 | |
| @@ -99,9 +104,21 @@ function ExamsContent() { | ||
| 99 | 104 | () => { |
| 100 | 105 | // Do not track now() here — it ticks every second and would re-fetch forever. |
| 101 | 106 | if (isStudent() && mine() === undefined) return null; |
| 107 | + if (!isStudent() && courses() === undefined) return null; | |
| 102 | 108 | return [isStudent() ? "s" : "t", (mine() ?? []).map((c) => c.id).join(",")].join("|"); |
| 103 | 109 | }, |
| 104 | - async () => (await getExams()).items, | |
| 110 | + async () => { | |
| 111 | + const items = (await getExams()).items; | |
| 112 | + const known = new Map(visibleCourses().map((c) => [c.id, c.title])); | |
| 113 | + const missing = [...new Set(items.map((e) => e.course))].filter((id) => !known.has(id)); | |
| 114 | + if (missing.length > 0) { | |
| 115 | + await Promise.all(missing.map((id) => | |
| 116 | + getCourseById(id).then((c) => known.set(id, c.title)).catch(() => {}), | |
| 117 | + )); | |
| 118 | + } | |
| 119 | + setCourseMap(Object.fromEntries(known)); | |
| 120 | + return items; | |
| 121 | + }, | |
| 105 | 122 | ); |
| 106 | 123 | |
| 107 | 124 | createEffect(() => { |
src/routes/router.tsxmodified+0 -8
| @@ -29,7 +29,6 @@ const EventsPage = lazyRoute(() => import("@/pages/events-page")); | ||
| 29 | 29 | const EventDetailPage = lazyRoute(() => import("@/pages/event-detail-page")); |
| 30 | 30 | const ExamsPage = lazyRoute(() => import("@/pages/exams-page")); |
| 31 | 31 | const ExamDetailPage = lazyRoute(() => import("@/pages/exam-detail-page")); |
| 32 | -const ExamAnswerSheetPage = lazyRoute(() => import("@/pages/exam-answer-sheet-page")); | |
| 33 | 32 | const ExamRoomPage = lazyRoute(() => import("@/pages/exam-room-page")); |
| 34 | 33 | const CoursesPage = lazyRoute(() => import("@/pages/courses-page")); |
| 35 | 34 | const CourseDetailPage = lazyRoute(() => import("@/pages/course-detail-page")); |
| @@ -120,12 +119,6 @@ const examDetailRoute = createRoute({ | ||
| 120 | 119 | component: ExamDetailPage, |
| 121 | 120 | }); |
| 122 | 121 | |
| 123 | -const examAnswerSheetRoute = createRoute({ | |
| 124 | - getParentRoute: () => rootRoute, | |
| 125 | - path: "/exam-answers/$examId/$userId", | |
| 126 | - component: ExamAnswerSheetPage, | |
| 127 | -}); | |
| 128 | - | |
| 129 | 122 | const examRoomRoute = createRoute({ |
| 130 | 123 | getParentRoute: () => rootRoute, |
| 131 | 124 | path: "/exam-room/$id", |
| @@ -247,7 +240,6 @@ const routeTree = rootRoute.addChildren([ | ||
| 247 | 240 | notesRoute, |
| 248 | 241 | eventsRoute, |
| 249 | 242 | eventDetailRoute, |
| 250 | - examAnswerSheetRoute, | |
| 251 | 243 | examDetailRoute, |
| 252 | 244 | examRoomRoute, |
| 253 | 245 | liveMonitorRoute, |