From cae0fc497304cb574b93c39c06278eecaaa73798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Mon, 20 Jul 2026 07:47:29 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20exam=20status=20colors=20?= =?UTF-8?q?and=20polling,=20add=20submitted/expired=20filters=20-=20replac?= =?UTF-8?q?e=20broken=20attemptCache=20approach=20with=20simpler=20polling?= =?UTF-8?q?=20that=20handles=20all=20errors=20-=20add=20submitted/expired?= =?UTF-8?q?=20options=20to=20status=20filter=20dropdown=20-=20active:=20bl?= =?UTF-8?q?ue=20(sky),=20submitted:=20green=20(emerald),=20expired:=20red?= =?UTF-8?q?=20(rose)=20-=20update=20detail=20page=20badge=20to=20use=20sub?= =?UTF-8?q?mitted=20tone=20-=20remove=20unused=20ApiError=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/schedule-status.ts | 9 ++++-- src/pages/exam-detail-page.tsx | 8 ++--- src/pages/exams-page.tsx | 59 +++++++++++++++++++++++++++------- 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/src/lib/schedule-status.ts b/src/lib/schedule-status.ts index 30f5c31..cae2da0 100644 --- a/src/lib/schedule-status.ts +++ b/src/lib/schedule-status.ts @@ -6,10 +6,14 @@ export type ScheduleStatus = | "soon" | "finished" | "past" - | "unscheduled"; + | "unscheduled" + | "submitted"; export function scheduleStatusClass(status: ScheduleStatus | string): string { if (status === "active") { + return "border-sky-500/30 bg-sky-500/10 text-sky-700 dark:text-sky-300"; + } + if (status === "submitted") { return "border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300"; } if (status === "today" || status === "upcoming" || status === "soon") { @@ -22,7 +26,8 @@ export function scheduleStatusClass(status: ScheduleStatus | string): string { } export function scheduleStatusDotClass(status: ScheduleStatus | string): string { - if (status === "active") return "bg-emerald-600"; + if (status === "active") return "bg-sky-600"; + if (status === "submitted") return "bg-emerald-600"; if (status === "today" || status === "upcoming" || status === "soon") return "bg-amber-600"; if (status === "finished" || status === "past") return "bg-rose-600"; return "bg-muted-foreground"; diff --git a/src/pages/exam-detail-page.tsx b/src/pages/exam-detail-page.tsx index 08ecd2a..bc1af55 100644 --- a/src/pages/exam-detail-page.tsx +++ b/src/pages/exam-detail-page.tsx @@ -92,6 +92,8 @@ function ExamDetailContent() { questions: false, results: false, }); + const isSittable = () => exam()?.mode === "sync" || exam()?.mode === "async" || exam()?.mode === "open"; + const isScheduled = () => isSittable(); const [ownResult] = createResource( () => (isStudent() ? id() : null), @@ -191,8 +193,6 @@ function ExamDetailContent() { if (mode === "open") return t("exams.mode.open"); return t("exams.unscheduled"); }; - const isSittable = () => exam()?.mode === "sync" || exam()?.mode === "async" || exam()?.mode === "open"; - const isScheduled = () => isSittable(); const isDraft = () => exam()?.draft === true; const gradeStudents = () => { const graded = new Set((results() ?? []).map((row) => personId(row.user))); @@ -347,10 +347,10 @@ function ExamDetailContent() { variant="outline" class={cn( "mt-2 w-fit rounded-sm capitalize", - scheduleStatusClass(detailStatus() === "submitted" || detailStatus() === "expired" ? "finished" : detailStatus()), + scheduleStatusClass(detailStatus() === "expired" ? "finished" : detailStatus()), )} > - + {detailStatusLabel()} diff --git a/src/pages/exams-page.tsx b/src/pages/exams-page.tsx index ec7cc88..c313450 100644 --- a/src/pages/exams-page.tsx +++ b/src/pages/exams-page.tsx @@ -1,13 +1,14 @@ -import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; +import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal, onCleanup } from "solid-js"; import type { ColumnDef } from "@tanstack/solid-table"; import { useNavigate } from "@tanstack/solid-router"; import { getCourses } from "@/api/getCourses"; +import { getExamAttempt } from "@/api/getExamAttempt"; import { getExams } from "@/api/getExams"; import { getMyCourses } from "@/api/getMyCourses"; import { patchExamById } from "@/api/patchExamById"; import { postCourseExam } from "@/api/postCourseExam"; import { formatApiError } from "@/api/client"; -import type { Course, Exam } from "@/api/types"; +import type { AttemptStatus, Course, Exam } from "@/api/types"; import { ExamForm, type ExamFormValues } from "@/components/exams/exam-form"; import { RouteGuard } from "@/components/layout/route-guard"; import { PageHeader } from "@/components/layout/page-header"; @@ -31,7 +32,8 @@ import { usePreferences, useT } from "@/stores/preferences-context"; const EXAM_PAGE_SIZE = 12; -type ExamStatus = "draft" | "unscheduled" | "upcoming" | "active" | "finished"; +type ExamStatus = "draft" | "unscheduled" | "upcoming" | "active" | "finished" | "submitted" | "expired"; +type ExamRow = Exam & { displayStatus: ExamStatus }; export default function ExamsPage() { return ( @@ -53,6 +55,7 @@ function ExamsContent() { const [createOpen, setCreateOpen] = createSignal(false); const [selectedCourseId, setSelectedCourseId] = createSignal(""); const [editingExam, setEditingExam] = createSignal(null); + const [attemptStatuses, setAttemptStatuses] = createSignal>({}); const [flash, setFlash] = createFlash(); const [courses] = createResource( @@ -75,9 +78,12 @@ function ExamsContent() { const courseById = createMemo(() => new Map(visibleCourses().map((course) => [course.id, course]))); const courseTitle = (courseId: string) => courseById().get(courseId)?.title ?? courseId; + const isSittable = (exam: Exam) => exam.mode === "sync" || exam.mode === "async" || exam.mode === "open"; const examStatus = (exam: Exam): ExamStatus => { + const own = attemptStatuses()[exam.id]; + if (own === "submitted" || own === "expired") return own; if (exam.draft) return "draft"; - if (exam.mode !== "sync" && exam.mode !== "async" && exam.mode !== "open") return "unscheduled"; + if (!isSittable(exam)) return "unscheduled"; if (exam.mode === "open") return "active"; const current = now(); if (exam.ends_at != null && exam.ends_at < current) return "finished"; @@ -94,8 +100,8 @@ function ExamsContent() { return true; }); }; - const searchExam = (exam: Exam, query: string) => - [exam.title, exam.description, courseTitle(exam.course), examKindLabel(String(exam.kind), t), statusLabel(examStatus(exam))] + const searchExam = (exam: ExamRow, query: string) => + [exam.title, exam.description, courseTitle(exam.course), examKindLabel(String(exam.kind), t), statusLabel(exam.displayStatus)] .join(" ") .toLocaleLowerCase(locale()) .includes(query.toLocaleLowerCase(locale())); @@ -115,15 +121,42 @@ function ExamsContent() { }); const statusLabel = (status: ExamStatus) => { + if (status === "submitted") return t("attempt.submitted"); + if (status === "expired") return t("attempt.expired"); if (status === "draft") return t("exams.draft"); if (status === "unscheduled") return t("exams.unscheduled"); if (status === "finished") return t("exams.finished"); if (status === "upcoming") return t("exams.upcoming"); return t("exams.active"); }; + const statusTone = (status: ExamStatus) => status === "expired" ? "finished" : status; - const rows = () => filterExams(list() ?? []); - const columns = createMemo[]>(() => [ + const rows = (): ExamRow[] => filterExams(list() ?? []).map((exam) => ({ ...exam, displayStatus: examStatus(exam) })); + createEffect(() => { + if (!isStudent()) return; + const exams = list(); + if (!exams) return; + const allowed = new Set(visibleCourses().map((course) => course.id)); + const refresh = () => { + for (const exam of exams) { + if (!allowed.has(exam.course) || !isSittable(exam)) continue; + const current = attemptStatuses()[exam.id]; + if (current === "submitted" || current === "expired") continue; + if (current != null && current !== "in_progress") continue; + void getExamAttempt(exam.id) + .then((attempt) => { + setAttemptStatuses((prev) => ({ ...prev, [exam.id]: attempt.status })); + }) + .catch(() => { + setAttemptStatuses((prev) => ({ ...prev, [exam.id]: "not_started" })); + }); + } + }; + refresh(); + const interval = window.setInterval(refresh, 5000); + onCleanup(() => window.clearInterval(interval)); + }); + const columns = createMemo[]>(() => [ { accessorKey: "title", header: t("exams.title"), @@ -149,14 +182,14 @@ function ExamsContent() { }, { id: "status", - accessorFn: (exam) => statusLabel(examStatus(exam)), + accessorFn: (exam) => statusLabel(exam.displayStatus), header: t("attempt.status"), meta: { headerClass: "text-center", cellClass: "text-center" }, cell: (cell) => { - const status = examStatus(cell.row.original); + const status = cell.row.original.displayStatus; return ( - - + + {statusLabel(status)} ); @@ -251,6 +284,8 @@ function ExamsContent() { <>