hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import type { KnownExamKind } from "@/api/client"; |
| 2 | import type { MessageKey } from "@/i18n/messages"; |
| 3 | |
| 4 | type T = (key: MessageKey, vars?: Record<string, string | number>) => string; |
| 5 | |
| 6 | const 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 | |
| 15 | export function isKnownExamKind(kind: string): kind is KnownExamKind { |
| 16 | return kind in EXAM_KIND_LABELS; |
| 17 | } |
| 18 | |
| 19 | export 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. */ |
| 25 | export 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 | } |