forge
Explore
Log in

Don't you dare go Hollow

📝 grade submitted/expired attempts during live exam

Browse files at this commit

08a1204db46ee3799c10fc9756e2038ccf0dcc53Burak BoduroğluParent: 02a2588
  • feat
    • 📝 grade submitted/expired attempts during live exam
Show full message
feat: 📝 grade submitted/expired attempts during live exam
- add onViewAnswers prop to GradeForm for answer sheet navigation
- fetch live roster for grading; show students who submitted/expired
- enable grade button during the exam (not just after finish)
- remove "grade after exam" helper text
src/components/exams/grade-form.tsxmodified+15 -6
@@ -1,8 +1,8 @@
1-import { For, createMemo, createSignal } from "solid-js";
1+import { For, Show, createMemo, createSignal } from "solid-js";
22 import { formatApiError } from "@/api/client";
33 import { Button } from "@/components/ui/button";
44 import { ConfirmDialog } from "@/components/ui/confirm-dialog";
5-import { IconCheck } from "@/components/ui/icons";
5+import { IconCheck, IconEye } from "@/components/ui/icons";
66 import { Input } from "@/components/ui/input";
77 import { Label } from "@/components/ui/label";
88 import { Select } from "@/components/ui/select";
@@ -16,6 +16,7 @@ export type GradeFormValues = {
1616 export function GradeForm(props: {
1717 students: { id: string; label: string }[];
1818 onSubmit: (values: GradeFormValues) => Promise<void>;
19+ onViewAnswers?: (userId: string) => void;
1920 }) {
2021 const t = useT();
2122 const [userId, setUserId] = createSignal("");
@@ -87,10 +88,18 @@ export function GradeForm(props: {
8788 />
8889 </div>
8990 </div>
90- <Button type="submit" disabled={pending()}>
91- <IconCheck />
92- {t("exams.gradeStudent")}
93- </Button>
91+ <div class="flex flex-wrap gap-2">
92+ <Show when={props.onViewAnswers}>
93+ <Button type="button" variant="outline" disabled={!userId()} onClick={() => props.onViewAnswers?.(userId())}>
94+ <IconEye />
95+ {t("exams.answerSheet")}
96+ </Button>
97+ </Show>
98+ <Button type="submit" disabled={pending()}>
99+ <IconCheck />
100+ {t("exams.gradeStudent")}
101+ </Button>
102+ </div>
94103 {error() && <p class="text-sm text-destructive">{error()}</p>}
95104 </form>
96105
src/pages/exam-detail-page.tsxmodified+18 -4
@@ -5,6 +5,7 @@ import { deleteExamById } from "@/api/exams";
55 import { deleteExamResultByUserId } from "@/api/exams";
66 import { getExamById } from "@/api/exams";
77 import { getExamAttempt } from "@/api/exams";
8+import { getExamLive } from "@/api/exams";
89 import { getExamResult } from "@/api/exams";
910 import { getExamResults } from "@/api/exams";
1011 import { getExamStatistics } from "@/api/exams";
@@ -221,6 +222,10 @@ function ExamDetailContent() {
221222 return t("exams.unscheduled");
222223 };
223224 const isDraft = () => exam()?.draft === true;
225+ const [gradeLive] = createResource(
226+ () => (hasCourseManagementRights() && gradeOpen() && !isFinished() ? id() : null),
227+ async (examId) => examId ? getExamLive(examId) : null,
228+ );
224229 const resultTotal = () => results()?.total ?? 0;
225230 const resultTotalPages = () => Math.max(1, Math.ceil(resultTotal() / RESULT_PAGE_SIZE));
226231 const setClampedAnswerMark = (value: string) => {
@@ -259,6 +264,14 @@ function ExamDetailContent() {
259264 const gradeStudents = () => {
260265 if (gradeResults.loading) return [];
261266 const graded = new Set((gradeResults()?.items ?? []).map((row) => personId(row.user)));
267+ if (!isFinished()) {
268+ return (gradeLive()?.students ?? [])
269+ .filter((row) => (row.status === "submitted" || row.status === "expired") && !graded.has(personId(row.user)))
270+ .map((row) => ({
271+ id: personId(row.user),
272+ label: personLabelWithId(row.user),
273+ }));
274+ }
262275 return (roster() ?? [])
263276 .filter((row) => !graded.has(row.user.id))
264277 .map((row) => ({
@@ -671,6 +684,10 @@ function ExamDetailContent() {
671684 >
672685 <GradeForm
673686 students={gradeStudents()}
687+ onViewAnswers={(userId) => {
688+ setGradeOpen(false);
689+ setAnswerSheetUserId(userId);
690+ }}
674691 onSubmit={async (values) => {
675692 await postExamResult(id(), values);
676693 await refetchResults();
@@ -688,10 +705,7 @@ function ExamDetailContent() {
688705 actions={
689706 <Show when={hasCourseManagementRights()}>
690707 <div class="flex items-center gap-2">
691- <Show when={!isFinished()}>
692- <span class="text-xs text-muted-foreground">{t("exams.gradeAfterExam")}</span>
693- </Show>
694- <Button type="button" variant="outline" size="sm" class="rounded-lg" disabled={!isFinished() || isDraft()} onClick={() => setGradeOpen(true)}>
708+ <Button type="button" variant="outline" size="sm" class="rounded-lg" disabled={isDraft()} onClick={() => setGradeOpen(true)}>
695709 <IconEdit class="h-4 w-4" />
696710 {t("exams.gradeStudent")}
697711 </Button>