forge
Explore
Log in

Don't you dare go Hollow

✨ exam room full screen, attempts display, and fresh data

Browse files at this commit

bcc0f698a063400de24aee7bb8bfee2ed17df48dBurak BoduroğluParent: 6452b17
  • feat
    • ✨ exam room full screen, attempts display, and fresh data
Show full message
feat: ✨ exam room full screen, attempts display, and fresh data
- update AppShell to hide sidebars and top header for /exam-room
- keep max-width reset so questions take up more screen space
- display used and remaining attempt counts on the exam detail page
- add `cache` option to API client `RequestOptions`
- bypass browser cache (`no-store`) for exam, attempt, and time endpoints to ensure fresh status and precise clock sync without stale data
- add exam start date, end date, and duration to the detail metric cards grid
- show contextual alert for submitted exams (prompt to retake using remaining attempts)
- display attempt submission timestamp in the alert box
src/api/client/client.tsmodified+2 -0
@@ -16,6 +16,7 @@ type RequestOptions = {
16 method?: "GET" | "POST" | "PATCH" | "DELETE";16 method?: "GET" | "POST" | "PATCH" | "DELETE";
17 body?: unknown;17 body?: unknown;
18 signal?: AbortSignal;18 signal?: AbortSignal;
19+ cache?: RequestCache;
19 };20 };
20 21
21 const API_PREFIX = "/api";22 const API_PREFIX = "/api";
@@ -132,6 +133,7 @@ export async function client<T>(path: string, options: RequestOptions = {}): Pro
132 body,133 body,
133 credentials: "same-origin",134 credentials: "same-origin",
134 signal: options.signal,135 signal: options.signal,
136+ cache: options.cache,
135 });137 });
136 138
137 if (res.status === 204) {139 if (res.status === 204) {
src/api/exams/getExamAttempt.tsmodified+1 -1
@@ -2,5 +2,5 @@ import { client } from "../client";
2 import type { ExamAttempt } from "../client";2 import type { ExamAttempt } from "../client";
3 3
4 export function getExamAttempt(examId: string, signal?: AbortSignal): Promise<ExamAttempt> {4 export function getExamAttempt(examId: string, signal?: AbortSignal): Promise<ExamAttempt> {
5- return client<ExamAttempt>(`/exams/${examId}/attempt`, { signal });5+ return client<ExamAttempt>(`/exams/${examId}/attempt`, { signal, cache: "no-store" });
6 }6 }
src/api/exams/getExamById.tsmodified+1 -1
@@ -2,5 +2,5 @@ import { client } from "../client";
2 import type { Exam } from "../client";2 import type { Exam } from "../client";
3 3
4 export function getExamById(id: string, signal?: AbortSignal): Promise<Exam> {4 export function getExamById(id: string, signal?: AbortSignal): Promise<Exam> {
5- return client<Exam>(`/exams/${id}`, { signal });5+ return client<Exam>(`/exams/${id}`, { signal, cache: "no-store" });
6 }6 }
src/api/time/getTime.tsmodified+1 -1
@@ -1,5 +1,5 @@
1 import { client } from "@/api/client";1 import { client } from "@/api/client";
2 2
3 export async function getTime(signal?: AbortSignal): Promise<{ now: number }> {3 export async function getTime(signal?: AbortSignal): Promise<{ now: number }> {
4- return client<{ now: number }>("/time", { signal });4+ return client<{ now: number }>("/time", { signal, cache: "no-store" });
5 }5 }
src/components/layout/app-shell.tsxmodified+3 -2
@@ -26,6 +26,7 @@ export function AppShell(props: ParentProps) {
26 const collapsed = () => prefs.sidebarCollapsed();26 const collapsed = () => prefs.sidebarCollapsed();
27 const location = useLocation();27 const location = useLocation();
28 const wide = () => location().pathname.startsWith("/exam-room/") || location().searchStr.includes("answerUser=") || location().pathname === "/messages";28 const wide = () => location().pathname.startsWith("/exam-room/") || location().searchStr.includes("answerUser=") || location().pathname === "/messages";
29+ const fullScreen = () => location().pathname.startsWith("/exam-room/");
29 const routeLabel = createMemo(() => {30 const routeLabel = createMemo(() => {
30 const path = location().pathname;31 const path = location().pathname;
31 if (path === "/") return t("nav.home");32 if (path === "/") return t("nav.home");
@@ -63,7 +64,7 @@ export function AppShell(props: ParentProps) {
63 <NavBar />64 <NavBar />
64 </Show>65 </Show>
65 <div class="flex w-full">66 <div class="flex w-full">
66- <Show when={auth.user()}>67+ <Show when={auth.user() && !fullScreen()}>
67 <aside68 <aside
68 class={cn(69 class={cn(
69 "sticky top-0 z-30 hidden h-screen shrink-0 border-r border-border/80 bg-sidebar shadow-[inset_-1px_0_0_hsl(var(--border)/0.45)] transition-[width] duration-150 ease-out lg:flex lg:flex-col",70 "sticky top-0 z-30 hidden h-screen shrink-0 border-r border-border/80 bg-sidebar shadow-[inset_-1px_0_0_hsl(var(--border)/0.45)] transition-[width] duration-150 ease-out lg:flex lg:flex-col",
@@ -143,7 +144,7 @@ export function AppShell(props: ParentProps) {
143 </Show>144 </Show>
144 145
145 <main class="min-w-0 flex-1">146 <main class="min-w-0 flex-1">
146- <Show when={auth.user()}>147+ <Show when={auth.user() && !fullScreen()}>
147 <header class="sticky top-0 z-20 flex h-14 items-center justify-between gap-3 border-b border-border/70 bg-background/95 px-4 backdrop-blur sm:px-6 lg:px-8">148 <header class="sticky top-0 z-20 flex h-14 items-center justify-between gap-3 border-b border-border/70 bg-background/95 px-4 backdrop-blur sm:px-6 lg:px-8">
148 <div class="min-w-0 rounded-lg border bg-card px-3 py-1.5 text-xs font-medium text-muted-foreground shadow-sm">149 <div class="min-w-0 rounded-lg border bg-card px-3 py-1.5 text-xs font-medium text-muted-foreground shadow-sm">
149 <span class="block truncate">{routeLabel()}</span>150 <span class="block truncate">{routeLabel()}</span>
src/i18n/messages.tsmodified+18 -3
@@ -315,6 +315,7 @@ export type MessageKey =
315 | "exams.durationRange"315 | "exams.durationRange"
316 | "exams.maxAttempts"316 | "exams.maxAttempts"
317 | "exams.maxAttemptsRange"317 | "exams.maxAttemptsRange"
318+ | "exams.attemptsLeft"
318 | "exams.retakes"319 | "exams.retakes"
319 | "exams.allowRejoin"320 | "exams.allowRejoin"
320 | "exams.allowRejoinHelp"321 | "exams.allowRejoinHelp"
@@ -390,7 +391,11 @@ export type MessageKey =
390 | "attempt.mark"391 | "attempt.mark"
391 | "attempt.saveAnswer"392 | "attempt.saveAnswer"
392 | "attempt.submitted"393 | "attempt.submitted"
393- | "attempt.submittedInfo"394+ | "attempt.submittedCanRetakeInfo"
395+ | "attempt.submittedFinalInfo"
396+ | "attempt.submittedAt"
397+ | "exams.startsAt"
398+ | "exams.endsAt"
394 | "attempt.expired"399 | "attempt.expired"
395 | "attempt.expiredInfo"400 | "attempt.expiredInfo"
396 | "attempt.noAttemptsLeft"401 | "attempt.noAttemptsLeft"
@@ -967,6 +972,7 @@ const en: Dict = {
967 "exams.durationRange": "Duration must be from 1 minute to 24 hours",972 "exams.durationRange": "Duration must be from 1 minute to 24 hours",
968 "exams.maxAttempts": "Max attempts",973 "exams.maxAttempts": "Max attempts",
969 "exams.maxAttemptsRange": "Max attempts must be 1 or higher",974 "exams.maxAttemptsRange": "Max attempts must be 1 or higher",
975+ "exams.attemptsLeft": "Remaining",
970 "exams.retakes": "Retakes",976 "exams.retakes": "Retakes",
971 "exams.allowRejoin": "Allow rejoin",977 "exams.allowRejoin": "Allow rejoin",
972 "exams.allowRejoinHelp": "If off, a student who leaves the exam room cannot return to answer.",978 "exams.allowRejoinHelp": "If off, a student who leaves the exam room cannot return to answer.",
@@ -1042,7 +1048,11 @@ const en: Dict = {
1042 "attempt.mark": "Mark",1048 "attempt.mark": "Mark",
1043 "attempt.saveAnswer": "Save answer",1049 "attempt.saveAnswer": "Save answer",
1044 "attempt.submitted": "Submitted",1050 "attempt.submitted": "Submitted",
1045- "attempt.submittedInfo": "You have already submitted this exam. It cannot be reopened.",1051+ "attempt.submittedCanRetakeInfo": "You have submitted this attempt. You can take the exam again using your remaining attempts.",
1052+ "attempt.submittedFinalInfo": "You have submitted this exam. It cannot be reopened.",
1053+ "attempt.submittedAt": "Submitted At",
1054+ "exams.startsAt": "Start Date",
1055+ "exams.endsAt": "End Date",
1046 "attempt.expired": "Expired",1056 "attempt.expired": "Expired",
1047 "attempt.expiredInfo": "The time for this exam has expired. It cannot be reopened.",1057 "attempt.expiredInfo": "The time for this exam has expired. It cannot be reopened.",
1048 "attempt.noAttemptsLeft": "No rights left",1058 "attempt.noAttemptsLeft": "No rights left",
@@ -1629,6 +1639,7 @@ const tr: Dict = {
1629 "exams.durationRange": "Süre 1 dakika ile 24 saat arasında olmalı",1639 "exams.durationRange": "Süre 1 dakika ile 24 saat arasında olmalı",
1630 "exams.maxAttempts": "Deneme hakkı",1640 "exams.maxAttempts": "Deneme hakkı",
1631 "exams.maxAttemptsRange": "Deneme hakkı 1 veya daha büyük olmalı",1641 "exams.maxAttemptsRange": "Deneme hakkı 1 veya daha büyük olmalı",
1642+ "exams.attemptsLeft": "Kalan",
1632 "exams.retakes": "Deneme hakkı",1643 "exams.retakes": "Deneme hakkı",
1633 "exams.allowRejoin": "Yeniden girişe izin ver",1644 "exams.allowRejoin": "Yeniden girişe izin ver",
1634 "exams.allowRejoinHelp": "Kapalıysa sınav odasından çıkan öğrenci cevap vermek için geri giremez.",1645 "exams.allowRejoinHelp": "Kapalıysa sınav odasından çıkan öğrenci cevap vermek için geri giremez.",
@@ -1704,7 +1715,11 @@ const tr: Dict = {
1704 "attempt.mark": "Not",1715 "attempt.mark": "Not",
1705 "attempt.saveAnswer": "Cevabı kaydet",1716 "attempt.saveAnswer": "Cevabı kaydet",
1706 "attempt.submitted": "Teslim edildi",1717 "attempt.submitted": "Teslim edildi",
1707- "attempt.submittedInfo": "Bu sınavı zaten teslim ettin. Yeniden açılamaz.",1718+ "attempt.submittedCanRetakeInfo": "Bu denemenizi teslim ettiniz. Kalan haklarınızı kullanarak sınava tekrardan başlayabilirsiniz.",
1719+ "attempt.submittedFinalInfo": "Bu sınavı zaten teslim ettin. Yeniden açılamaz.",
1720+ "attempt.submittedAt": "Teslim Tarihi",
1721+ "exams.startsAt": "Başlangıç Tarihi",
1722+ "exams.endsAt": "Bitiş Tarihi",
1708 "attempt.expired": "Süresi doldu",1723 "attempt.expired": "Süresi doldu",
1709 "attempt.expiredInfo": "Bu sınavın süresi doldu. Yeniden açılamaz.",1724 "attempt.expiredInfo": "Bu sınavın süresi doldu. Yeniden açılamaz.",
1710 "attempt.noAttemptsLeft": "Hak bitti",1725 "attempt.noAttemptsLeft": "Hak bitti",
src/lib/exam-status.tsmodified+7 -2
@@ -13,8 +13,13 @@ export function isSittableExam(exam: Exam): boolean {
13 }13 }
14 14
15 export function examDisplayStatus(exam: Exam, now: number, attempt?: ExamAttemptSummary | null): ExamDisplayStatus {15 export function examDisplayStatus(exam: Exam, now: number, attempt?: ExamAttemptSummary | null): ExamDisplayStatus {
16- if (attempt?.status === "submitted" || attempt?.status === "expired") return attempt.status;16+ const noAttemptsLeft = attempt && attempt.status !== "in_progress" && attempt.max_attempts > 0 && attempt.attempts_used >= attempt.max_attempts;
17- if (attempt && attempt.status !== "in_progress" && attempt.max_attempts > 0 && attempt.attempts_used >= attempt.max_attempts) return "no_attempts_left";17+
18+ if (noAttemptsLeft) {
19+ if (attempt.status === "submitted" || attempt.status === "expired") return attempt.status;
20+ return "no_attempts_left";
21+ }
22+
18 if (exam.draft) return "draft";23 if (exam.draft) return "draft";
19 if (!isSittableExam(exam)) return "unscheduled";24 if (!isSittableExam(exam)) return "unscheduled";
20 if (exam.mode === "open") return "active";25 if (exam.mode === "open") return "active";
src/pages/exam-detail-page.tsxmodified+40 -4
@@ -367,12 +367,12 @@ function ExamDetailContent() {
367 </Link>367 </Link>
368 <Show when={isStudent() && !isDraft() && isSittable()}>368 <Show when={isStudent() && !isDraft() && isSittable()}>
369 <Show when={!isUpcoming() && !isFinished()}>369 <Show when={!isUpcoming() && !isFinished()}>
370- <Show when={ownAttempt()?.status === "submitted" || ownAttempt()?.status === "expired" || noAttemptsLeft()}370+ <Show when={noAttemptsLeft()}
371 fallback={371 fallback={
372 <Link to="/exam-room/$id" params={{ id: id() }}>372 <Link to="/exam-room/$id" params={{ id: id() }}>
373 <Button size="sm" class="flex-1 rounded-sm sm:flex-none">373 <Button size="sm" class="flex-1 rounded-sm sm:flex-none">
374 <IconExam class="h-4 w-4" />374 <IconExam class="h-4 w-4" />
375- {ownAttempt() ? t("attempt.resume") : t("attempt.openRoom")}375+ {ownAttempt()?.status === "in_progress" ? t("attempt.resume") : t("attempt.openRoom")}
376 </Button>376 </Button>
377 </Link>377 </Link>
378 }378 }
@@ -430,8 +430,35 @@ function ExamDetailContent() {
430 </div>430 </div>
431 <div class="detail-metric-card">431 <div class="detail-metric-card">
432 <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.maxAttempts")}</p>432 <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.maxAttempts")}</p>
433- <p class="mono mt-1 font-medium tabular-nums">{ex().max_attempts}</p>433+ <p class="mono mt-1 font-medium tabular-nums">
434+ <Show when={isStudent()} fallback={ex().max_attempts}>
435+ {ownAttemptSummary() ? `${ownAttemptSummary()!.attempts_used} / ${ex().max_attempts}` : `0 / ${ex().max_attempts}`}
436+ <span class="ml-1.5 text-xs text-muted-foreground font-sans tracking-normal">
437+ ({t("exams.attemptsLeft")}: {ex().max_attempts - (ownAttemptSummary()?.attempts_used ?? 0)})
438+ </span>
439+ </Show>
440+ </p>
434 </div>441 </div>
442+ <Show when={ex().starts_at}>
443+ <div class="detail-metric-card">
444+ <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.startsAt")}</p>
445+ <p class="mono mt-1 font-medium tabular-nums">{formatDateTime(ex().starts_at, locale())}</p>
446+ </div>
447+ </Show>
448+ <Show when={ex().ends_at}>
449+ <div class="detail-metric-card">
450+ <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.endsAt")}</p>
451+ <p class="mono mt-1 font-medium tabular-nums">{formatDateTime(ex().ends_at, locale())}</p>
452+ </div>
453+ </Show>
454+ <Show when={examDurationMs(ex().duration_ms, ex().starts_at, ex().ends_at)}>
455+ {(dur) => (
456+ <div class="detail-metric-card">
457+ <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.durationMinutes")}</p>
458+ <p class="mono mt-1 font-medium tabular-nums">{formatDurationMinutes(dur(), locale())}</p>
459+ </div>
460+ )}
461+ </Show>
435 </div>462 </div>
436 </div>463 </div>
437 464
@@ -553,7 +580,16 @@ function ExamDetailContent() {
553 580
554 <Show when={isStudent() && ownAttempt()?.status && (ownAttempt()!.status === "submitted" || ownAttempt()!.status === "expired")}>581 <Show when={isStudent() && ownAttempt()?.status && (ownAttempt()!.status === "submitted" || ownAttempt()!.status === "expired")}>
555 <Alert variant={ownAttempt()!.status === "submitted" ? "default" : "destructive"} class="border">582 <Alert variant={ownAttempt()!.status === "submitted" ? "default" : "destructive"} class="border">
556- <p class="text-sm font-medium">{ownAttempt()!.status === "submitted" ? t("attempt.submittedInfo") : t("attempt.expiredInfo")}</p>583+ <p class="text-sm font-medium">
584+ {ownAttempt()!.status === "submitted"
585+ ? (noAttemptsLeft() ? t("attempt.submittedFinalInfo") : t("attempt.submittedCanRetakeInfo"))
586+ : t("attempt.expiredInfo")}
587+ </p>
588+ <Show when={ownAttempt()?.finished_at}>
589+ <p class="text-sm mt-1 opacity-80">
590+ {t("attempt.submittedAt")}: {formatDateTime(ownAttempt()!.finished_at, locale())}
591+ </p>
592+ </Show>
557 </Alert>593 </Alert>
558 </Show>594 </Show>
559 595