forge
Explore
Log in

Don't you dare go Hollow

✨ polish course and exam UX

Browse files at this commit

8d5749eaa64c4741c745c2874376fb157cfb6c4aBurak BoduroğluParent: 7101da6
  • feat
    • ✨ polish course and exam UX
Show full message
feat: ✨ polish course and exam UX

- add course detail summary cards for exams, roster, and total weight

- make course exam and roster lists easier to scan with clearer empty states

- clarify unscheduled exam status and keep schedule time as a compact badge

- improve exam room progress, remaining-time, WebSocket, and saved-answer indicators

- improve live monitor roster status, progress, remaining-time, and error display

- localize known backend exam errors and sentence-case fallback messages

- remove duplicated no-students text from the grading form
src/api/client.tsmodified+49 -5
@@ -1,3 +1,5 @@
1+import type { Locale } from "@/i18n/messages";
2+
1 export class ApiError extends Error {3 export class ApiError extends Error {
2 readonly status: number;4 readonly status: number;
3 readonly retryAfter: number | null;5 readonly retryAfter: number | null;
@@ -18,6 +20,44 @@ type RequestOptions = {
18 20
19 const API_PREFIX = "/api";21 const API_PREFIX = "/api";
20 22
23+const API_ERROR_MESSAGES: Record<string, Record<Locale, string>> = {
24+ "not enrolled in this exam's course": {
25+ en: "You are not enrolled in this exam's course.",
26+ tr: "Bu sınavın dersine kayıtlı değilsin.",
27+ },
28+ "you are not enrolled in this exam's course": {
29+ en: "You are not enrolled in this exam's course.",
30+ tr: "Bu sınavın dersine kayıtlı değilsin.",
31+ },
32+ "exam is not scheduled": {
33+ en: "This exam is not scheduled for online sitting.",
34+ tr: "Bu sınav çevrim içi oturum için zamanlanmamış.",
35+ },
36+ "attempt not found": {
37+ en: "Start the exam before opening the exam room.",
38+ tr: "Sınav odasını açmadan önce sınavı başlat.",
39+ },
40+ "attempt is closed": {
41+ en: "This attempt is closed. Answers are read-only.",
42+ tr: "Bu oturum kapalı. Cevaplar salt okunur.",
43+ },
44+};
45+
46+function normalizeApiMessage(message: string): string {
47+ return message
48+ .trim()
49+ .replace(/[’‘]/g, "'")
50+ .replace(/\s+/g, " ")
51+ .replace(/[.!?]+$/, "")
52+ .toLowerCase();
53+}
54+
55+function sentenceCase(message: string): string {
56+ const trimmed = message.trim();
57+ if (!trimmed) return trimmed;
58+ return trimmed[0].toLocaleUpperCase("en-US") + trimmed.slice(1);
59+}
60+
21 export async function client<T>(path: string, options: RequestOptions = {}): Promise<T> {61 export async function client<T>(path: string, options: RequestOptions = {}): Promise<T> {
22 const headers: Record<string, string> = {};62 const headers: Record<string, string> = {};
23 let body: string | undefined;63 let body: string | undefined;
@@ -70,13 +110,17 @@ export async function client<T>(path: string, options: RequestOptions = {}): Pro
70 return data as T;110 return data as T;
71 }111 }
72 112
73-export function formatApiError(err: unknown): string {113+export function formatApiErrorMessage(message: string, locale: Locale = "en"): string {
114+ return API_ERROR_MESSAGES[normalizeApiMessage(message)]?.[locale] ?? sentenceCase(message);
115+}
116+
117+export function formatApiError(err: unknown, locale: Locale = "en"): string {
74 if (err instanceof ApiError) {118 if (err instanceof ApiError) {
75 if (err.status === 429 && err.retryAfter != null) {119 if (err.status === 429 && err.retryAfter != null) {
76- return `Try again in ${err.retryAfter}s`;120+ return locale === "tr" ? `${err.retryAfter} sn sonra tekrar dene.` : `Try again in ${err.retryAfter}s.`;
77 }121 }
78- return err.message;122+ return formatApiErrorMessage(err.message, locale);
79 }123 }
80- if (err instanceof Error) return err.message;124+ if (err instanceof Error) return formatApiErrorMessage(err.message, locale);
81- return "Something went wrong";125+ return locale === "tr" ? "Bir şeyler ters gitti." : "Something went wrong.";
82 }126 }
src/components/exams/exam-card.tsxmodified+13 -7
@@ -17,6 +17,7 @@ export function ExamCard(props: { exam: Exam; courseTitle?: string; now?: number
17 };17 };
18 18
19 const status = () => {19 const status = () => {
20+ if (props.exam.mode !== "sync" && props.exam.mode !== "async") return "unscheduled";
20 const current = props.now ?? Date.now();21 const current = props.now ?? Date.now();
21 if (props.exam.ends_at != null && props.exam.ends_at < current) return "finished";22 if (props.exam.ends_at != null && props.exam.ends_at < current) return "finished";
22 if (props.exam.starts_at != null && props.exam.starts_at > current) return "upcoming";23 if (props.exam.starts_at != null && props.exam.starts_at > current) return "upcoming";
@@ -25,6 +26,7 @@ export function ExamCard(props: { exam: Exam; courseTitle?: string; now?: number
25 26
26 const statusLabel = () => {27 const statusLabel = () => {
27 const s = status();28 const s = status();
29+ if (s === "unscheduled") return t("exams.unscheduled");
28 if (s === "finished") return t("exams.finished");30 if (s === "finished") return t("exams.finished");
29 if (s === "upcoming") return t("exams.upcoming");31 if (s === "upcoming") return t("exams.upcoming");
30 return t("exams.active");32 return t("exams.active");
@@ -32,6 +34,7 @@ export function ExamCard(props: { exam: Exam; courseTitle?: string; now?: number
32 34
33 const statusClass = () => {35 const statusClass = () => {
34 const s = status();36 const s = status();
37+ if (s === "unscheduled") return "bg-muted text-muted-foreground border-muted";
35 if (s === "finished") return "bg-muted text-muted-foreground border-muted";38 if (s === "finished") return "bg-muted text-muted-foreground border-muted";
36 if (s === "upcoming") return "bg-amber-500/15 text-amber-600 border-amber-500/30";39 if (s === "upcoming") return "bg-amber-500/15 text-amber-600 border-amber-500/30";
37 return "bg-emerald-500/15 text-emerald-600 border-emerald-500/30";40 return "bg-emerald-500/15 text-emerald-600 border-emerald-500/30";
@@ -39,6 +42,7 @@ export function ExamCard(props: { exam: Exam; courseTitle?: string; now?: number
39 42
40 const statusDot = () => {43 const statusDot = () => {
41 const s = status();44 const s = status();
45+ if (s === "unscheduled") return "bg-muted-foreground";
42 if (s === "finished") return "bg-muted-foreground";46 if (s === "finished") return "bg-muted-foreground";
43 if (s === "upcoming") return "bg-amber-600";47 if (s === "upcoming") return "bg-amber-600";
44 return "bg-emerald-600";48 return "bg-emerald-600";
@@ -71,13 +75,15 @@ export function ExamCard(props: { exam: Exam; courseTitle?: string; now?: number
71 {props.exam.description || "—"}75 {props.exam.description || "—"}
72 </p>76 </p>
73 <dl class="mt-4 grid gap-2 text-xs text-muted-foreground">77 <dl class="mt-4 grid gap-2 text-xs text-muted-foreground">
74- <div class="flex justify-between gap-3">78+ <div class="flex flex-wrap gap-2">
75- <dt>{t("exams.mode")}</dt>79+ <Badge variant="outline" class="rounded-full">
76- <dd class="font-medium text-foreground">{modeLabel()}</dd>80+ {modeLabel()}
77- </div>81+ </Badge>
78- <div class="flex justify-between gap-3">82+ <Show when={props.exam.starts_at != null && props.exam.ends_at != null}>
79- <dt>{t("exams.window")}</dt>83+ <Badge variant="outline" class="rounded-full">
80- <dd class="text-right">{formatDateTime(props.exam.starts_at, locale())} → {formatDateTime(props.exam.ends_at, locale())}</dd>84+ {formatDateTime(props.exam.starts_at, locale())} → {formatDateTime(props.exam.ends_at, locale())}
85+ </Badge>
86+ </Show>
81 </div>87 </div>
82 {(props.exam.mode === "sync" || props.exam.mode === "async") && (88 {(props.exam.mode === "sync" || props.exam.mode === "async") && (
83 <div class="flex justify-between gap-3">89 <div class="flex justify-between gap-3">
src/components/exams/exam-room-ws.tsxmodified+42 -21
@@ -4,7 +4,7 @@ import { getExamAttemptQuestions } from "@/api/getExamAttemptQuestions";
4 import { postExamAttempt } from "@/api/postExamAttempt";4 import { postExamAttempt } from "@/api/postExamAttempt";
5 import { postExamAttemptAnswer } from "@/api/postExamAttemptAnswer";5 import { postExamAttemptAnswer } from "@/api/postExamAttemptAnswer";
6 import { postExamAttemptFinish } from "@/api/postExamAttemptFinish";6 import { postExamAttemptFinish } from "@/api/postExamAttemptFinish";
7-import { formatApiError } from "@/api/client";7+import { formatApiError, formatApiErrorMessage } from "@/api/client";
8 import type { AttemptQuestion, Exam, ExamAttempt } from "@/api/types";8 import type { AttemptQuestion, Exam, ExamAttempt } from "@/api/types";
9 import { Badge } from "@/components/ui/badge";9 import { Badge } from "@/components/ui/badge";
10 import { Button } from "@/components/ui/button";10 import { Button } from "@/components/ui/button";
@@ -34,6 +34,7 @@ function formatRemaining(ms: number): string {
34 34
35 export function ExamRoomWS(props: { exam: Exam }) {35 export function ExamRoomWS(props: { exam: Exam }) {
36 const t = useT();36 const t = useT();
37+ const { locale } = usePreferences();
37 const [error, setError] = createSignal("");38 const [error, setError] = createSignal("");
38 const [pending, setPending] = createSignal(false);39 const [pending, setPending] = createSignal(false);
39 const [finishOpen, setFinishOpen] = createSignal(false);40 const [finishOpen, setFinishOpen] = createSignal(false);
@@ -123,7 +124,7 @@ export function ExamRoomWS(props: { exam: Exam }) {
123 break;124 break;
124 }125 }
125 case "error": {126 case "error": {
126- setError(msg.message);127+ setError(formatApiErrorMessage(msg.message, locale()));
127 break;128 break;
128 }129 }
129 }130 }
@@ -146,7 +147,7 @@ export function ExamRoomWS(props: { exam: Exam }) {
146 setQuestions(qs);147 setQuestions(qs);
147 connectWs();148 connectWs();
148 } catch (err) {149 } catch (err) {
149- setError(formatApiError(err));150+ setError(formatApiError(err, locale()));
150 } finally {151 } finally {
151 setPending(false);152 setPending(false);
152 }153 }
@@ -161,7 +162,7 @@ export function ExamRoomWS(props: { exam: Exam }) {
161 setQuestions(qs);162 setQuestions(qs);
162 connectWs();163 connectWs();
163 } catch (err) {164 } catch (err) {
164- setError(formatApiError(err));165+ setError(formatApiError(err, locale()));
165 }166 }
166 };167 };
167 168
@@ -191,7 +192,7 @@ export function ExamRoomWS(props: { exam: Exam }) {
191 const qs = await getExamAttemptQuestions(props.exam.id);192 const qs = await getExamAttemptQuestions(props.exam.id);
192 setQuestions(qs);193 setQuestions(qs);
193 } catch (err) {194 } catch (err) {
194- setError(formatApiError(err));195+ setError(formatApiError(err, locale()));
195 } finally {196 } finally {
196 setPending(false);197 setPending(false);
197 }198 }
@@ -210,7 +211,7 @@ export function ExamRoomWS(props: { exam: Exam }) {
210 setAttempt(next);211 setAttempt(next);
211 }212 }
212 } catch (err) {213 } catch (err) {
213- setError(formatApiError(err));214+ setError(formatApiError(err, locale()));
214 } finally {215 } finally {
215 setPending(false);216 setPending(false);
216 }217 }
@@ -286,13 +287,22 @@ export function ExamRoomWS(props: { exam: Exam }) {
286 </For>287 </For>
287 </div>288 </div>
288 <aside class="surface-card sticky top-4 space-y-3 p-4">289 <aside class="surface-card sticky top-4 space-y-3 p-4">
289- <h3 class="font-display text-sm font-semibold">{t("questions.title")}</h3>290+ <div>
291+ <h3 class="font-display text-sm font-semibold">{t("questions.title")}</h3>
292+ <p class="mt-1 text-xs text-muted-foreground">
293+ {attempt()?.answered ?? 0} / {attempt()?.question_count ?? questions().length} {t("attempt.progress").toLowerCase()}
294+ </p>
295+ </div>
290 <div class="grid grid-cols-4 gap-2">296 <div class="grid grid-cols-4 gap-2">
291 <For each={questions()}>297 <For each={questions()}>
292 {(question, index) => (298 {(question, index) => (
293 <a299 <a
294 href={`#question-${question.id}`}300 href={`#question-${question.id}`}
295- class="inline-flex h-9 items-center justify-center rounded-sm border bg-background text-sm font-medium hover:bg-accent"301+ class={
302+ question.answer
303+ ? "inline-flex h-9 items-center justify-center rounded-lg border border-primary/35 bg-primary/10 text-sm font-medium text-primary hover:bg-primary/15"
304+ : "inline-flex h-9 items-center justify-center rounded-lg border bg-background text-sm font-medium hover:bg-accent"
305+ }
296 >306 >
297 {index() + 1}307 {index() + 1}
298 </a>308 </a>
@@ -323,6 +333,11 @@ export function ExamRoomWS(props: { exam: Exam }) {
323 function AttemptSummaryWS(props: { attempt: ExamAttempt; remainingMs: number; wsState: WsState }) {333 function AttemptSummaryWS(props: { attempt: ExamAttempt; remainingMs: number; wsState: WsState }) {
324 const t = useT();334 const t = useT();
325 const { locale } = usePreferences();335 const { locale } = usePreferences();
336+ const progressPct = () =>
337+ props.attempt.question_count <= 0
338+ ? 0
339+ : Math.round((props.attempt.answered / props.attempt.question_count) * 100);
340+ const remainingWarn = () => props.attempt.status === "in_progress" && props.remainingMs <= 5 * 60 * 1000;
326 const statusLabel = () => {341 const statusLabel = () => {
327 if (props.attempt.status === "in_progress") return t("attempt.inProgress");342 if (props.attempt.status === "in_progress") return t("attempt.inProgress");
328 if (props.attempt.status === "submitted") return t("attempt.submitted");343 if (props.attempt.status === "submitted") return t("attempt.submitted");
@@ -336,32 +351,38 @@ function AttemptSummaryWS(props: { attempt: ExamAttempt; remainingMs: number; ws
336 };351 };
337 return (352 return (
338 <div class="grid auto-rows-fr gap-3 text-sm sm:grid-cols-2 xl:grid-cols-6">353 <div class="grid auto-rows-fr gap-3 text-sm sm:grid-cols-2 xl:grid-cols-6">
339- <div class="h-full rounded-md border bg-background/60 p-3">354+ <div class="h-full rounded-lg border bg-background/60 p-3">
340 <p class="text-xs text-muted-foreground">{t("attempt.status")}</p>355 <p class="text-xs text-muted-foreground">{t("attempt.status")}</p>
341 <p class="mt-1 font-medium">{statusLabel()}</p>356 <p class="mt-1 font-medium">{statusLabel()}</p>
342 </div>357 </div>
343- <div class="h-full rounded-md border bg-background/60 p-3">358+ <div class={remainingWarn() ? "h-full rounded-lg border border-amber-500/40 bg-amber-500/10 p-3" : "h-full rounded-lg border bg-background/60 p-3"}>
344 <p class="text-xs text-muted-foreground">{t("attempt.remaining")}</p>359 <p class="text-xs text-muted-foreground">{t("attempt.remaining")}</p>
345- <p class="mt-1 font-mono font-medium">{formatRemaining(props.remainingMs)}</p>360+ <p class="mt-1 font-mono text-lg font-semibold tabular-nums">{formatRemaining(props.remainingMs)}</p>
346 </div>361 </div>
347- <div class="h-full rounded-md border bg-background/60 p-3">362+ <div class="h-full rounded-lg border bg-background/60 p-3">
348 <p class="text-xs text-muted-foreground">{t("attempt.progress")}</p>363 <p class="text-xs text-muted-foreground">{t("attempt.progress")}</p>
349 <p class="mt-1 font-medium">{props.attempt.answered} / {props.attempt.question_count}</p>364 <p class="mt-1 font-medium">{props.attempt.answered} / {props.attempt.question_count}</p>
365+ <div class="mt-2 h-1.5 overflow-hidden rounded-full bg-muted">
366+ <div class="h-full rounded-full bg-primary" style={{ width: `${progressPct()}%` }} />
367+ </div>
350 </div>368 </div>
351- <div class="h-full rounded-md border bg-background/60 p-3">369+ <div class="h-full rounded-lg border bg-background/60 p-3">
352 <p class="text-xs text-muted-foreground">{t("attempt.deadline")}</p>370 <p class="text-xs text-muted-foreground">{t("attempt.deadline")}</p>
353 <p class="mt-1 font-medium">{formatDateTime(props.attempt.deadline, locale())}</p>371 <p class="mt-1 font-medium">{formatDateTime(props.attempt.deadline, locale())}</p>
354 </div>372 </div>
355- <div class="h-full rounded-md border bg-background/60 p-3">373+ <div class="h-full rounded-lg border bg-background/60 p-3">
356 <p class="text-xs text-muted-foreground">{t("attempt.serverNow")}</p>374 <p class="text-xs text-muted-foreground">{t("attempt.serverNow")}</p>
357 <p class="mt-1 font-medium">{formatDateTime(props.attempt.now, locale())}</p>375 <p class="mt-1 font-medium">{formatDateTime(props.attempt.now, locale())}</p>
358 </div>376 </div>
359- <div class="h-full rounded-md border bg-background/60 p-3">377+ <div class="h-full rounded-lg border bg-background/60 p-3">
360 <p class="text-xs text-muted-foreground">{t("ws.ping")}</p>378 <p class="text-xs text-muted-foreground">{t("ws.ping")}</p>
361- <p class="mt-1 font-medium">{wsLabel()}</p>379+ <p class="mt-1 inline-flex items-center gap-2 font-medium">
380+ <span class={props.wsState === "connected" ? "h-2 w-2 rounded-full bg-success" : "h-2 w-2 rounded-full bg-warning"} />
381+ {wsLabel()}
382+ </p>
362 </div>383 </div>
363 <Show when={props.attempt.mark != null}>384 <Show when={props.attempt.mark != null}>
364- <div class="h-full rounded-md border bg-background/60 p-3">385+ <div class="h-full rounded-lg border bg-background/60 p-3">
365 <p class="text-xs text-muted-foreground">{t("attempt.mark")}</p>386 <p class="text-xs text-muted-foreground">{t("attempt.mark")}</p>
366 <p class="mt-1 font-medium">{props.attempt.mark}</p>387 <p class="mt-1 font-medium">{props.attempt.mark}</p>
367 </div>388 </div>
@@ -411,12 +432,12 @@ function QuestionAnswerCardWS(props: {
411 <article id={`question-${props.question.id}`} class="surface-card min-h-[18rem] scroll-mt-24 p-5">432 <article id={`question-${props.question.id}`} class="surface-card min-h-[18rem] scroll-mt-24 p-5">
412 <div class="mb-3 flex flex-wrap items-center gap-2">433 <div class="mb-3 flex flex-wrap items-center gap-2">
413 <span class="text-xs font-semibold text-muted-foreground">#{props.index}</span>434 <span class="text-xs font-semibold text-muted-foreground">#{props.index}</span>
414- <Badge variant="outline">{props.question.points} {t("questions.points")}</Badge>435+ <Badge variant="outline" class="rounded-full">{props.question.points} {t("questions.points")}</Badge>
415 <Show when={saved()}>436 <Show when={saved()}>
416- <Badge variant="outline">{t("attempt.saved")}</Badge>437+ <Badge variant="outline" class="rounded-full">{t("attempt.saved")}</Badge>
417 </Show>438 </Show>
418 <Show when={props.question.answer?.updated_at}>439 <Show when={props.question.answer?.updated_at}>
419- {(updatedAt) => <Badge variant="outline">{t("attempt.savedAt")}: {formatDateTime(updatedAt(), locale())}</Badge>}440+ {(updatedAt) => <Badge variant="outline" class="rounded-full">{t("attempt.savedAt")}: {formatDateTime(updatedAt(), locale())}</Badge>}
420 </Show>441 </Show>
421 </div>442 </div>
422 <p class="mb-4 whitespace-pre-wrap text-sm font-medium">{props.question.text}</p>443 <p class="mb-4 whitespace-pre-wrap text-sm font-medium">{props.question.text}</p>
@@ -440,7 +461,7 @@ function QuestionAnswerCardWS(props: {
440 {(choice, choiceIndex) => (461 {(choice, choiceIndex) => (
441 <button462 <button
442 type="button"463 type="button"
443- class="flex w-full items-center gap-3 rounded-sm border px-3 py-2 text-left text-sm transition-colors hover:bg-accent disabled:cursor-not-allowed disabled:opacity-60"464+ class="flex w-full items-center gap-3 rounded-lg border px-3 py-2 text-left text-sm transition-colors hover:bg-accent disabled:cursor-not-allowed disabled:opacity-60"
444 disabled={props.disabled}465 disabled={props.disabled}
445 onClick={() => {466 onClick={() => {
446 setSaved(false);467 setSaved(false);
src/components/exams/grade-form.tsxmodified+1 -4
@@ -1,4 +1,4 @@
1-import { For, Show, createSignal } from "solid-js";1+import { For, createSignal } from "solid-js";
2 import { formatApiError } from "@/api/client";2 import { formatApiError } from "@/api/client";
3 import { Button } from "@/components/ui/button";3 import { Button } from "@/components/ui/button";
4 import { ConfirmDialog } from "@/components/ui/confirm-dialog";4 import { ConfirmDialog } from "@/components/ui/confirm-dialog";
@@ -81,9 +81,6 @@ export function GradeForm(props: {
81 <IconCheck />81 <IconCheck />
82 {t("exams.gradeStudent")}82 {t("exams.gradeStudent")}
83 </Button>83 </Button>
84- <Show when={props.students.length === 0}>
85- <p class="text-sm text-muted-foreground">{t("form.noStudents")}</p>
86- </Show>
87 {error() && <p class="text-sm text-destructive">{error()}</p>}84 {error() && <p class="text-sm text-destructive">{error()}</p>}
88 </form>85 </form>
89 86
src/pages/course-detail-page.tsxmodified+112 -51
@@ -1,4 +1,4 @@
1-import { For, Show, Suspense, createResource, createSignal } from "solid-js";1+import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js";
2 import { Link, useNavigate, useParams } from "@tanstack/solid-router";2 import { Link, useNavigate, useParams } from "@tanstack/solid-router";
3 import { deleteCourseById } from "@/api/deleteCourseById";3 import { deleteCourseById } from "@/api/deleteCourseById";
4 import { deleteCourseEnrollmentByUserId } from "@/api/deleteCourseEnrollmentByUserId";4 import { deleteCourseEnrollmentByUserId } from "@/api/deleteCourseEnrollmentByUserId";
@@ -83,6 +83,11 @@ function CourseDetailContent() {
83 if (mode === "async") return t("exams.mode.async");83 if (mode === "async") return t("exams.mode.async");
84 return t("exams.unscheduled");84 return t("exams.unscheduled");
85 };85 };
86+
87+ const examCount = createMemo(() => exams()?.length ?? 0);
88+ const rosterCount = createMemo(() => roster()?.length ?? 0);
89+ const totalWeight = createMemo(() => (exams() ?? []).reduce((sum, exam) => sum + exam.weight, 0));
90+
86 const enrollableUsers = () => {91 const enrollableUsers = () => {
87 const enrolled = new Set((roster() ?? []).map((row) => row.user.id));92 const enrolled = new Set((roster() ?? []).map((row) => row.user.id));
88 return (users() ?? []).filter((user) => user.role === "student" && !enrolled.has(user.id));93 return (users() ?? []).filter((user) => user.role === "student" && !enrolled.has(user.id));
@@ -220,6 +225,34 @@ function CourseDetailContent() {
220 <p class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p>225 <p class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p>
221 )}226 )}
222 227
228+ <section class="grid gap-3 sm:grid-cols-3">
229+ <div class="surface-card p-4">
230+ <p class="text-xs font-semibold uppercase tracking-wider text-muted-foreground">
231+ {t("courses.exams")}
232+ </p>
233+ <p class="mt-2 font-display text-3xl font-semibold tabular-nums">{examCount()}</p>
234+ <p class="mt-1 text-xs text-muted-foreground">{t("nav.exams")}</p>
235+ </div>
236+
237+ <Show when={isTeacherPlus()}>
238+ <div class="surface-card p-4">
239+ <p class="text-xs font-semibold uppercase tracking-wider text-muted-foreground">
240+ {t("courses.roster")}
241+ </p>
242+ <p class="mt-2 font-display text-3xl font-semibold tabular-nums">{rosterCount()}</p>
243+ <p class="mt-1 text-xs text-muted-foreground">{t("courses.enroll")}</p>
244+ </div>
245+ </Show>
246+
247+ <div class="surface-card p-4">
248+ <p class="text-xs font-semibold uppercase tracking-wider text-muted-foreground">
249+ {t("courses.weight")}
250+ </p>
251+ <p class="mt-2 font-display text-3xl font-semibold tabular-nums">{totalWeight()}</p>
252+ <p class="mt-1 text-xs text-muted-foreground">{t("marks.subtitle")}</p>
253+ </div>
254+ </section>
255+
223 {/* Course exams */}256 {/* Course exams */}
224 <section class="surface-card space-y-4 p-5">257 <section class="surface-card space-y-4 p-5">
225 <div class="flex flex-wrap items-center justify-between gap-2">258 <div class="flex flex-wrap items-center justify-between gap-2">
@@ -257,7 +290,9 @@ function CourseDetailContent() {
257 <Show290 <Show
258 when={(exams() ?? []).length > 0}291 when={(exams() ?? []).length > 0}
259 fallback={292 fallback={
260- <p class="text-sm text-muted-foreground">{t("exams.empty")}</p>293+ <div class="rounded-lg border border-dashed border-border/80 bg-muted/20 px-4 py-8 text-center text-sm text-muted-foreground">
294+ {t("exams.empty")}
295+ </div>
261 }296 }
262 >297 >
263 <ul class="space-y-2">298 <ul class="space-y-2">
@@ -267,17 +302,27 @@ function CourseDetailContent() {
267 <Link302 <Link
268 to="/exams/$id"303 to="/exams/$id"
269 params={{ id: exam.id }}304 params={{ id: exam.id }}
270- class="flex items-center justify-between gap-3 rounded-md border px-3 py-3 transition-colors hover:border-primary/30 hover:bg-accent/40"305+ class="group flex items-start justify-between gap-3 rounded-lg border border-border/70 bg-background/60 px-4 py-3 transition-all hover:-translate-y-0.5 hover:border-primary/30 hover:bg-accent/35 hover:shadow-sm"
271 >306 >
272- <div class="min-w-0">307+ <div class="min-w-0 space-y-2">
273- <p class="truncate font-medium">{exam.title}</p>308+ <div>
274- <p class="text-xs text-muted-foreground">309+ <p class="truncate font-medium group-hover:text-primary">{exam.title}</p>
275- {t("courses.weight")}: {exam.weight} · {examModeLabel(exam.mode)}310+ </div>
311+ <div class="flex flex-wrap items-center gap-2">
312+ <Badge variant="outline" class="rounded-full capitalize">
313+ {examKindLabel(String(exam.kind), t)}
314+ </Badge>
315+ <Badge variant="secondary" class="rounded-full">
316+ {examModeLabel(exam.mode)}
317+ </Badge>
318+ </div>
319+ </div>
320+ <div class="shrink-0 rounded-lg border bg-card px-3 py-2 text-center shadow-sm">
321+ <p class="text-[10px] font-semibold uppercase tracking-wider text-muted-foreground">
322+ {t("courses.weight")}
276 </p>323 </p>
324+ <p class="font-display text-xl font-semibold tabular-nums">{exam.weight}</p>
277 </div>325 </div>
278- <Badge variant="outline" class="capitalize">
279- {examKindLabel(String(exam.kind), t)}
280- </Badge>
281 </Link>326 </Link>
282 </li>327 </li>
283 )}328 )}
@@ -290,7 +335,12 @@ function CourseDetailContent() {
290 {/* Roster */}335 {/* Roster */}
291 <Show when={isTeacherPlus()}>336 <Show when={isTeacherPlus()}>
292 <section class="surface-card space-y-4 p-5">337 <section class="surface-card space-y-4 p-5">
293- <h2 class="font-display text-lg font-semibold">{t("courses.roster")}</h2>338+ <div class="flex flex-wrap items-center justify-between gap-2">
339+ <h2 class="font-display text-lg font-semibold">{t("courses.roster")}</h2>
340+ <Badge variant="secondary" class="rounded-full px-3 py-1">
341+ {rosterCount()}
342+ </Badge>
343+ </div>
294 <form344 <form
295 class="grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto]"345 class="grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto]"
296 onSubmit={(e) => {346 onSubmit={(e) => {
@@ -337,46 +387,57 @@ function CourseDetailContent() {
337 </form>387 </form>
338 388
339 <Suspense fallback={<PageSpinner />}>389 <Suspense fallback={<PageSpinner />}>
340- <Show when={(roster() ?? []).length > 0} fallback={null}>390+ <Show
341- <Table>391+ when={(roster() ?? []).length > 0}
342- <TableHeader>392+ fallback={
343- <TableRow>393+ <div class="rounded-lg border border-dashed border-border/80 bg-muted/20 px-4 py-8 text-center text-sm text-muted-foreground">
344- <TableHead>{t("admin.username")}</TableHead>394+ {t("exams.emptyRoster")}
345- <TableHead>{t("admin.id")}</TableHead>395+ </div>
346- <TableHead class="w-24" />396+ }
347- </TableRow>397+ >
348- </TableHeader>398+ <div class="overflow-hidden rounded-lg border border-border/70">
349- <TableBody>399+ <Table>
350- <For each={roster() ?? []}>400+ <TableHeader>
351- {(row) => (401+ <TableRow>
352- <TableRow>402+ <TableHead>{t("admin.username")}</TableHead>
353- <TableCell class="font-medium">403+ <TableHead>{t("admin.id")}</TableHead>
354- {row.user.display_name || row.user.username}404+ <TableHead class="w-24" />
355- </TableCell>405+ </TableRow>
356- <TableCell class="font-mono text-xs">{row.user.id}</TableCell>406+ </TableHeader>
357- <TableCell>407+ <TableBody>
358- <Show when={canManage()}>408+ <For each={roster() ?? []}>
359- <Button409+ {(row) => (
360- type="button"410+ <TableRow>
361- variant="ghost"411+ <TableCell class="font-medium">
362- size="sm"412+ {row.user.display_name || row.user.username}
363- class="text-destructive"413+ </TableCell>
364- onClick={() =>414+ <TableCell class="font-mono text-xs text-muted-foreground">
365- void wrap(async () => {415+ {row.user.id}
366- await deleteCourseEnrollmentByUserId(id(), row.user.id);416+ </TableCell>
367- await refetchRoster();417+ <TableCell class="text-right">
368- })418+ <Show when={canManage()}>
369- }419+ <Button
370- >420+ type="button"
371- <IconTrash class="h-4 w-4" />421+ variant="ghost"
372- </Button>422+ size="sm"
373- </Show>423+ class="text-destructive"
374- </TableCell>424+ onClick={() =>
375- </TableRow>425+ void wrap(async () => {
376- )}426+ await deleteCourseEnrollmentByUserId(id(), row.user.id);
377- </For>427+ await refetchRoster();
378- </TableBody>428+ })
379- </Table>429+ }
430+ >
431+ <IconTrash class="h-4 w-4" />
432+ </Button>
433+ </Show>
434+ </TableCell>
435+ </TableRow>
436+ )}
437+ </For>
438+ </TableBody>
439+ </Table>
440+ </div>
380 </Show>441 </Show>
381 </Suspense>442 </Suspense>
382 </section>443 </section>
src/pages/exam-detail-page.tsxmodified+5 -3
@@ -222,17 +222,19 @@ function ExamDetailContent() {
222 <div class="flex flex-wrap items-center gap-2 pt-1">222 <div class="flex flex-wrap items-center gap-2 pt-1">
223 <Badge variant="outline" class={cn(223 <Badge variant="outline" class={cn(
224 "rounded-sm capitalize",224 "rounded-sm capitalize",
225+ !isScheduled() && "bg-muted text-muted-foreground border-muted",
225 isFinished() && "bg-muted text-muted-foreground border-muted",226 isFinished() && "bg-muted text-muted-foreground border-muted",
226- !isFinished() && !isUpcoming() && "bg-emerald-500/15 text-emerald-600 border-emerald-500/30",227+ isScheduled() && !isFinished() && !isUpcoming() && "bg-emerald-500/15 text-emerald-600 border-emerald-500/30",
227 isUpcoming() && "bg-amber-500/15 text-amber-600 border-amber-500/30",228 isUpcoming() && "bg-amber-500/15 text-amber-600 border-amber-500/30",
228 )}>229 )}>
229 <span class={cn(230 <span class={cn(
230 "mr-1.5 inline-block h-1.5 w-1.5 rounded-full",231 "mr-1.5 inline-block h-1.5 w-1.5 rounded-full",
232+ !isScheduled() && "bg-muted-foreground",
231 isFinished() && "bg-muted-foreground",233 isFinished() && "bg-muted-foreground",
232- !isFinished() && !isUpcoming() && "bg-emerald-600",234+ isScheduled() && !isFinished() && !isUpcoming() && "bg-emerald-600",
233 isUpcoming() && "bg-amber-600",235 isUpcoming() && "bg-amber-600",
234 )} />236 )} />
235- {isFinished() ? t("exams.finished") : isUpcoming() ? t("exams.upcoming") : t("exams.active")}237+ {!isScheduled() ? t("exams.unscheduled") : isFinished() ? t("exams.finished") : isUpcoming() ? t("exams.upcoming") : t("exams.active")}
236 </Badge>238 </Badge>
237 <Badge variant="outline" class="rounded-sm capitalize">239 <Badge variant="outline" class="rounded-sm capitalize">
238 {examKindLabel(String(ex().kind), t)}240 {examKindLabel(String(ex().kind), t)}
src/pages/live-monitor-page.tsxmodified+74 -50
@@ -2,7 +2,7 @@ import { For, Show, Suspense, createEffect, createResource, createSignal, onClea
2 import { Link, useLocation } from "@tanstack/solid-router";2 import { Link, useLocation } from "@tanstack/solid-router";
3 import { getExamLive } from "@/api/getExamLive";3 import { getExamLive } from "@/api/getExamLive";
4 import { getExamById } from "@/api/getExamById";4 import { getExamById } from "@/api/getExamById";
5-import { ApiError } from "@/api/client";5+import { ApiError, formatApiError } from "@/api/client";
6 import type { LiveMonitor, LiveRosterEntry } from "@/api/types";6 import type { LiveMonitor, LiveRosterEntry } from "@/api/types";
7 import type { MessageKey } from "@/i18n/messages";7 import type { MessageKey } from "@/i18n/messages";
8 import { RouteGuard } from "@/components/layout/route-guard";8 import { RouteGuard } from "@/components/layout/route-guard";
@@ -42,6 +42,11 @@ function labelFromStatus(status: string, t: (key: MessageKey) => string): string
42 return k ? t(k) : status;42 return k ? t(k) : status;
43 }43 }
44 44
45+function progressPercent(entry: LiveRosterEntry, questionCount: number): number {
46+ if (questionCount <= 0) return 0;
47+ return Math.round(((entry.answered ?? 0) / questionCount) * 100);
48+}
49+
45 function LiveMonitorContent() {50 function LiveMonitorContent() {
46 const location = useLocation();51 const location = useLocation();
47 const t = useT();52 const t = useT();
@@ -68,7 +73,7 @@ function LiveMonitorContent() {
68 setSnapshot(data);73 setSnapshot(data);
69 } catch (err) {74 } catch (err) {
70 console.error("[live-monitor] fetch error:", err);75 console.error("[live-monitor] fetch error:", err);
71- setError(err instanceof ApiError ? err.message : "Failed to load");76+ setError(err instanceof ApiError ? formatApiError(err, locale()) : formatApiError(err, locale()));
72 }77 }
73 };78 };
74 79
@@ -174,57 +179,76 @@ function LiveMonitorContent() {
174 </section>179 </section>
175 180
176 <section class="surface-card p-2 sm:p-4">181 <section class="surface-card p-2 sm:p-4">
177- <h2 class="mb-4 font-display text-lg font-semibold">{t("exams.liveRoster")}</h2>182+ <div class="mb-4 flex flex-wrap items-center justify-between gap-2">
183+ <h2 class="font-display text-lg font-semibold">{t("exams.liveRoster")}</h2>
184+ <Badge variant="outline" class="rounded-full px-3 py-1">
185+ {sorted.length} / {m.question_count}
186+ </Badge>
187+ </div>
178 <Show188 <Show
179 when={sorted.length > 0}189 when={sorted.length > 0}
180- fallback={<p class="rounded-sm bg-muted/40 px-3 py-4 text-sm text-muted-foreground">{t("exams.emptyRoster")}</p>}190+ fallback={<p class="rounded-lg bg-muted/40 px-3 py-4 text-sm text-muted-foreground">{t("exams.emptyRoster")}</p>}
181 >191 >
182- <Table>192+ <div class="overflow-hidden rounded-lg border border-border/70">
183- <TableHeader>193+ <Table>
184- <TableRow>194+ <TableHeader>
185- <SortHead label={t("admin.username")} sortKey="username" currentKey={sortKey()} currentDir={sortDir()} onSort={toggleSort} class="text-left" />195+ <TableRow>
186- <SortHead label={t("attempt.status")} sortKey="status" currentKey={sortKey()} currentDir={sortDir()} onSort={toggleSort} class="text-center" />196+ <SortHead label={t("admin.username")} sortKey="username" currentKey={sortKey()} currentDir={sortDir()} onSort={toggleSort} class="text-left" />
187- <SortHead label={t("attempt.progress")} sortKey="progress" currentKey={sortKey()} currentDir={sortDir()} onSort={toggleSort} class="text-center" />197+ <SortHead label={t("attempt.status")} sortKey="status" currentKey={sortKey()} currentDir={sortDir()} onSort={toggleSort} class="text-center" />
188- <SortHead label={t("attempt.remaining")} sortKey="remaining" currentKey={sortKey()} currentDir={sortDir()} onSort={toggleSort} class="text-center" />198+ <SortHead label={t("attempt.progress")} sortKey="progress" currentKey={sortKey()} currentDir={sortDir()} onSort={toggleSort} class="text-center" />
189- <SortHead label={t("exams.lastActivity")} sortKey="activity" currentKey={sortKey()} currentDir={sortDir()} onSort={toggleSort} class="text-center" />199+ <SortHead label={t("attempt.remaining")} sortKey="remaining" currentKey={sortKey()} currentDir={sortDir()} onSort={toggleSort} class="text-center" />
190- <SortHead label={t("marks.mark")} sortKey="mark" currentKey={sortKey()} currentDir={sortDir()} onSort={toggleSort} class="text-center" />200+ <SortHead label={t("exams.lastActivity")} sortKey="activity" currentKey={sortKey()} currentDir={sortDir()} onSort={toggleSort} class="text-center" />
191- </TableRow>201+ <SortHead label={t("marks.mark")} sortKey="mark" currentKey={sortKey()} currentDir={sortDir()} onSort={toggleSort} class="text-center" />
192- </TableHeader>202+ </TableRow>
193- <TableBody>203+ </TableHeader>
194- <For each={pageItems}>204+ <TableBody>
195- {(entry) => (205+ <For each={pageItems}>
196- <TableRow>206+ {(entry) => (
197- <TableCell class="font-medium">207+ <TableRow>
198- {entry.display_name || entry.username || t("exams.nameless")}208+ <TableCell class="font-medium">
199- </TableCell>209+ {entry.display_name || entry.username || t("exams.nameless")}
200- <TableCell>210+ </TableCell>
201- <Badge variant={211+ <TableCell class="text-center">
202- entry.status === "in_progress" ? "default" :212+ <Badge
203- entry.status === "submitted" ? "secondary" :213+ class="rounded-full"
204- "outline"214+ variant={
205- }>215+ entry.status === "in_progress" ? "default" :
206- {labelFromStatus(entry.status, t)}216+ entry.status === "submitted" ? "secondary" :
207- </Badge>217+ "outline"
208- </TableCell>218+ }
209- <TableCell class="tabular-nums text-center">{entry.answered}/{m.question_count}</TableCell>219+ >
210- <TableCell class="tabular-nums text-center">220+ {labelFromStatus(entry.status, t)}
211- {entry.status === "in_progress" && entry.remaining_ms > 0221+ </Badge>
212- ? `${Math.ceil(entry.remaining_ms / 60000)}dk`222+ </TableCell>
213- : entry.status === "in_progress" && entry.remaining_ms <= 0223+ <TableCell class="min-w-32 tabular-nums">
214- ? `<1dk`224+ <div class="flex items-center justify-center gap-2">
215- : "—"}225+ <span>{entry.answered}/{m.question_count}</span>
216- </TableCell>226+ <div class="h-1.5 w-16 overflow-hidden rounded-full bg-muted">
217- <TableCell class="text-xs text-center">227+ <div class="h-full rounded-full bg-primary" style={{ width: `${progressPercent(entry, m.question_count)}%` }} />
218- {entry.last_activity ? formatDateTime(entry.last_activity, locale()) : "—"}228+ </div>
219- </TableCell>229+ </div>
220- <TableCell class="tabular-nums font-semibold text-center">230+ </TableCell>
221- {entry.mark != null ? entry.mark : "—"}231+ <TableCell class="tabular-nums text-center">
222- </TableCell>232+ <span class={entry.status === "in_progress" && entry.remaining_ms <= 5 * 60 * 1000 ? "rounded-full bg-amber-500/10 px-2 py-1 text-amber-700 dark:text-amber-300" : ""}>
223- </TableRow>233+ {entry.status === "in_progress" && entry.remaining_ms > 0
224- )}234+ ? `${Math.ceil(entry.remaining_ms / 60000)}dk`
225- </For>235+ : entry.status === "in_progress" && entry.remaining_ms <= 0
226- </TableBody>236+ ? `<1dk`
227- </Table>237+ : "—"}
238+ </span>
239+ </TableCell>
240+ <TableCell class="text-center text-xs">
241+ {entry.last_activity ? formatDateTime(entry.last_activity, locale()) : "—"}
242+ </TableCell>
243+ <TableCell class="text-center font-semibold tabular-nums">
244+ {entry.mark != null ? entry.mark : "—"}
245+ </TableCell>
246+ </TableRow>
247+ )}
248+ </For>
249+ </TableBody>
250+ </Table>
251+ </div>
228 252
229 <Show when={sorted.length > PAGE_SIZE}>253 <Show when={sorted.length > PAGE_SIZE}>
230 <div class="mt-4 flex items-center justify-between gap-2 border-t border-border/60 pt-3">254 <div class="mt-4 flex items-center justify-between gap-2 border-t border-border/60 pt-3">