forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

exam-labels.ts35 lines, 1.3 KiBHistoryRawDownload
1import type { KnownExamKind } from "@/api/client";
2import type { MessageKey } from "@/i18n/messages";
3
4type T = (key: MessageKey, vars?: Record<string, string | number>) => string;
5
6const EXAM_KIND_LABELS: Record<KnownExamKind, MessageKey> = {
7 homework: "exams.kind.homework",
8 quiz: "exams.kind.quiz",
9 midterm: "exams.kind.midterm",
10 final: "exams.kind.final",
11 project: "exams.kind.project",
12 oral: "exams.kind.oral",
13};
14
15export function isKnownExamKind(kind: string): kind is KnownExamKind {
16 return kind in EXAM_KIND_LABELS;
17}
18
19export function examKindLabel(kind: string, t: T): string {
20 return kind in EXAM_KIND_LABELS ? t(EXAM_KIND_LABELS[kind as KnownExamKind]) : kind;
21}
22
23/** Attempts cell for the live monitor. `maxAttempts` comes from the monitored
24 * exam itself (the roster rows don't carry it); `0` means unlimited. */
25export function attemptLabel(
26 entry: { attempt?: number | null; attempts_used?: number | null },
27 maxAttempts: number | null | undefined,
28): string {
29 if (entry.attempts_used != null && maxAttempts != null && maxAttempts > 0) {
30 return `${entry.attempts_used} / ${maxAttempts}`;
31 }
32 if (entry.attempt != null) return String(entry.attempt);
33 if (entry.attempts_used != null) return String(entry.attempts_used);
34 return "—";
35}