✨ live exams, Turkish i18n, and mobile tab bar
Browse files at this commit7024736eb0c0a0ef58377ff1f2aebd121d301944Parent: b2179ec- feat
- ✨ live exams, Turkish i18n, and mobile tab bar
32 changed files +3184 -406
- src/app.tsx +2 -0
- src/components/ConfirmButton.tsx +49 -0
- src/components/ExamMonitor.tsx +219 -0
- src/components/ExamQuestions.tsx +274 -0
- src/components/Feedback.tsx +7 -2
- src/components/Icons.tsx +16 -0
- src/components/Layout.tsx +49 -12
- src/components/ProfileFields.tsx +7 -6
- src/components/ScheduleFields.tsx +105 -0
- src/components/UserPicker.tsx +101 -0
- src/lib/action.ts +3 -2
- src/lib/api.ts +90 -3
- src/lib/clock.ts +42 -0
- src/lib/format.ts +28 -8
- src/lib/i18n.ts +606 -0
- src/lib/types.ts +149 -6
- src/pages/CourseDetail.tsx +95 -62
- src/pages/Courses.tsx +36 -20
- src/pages/EventDetail.tsx +63 -48
- src/pages/Events.tsx +37 -21
- src/pages/ExamDetail.tsx +240 -62
- src/pages/ExamRoom.tsx +370 -0
- src/pages/Exams.tsx +8 -7
- src/pages/Home.tsx +16 -19
- src/pages/Login.tsx +36 -18
- src/pages/Marks.tsx +27 -23
- src/pages/NotFound.tsx +3 -2
- src/pages/Notes.tsx +59 -44
- src/pages/Profile.tsx +7 -6
- src/pages/Users.tsx +61 -28
- src/styles.css +377 -7
- vite.config.ts +2 -0
src/app.tsxmodified+2 -0
| @@ -16,6 +16,7 @@ const Courses = lazy(() => import("./pages/Courses")); | ||
| 16 | 16 | const CourseDetail = lazy(() => import("./pages/CourseDetail")); |
| 17 | 17 | const Exams = lazy(() => import("./pages/Exams")); |
| 18 | 18 | const ExamDetail = lazy(() => import("./pages/ExamDetail")); |
| 19 | +const ExamRoom = lazy(() => import("./pages/ExamRoom")); | |
| 19 | 20 | const Marks = lazy(() => import("./pages/Marks")); |
| 20 | 21 | const Profile = lazy(() => import("./pages/Profile")); |
| 21 | 22 | const Users = lazy(() => import("./pages/Users")); |
| @@ -46,6 +47,7 @@ export function App() { | ||
| 46 | 47 | <Route path="/courses/:id" component={CourseDetail} /> |
| 47 | 48 | <Route path="/exams" component={Exams} /> |
| 48 | 49 | <Route path="/exams/:id" component={ExamDetail} /> |
| 50 | + <Route path="/exams/:id/room" component={ExamRoom} /> | |
| 49 | 51 | <Route path="/marks" component={Marks} /> |
| 50 | 52 | <Route path="/profile" component={Profile} /> |
| 51 | 53 | <Route path="/users" component={Users} /> |
src/components/ConfirmButton.tsxadded+49 -0
| @@ -0,0 +1,49 @@ | ||
| 1 | +// Two-step destructive button: the first press arms it ("Really delete?"), | |
| 2 | +// the second fires. It disarms by itself after a moment or when focus leaves, | |
| 3 | +// so a stray tap never destroys anything. | |
| 4 | + | |
| 5 | +import { Show, createSignal, onCleanup, type JSX } from "solid-js"; | |
| 6 | +import { t } from "../lib/i18n"; | |
| 7 | + | |
| 8 | +export function ConfirmButton(props: { | |
| 9 | + children: JSX.Element; | |
| 10 | + onConfirm: () => void; | |
| 11 | + /** Armed label; defaults to the localized "Really delete?". */ | |
| 12 | + confirmText?: string; | |
| 13 | + /** Resting classes; defaults to "ghost danger". */ | |
| 14 | + class?: string; | |
| 15 | + disabled?: boolean; | |
| 16 | +}) { | |
| 17 | + const [armed, setArmed] = createSignal(false); | |
| 18 | + let timer: ReturnType<typeof setTimeout> | undefined; | |
| 19 | + onCleanup(() => clearTimeout(timer)); | |
| 20 | + | |
| 21 | + const disarm = () => { | |
| 22 | + clearTimeout(timer); | |
| 23 | + setArmed(false); | |
| 24 | + }; | |
| 25 | + | |
| 26 | + const press = () => { | |
| 27 | + if (armed()) { | |
| 28 | + disarm(); | |
| 29 | + props.onConfirm(); | |
| 30 | + } else { | |
| 31 | + setArmed(true); | |
| 32 | + timer = setTimeout(disarm, 4000); | |
| 33 | + } | |
| 34 | + }; | |
| 35 | + | |
| 36 | + return ( | |
| 37 | + <button | |
| 38 | + type="button" | |
| 39 | + class={`${props.class ?? "ghost danger"}${armed() ? " confirm-armed" : ""}`} | |
| 40 | + disabled={props.disabled} | |
| 41 | + onClick={press} | |
| 42 | + onBlur={disarm} | |
| 43 | + > | |
| 44 | + <Show when={armed()} fallback={props.children}> | |
| 45 | + {props.confirmText ?? t("reallyDelete")} | |
| 46 | + </Show> | |
| 47 | + </button> | |
| 48 | + ); | |
| 49 | +} |
src/components/ExamMonitor.tsxadded+219 -0
| @@ -0,0 +1,219 @@ | ||
| 1 | +// The teacher's live view of a scheduled exam: who's in, who's still writing, | |
| 2 | +// time each student has left, marks as they land. Fed by the backend's SSE | |
| 3 | +// stream (a fresh snapshot every couple of seconds); the browser's | |
| 4 | +// EventSource reconnects by itself. Each row opens the student's answer | |
| 5 | +// sheet with the machine's auto-score suggestion and an inline grade box. | |
| 6 | + | |
| 7 | +import { For, Show, createResource, createSignal, onCleanup } from "solid-js"; | |
| 8 | +import { createAction } from "../lib/action"; | |
| 9 | +import { exams } from "../lib/api"; | |
| 10 | +import { formatCountdown, personLabel } from "../lib/format"; | |
| 11 | +import { t } from "../lib/i18n"; | |
| 12 | +import type { Exam, ExamLive, LiveStudent, PersonRef } from "../lib/types"; | |
| 13 | +import { LIMITS } from "../lib/types"; | |
| 14 | +import { Empty, ErrorLine, Loading } from "./Feedback"; | |
| 15 | + | |
| 16 | +export function ExamMonitor(props: { exam: Exam }) { | |
| 17 | + const [snapshot, setSnapshot] = createSignal<ExamLive | null>(null); | |
| 18 | + const [reviewing, setReviewing] = createSignal<PersonRef | null>(null); | |
| 19 | + | |
| 20 | + const source = new EventSource(exams.liveStreamUrl(props.exam.id), { | |
| 21 | + withCredentials: true, | |
| 22 | + }); | |
| 23 | + source.addEventListener("snapshot", (event) => { | |
| 24 | + setSnapshot(JSON.parse((event as MessageEvent).data) as ExamLive); | |
| 25 | + }); | |
| 26 | + onCleanup(() => source.close()); | |
| 27 | + | |
| 28 | + const seconds = (student: LiveStudent) => | |
| 29 | + student.remaining_ms === null ? "—" : formatCountdown(student.remaining_ms); | |
| 30 | + | |
| 31 | + const activity = (student: LiveStudent, now: number) => { | |
| 32 | + if (student.last_activity === null) return "—"; | |
| 33 | + const secondsAgo = Math.max(0, Math.round((now - student.last_activity) / 1000)); | |
| 34 | + return secondsAgo < 120 | |
| 35 | + ? t("agoSeconds")(secondsAgo) | |
| 36 | + : t("agoMinutes")(Math.round(secondsAgo / 60)); | |
| 37 | + }; | |
| 38 | + | |
| 39 | + return ( | |
| 40 | + <article class="stack gap-top"> | |
| 41 | + <h2>{t("liveMonitor")}</h2> | |
| 42 | + <Show when={snapshot()} fallback={<Loading />}> | |
| 43 | + {(live) => ( | |
| 44 | + <> | |
| 45 | + <div class="live-counts"> | |
| 46 | + <span class="badge">{t("countEnrolled")(live().counts.enrolled)}</span> | |
| 47 | + <span class="badge phase-open">{t("countWriting")(live().counts.in_progress)}</span> | |
| 48 | + <span class="badge">{t("countTurnedIn")(live().counts.submitted)}</span> | |
| 49 | + <span class="badge">{t("countNotStarted")(live().counts.not_started)}</span> | |
| 50 | + <Show when={live().counts.expired > 0}> | |
| 51 | + <span class="badge phase-closed">{t("countTimeUp")(live().counts.expired)}</span> | |
| 52 | + </Show> | |
| 53 | + <span class="badge">{t("countGraded")(live().counts.graded)}</span> | |
| 54 | + </div> | |
| 55 | + | |
| 56 | + <Show | |
| 57 | + when={live().students.length} | |
| 58 | + fallback={<Empty>{t("nobodyEnrolledCourse")}</Empty>} | |
| 59 | + > | |
| 60 | + <div class="table-wrap"> | |
| 61 | + <table> | |
| 62 | + <thead> | |
| 63 | + <tr> | |
| 64 | + <th>{t("student")}</th> | |
| 65 | + <th>{t("status")}</th> | |
| 66 | + <th>{t("answeredCol")}</th> | |
| 67 | + <th>{t("timeLeftCol")}</th> | |
| 68 | + <th>{t("lastSaveCol")}</th> | |
| 69 | + <th>{t("markCol")}</th> | |
| 70 | + <th /> | |
| 71 | + </tr> | |
| 72 | + </thead> | |
| 73 | + <tbody> | |
| 74 | + <For each={live().students}> | |
| 75 | + {(student) => ( | |
| 76 | + <tr> | |
| 77 | + <td>{personLabel(student.user)}</td> | |
| 78 | + <td> | |
| 79 | + <span class={`badge status-${student.status}`}> | |
| 80 | + {t("liveStatusWord")(student.status)} | |
| 81 | + </span> | |
| 82 | + </td> | |
| 83 | + <td> | |
| 84 | + {student.answered} / {live().question_count} | |
| 85 | + </td> | |
| 86 | + <td>{seconds(student)}</td> | |
| 87 | + <td class="meta">{activity(student, live().now)}</td> | |
| 88 | + <td>{student.mark ?? "—"}</td> | |
| 89 | + <td> | |
| 90 | + <Show when={student.status !== "not_started"}> | |
| 91 | + <button | |
| 92 | + class="ghost" | |
| 93 | + onClick={() => | |
| 94 | + setReviewing((current) => | |
| 95 | + current?.id === student.user.id ? null : student.user, | |
| 96 | + ) | |
| 97 | + } | |
| 98 | + > | |
| 99 | + {reviewing()?.id === student.user.id ? t("close") : t("review")} | |
| 100 | + </button> | |
| 101 | + </Show> | |
| 102 | + </td> | |
| 103 | + </tr> | |
| 104 | + )} | |
| 105 | + </For> | |
| 106 | + </tbody> | |
| 107 | + </table> | |
| 108 | + </div> | |
| 109 | + </Show> | |
| 110 | + | |
| 111 | + <Show when={reviewing()}> | |
| 112 | + {(student) => <AnswerSheet examId={props.exam.id} student={student()} />} | |
| 113 | + </Show> | |
| 114 | + </> | |
| 115 | + )} | |
| 116 | + </Show> | |
| 117 | + </article> | |
| 118 | + ); | |
| 119 | +} | |
| 120 | + | |
| 121 | +/** One student's judged answers plus the auto-score suggestion and a grade box. */ | |
| 122 | +function AnswerSheet(props: { examId: string; student: PersonRef }) { | |
| 123 | + const [sheet] = createResource( | |
| 124 | + () => [props.examId, props.student.id] as const, | |
| 125 | + ([examId, userId]) => exams.attemptAnswers(examId, userId), | |
| 126 | + ); | |
| 127 | + // The authored questions (with text/choices/correct) to render rows against. | |
| 128 | + const [questions] = createResource(() => props.examId, exams.questions); | |
| 129 | + | |
| 130 | + const grade = createAction(async (form: HTMLFormElement) => { | |
| 131 | + const data = new FormData(form); | |
| 132 | + await exams.grade(props.examId, props.student.id, Number(data.get("mark"))); | |
| 133 | + }); | |
| 134 | + | |
| 135 | + const suggestion = () => { | |
| 136 | + const auto = sheet()?.auto_score; | |
| 137 | + return auto && auto.possible > 0 | |
| 138 | + ? Math.round((auto.earned / auto.possible) * 100) | |
| 139 | + : undefined; | |
| 140 | + }; | |
| 141 | + | |
| 142 | + return ( | |
| 143 | + <div class="card stack"> | |
| 144 | + <h3>{t("sheetTitle")(personLabel(props.student))}</h3> | |
| 145 | + <Show when={sheet() && questions()} fallback={<Loading />}> | |
| 146 | + <Show | |
| 147 | + when={questions()!.length} | |
| 148 | + fallback={<Empty>{t("noQuestionsSheet")}</Empty>} | |
| 149 | + > | |
| 150 | + <div class="stack"> | |
| 151 | + <For each={questions()}> | |
| 152 | + {(question, index) => { | |
| 153 | + const answer = () => | |
| 154 | + sheet()!.answers.find((a) => a.question === question.id); | |
| 155 | + return ( | |
| 156 | + <div class="sheet-row"> | |
| 157 | + <p class="qtext"> | |
| 158 | + <strong>Q{index() + 1}.</strong> {question.text} | |
| 159 | + <span class="badge">{t("pts")(question.points)}</span> | |
| 160 | + </p> | |
| 161 | + <Show when={answer()} fallback={<p class="muted">{t("noAnswer")}</p>}> | |
| 162 | + {(current) => ( | |
| 163 | + <p | |
| 164 | + classList={{ | |
| 165 | + "answer-ok": current().is_correct === true, | |
| 166 | + "answer-bad": current().is_correct === false, | |
| 167 | + }} | |
| 168 | + > | |
| 169 | + <Show | |
| 170 | + when={question.kind === "choice"} | |
| 171 | + fallback={<span class="prewrap">{current().text || "—"}</span>} | |
| 172 | + > | |
| 173 | + {question.choices?.[current().selected ?? -1] ?? "—"} | |
| 174 | + <Show when={current().is_correct === true}> ✓</Show> | |
| 175 | + <Show when={current().is_correct === false}> | |
| 176 | + {t("rightAnswerIs")(question.choices?.[question.correct ?? -1] ?? "—")} | |
| 177 | + </Show> | |
| 178 | + </Show> | |
| 179 | + </p> | |
| 180 | + )} | |
| 181 | + </Show> | |
| 182 | + </div> | |
| 183 | + ); | |
| 184 | + }} | |
| 185 | + </For> | |
| 186 | + </div> | |
| 187 | + | |
| 188 | + <p class="meta"> | |
| 189 | + {t("autoScoreLine")(sheet()!.auto_score.earned, sheet()!.auto_score.possible)} | |
| 190 | + </p> | |
| 191 | + </Show> | |
| 192 | + | |
| 193 | + <form | |
| 194 | + class="row row-end" | |
| 195 | + onSubmit={(e) => { | |
| 196 | + e.preventDefault(); | |
| 197 | + void grade.run(e.currentTarget); | |
| 198 | + }} | |
| 199 | + > | |
| 200 | + <label> | |
| 201 | + {t("mark0100")} | |
| 202 | + <input | |
| 203 | + name="mark" | |
| 204 | + type="number" | |
| 205 | + required | |
| 206 | + min={LIMITS.mark.min} | |
| 207 | + max={LIMITS.mark.max} | |
| 208 | + value={suggestion()} | |
| 209 | + /> | |
| 210 | + </label> | |
| 211 | + <button type="submit" disabled={grade.pending()}> | |
| 212 | + {t("gradeAction")} | |
| 213 | + </button> | |
| 214 | + </form> | |
| 215 | + <ErrorLine error={grade.error()} /> | |
| 216 | + </Show> | |
| 217 | + </div> | |
| 218 | + ); | |
| 219 | +} |
src/components/ExamQuestions.tsxadded+274 -0
| @@ -0,0 +1,274 @@ | ||
| 1 | +// Question authoring for whoever manages the exam's course. Choice questions | |
| 2 | +// carry 2–10 options with the right one picked by radio; text questions are | |
| 3 | +// free-form and graded by a human. The backend freezes the list the moment | |
| 4 | +// anyone starts an attempt — that lands here as an error line, not a crash. | |
| 5 | + | |
| 6 | +import { For, Show, createResource, createSignal } from "solid-js"; | |
| 7 | +import { createAction } from "../lib/action"; | |
| 8 | +import { exams } from "../lib/api"; | |
| 9 | +import { t } from "../lib/i18n"; | |
| 10 | +import { LIMITS, type ExamQuestion, type QuestionKind } from "../lib/types"; | |
| 11 | +import { ConfirmButton } from "./ConfirmButton"; | |
| 12 | +import { Empty, ErrorLine, Loading } from "./Feedback"; | |
| 13 | +import { IconPlus } from "./Icons"; | |
| 14 | + | |
| 15 | +interface QuestionDraft { | |
| 16 | + text: string; | |
| 17 | + kind: string; | |
| 18 | + points: number; | |
| 19 | + choices: string[] | null; | |
| 20 | + correct: number | null; | |
| 21 | +} | |
| 22 | + | |
| 23 | +export function ExamQuestions(props: { examId: string }) { | |
| 24 | + const [list, { mutate }] = createResource(() => props.examId, exams.questions); | |
| 25 | + const [adding, setAdding] = createSignal(false); | |
| 26 | + const [editing, setEditing] = createSignal<string | null>(null); | |
| 27 | + | |
| 28 | + const create = createAction(async (draft: QuestionDraft) => { | |
| 29 | + const created = await exams.createQuestion(props.examId, draft); | |
| 30 | + mutate((current) => [...(current ?? []), created]); | |
| 31 | + setAdding(false); | |
| 32 | + }); | |
| 33 | + | |
| 34 | + const save = createAction(async (qid: string, draft: QuestionDraft) => { | |
| 35 | + const updated = await exams.updateQuestion(props.examId, qid, draft); | |
| 36 | + mutate((current) => current?.map((q) => (q.id === qid ? updated : q))); | |
| 37 | + setEditing(null); | |
| 38 | + }); | |
| 39 | + | |
| 40 | + const remove = createAction(async (qid: string) => { | |
| 41 | + await exams.removeQuestion(props.examId, qid); | |
| 42 | + mutate((current) => current?.filter((q) => q.id !== qid)); | |
| 43 | + }); | |
| 44 | + | |
| 45 | + const totalPoints = () => (list() ?? []).reduce((sum, q) => sum + q.points, 0); | |
| 46 | + | |
| 47 | + return ( | |
| 48 | + <article class="stack gap-top"> | |
| 49 | + <div class="section-head"> | |
| 50 | + <h2>{t("questionsTitle")}</h2> | |
| 51 | + <Show when={list()?.length}> | |
| 52 | + <span class="badge">{t("totalPoints")(totalPoints())}</span> | |
| 53 | + </Show> | |
| 54 | + <button class="ghost" onClick={() => setAdding((open) => !open)}> | |
| 55 | + <IconPlus /> {t("addQuestion")} | |
| 56 | + </button> | |
| 57 | + </div> | |
| 58 | + | |
| 59 | + <Show when={adding()}> | |
| 60 | + <QuestionForm | |
| 61 | + pending={create.pending()} | |
| 62 | + onCancel={() => setAdding(false)} | |
| 63 | + onSubmit={(draft) => void create.run(draft)} | |
| 64 | + /> | |
| 65 | + <ErrorLine error={create.error()} /> | |
| 66 | + </Show> | |
| 67 | + | |
| 68 | + <ErrorLine error={save.error() ?? remove.error()} /> | |
| 69 | + | |
| 70 | + <Show when={!list.loading} fallback={<Loading />}> | |
| 71 | + <Show | |
| 72 | + when={list()?.length} | |
| 73 | + fallback={ | |
| 74 | + <Empty | |
| 75 | + action={ | |
| 76 | + <button onClick={() => setAdding(true)}> | |
| 77 | + <IconPlus /> {t("addQuestion")} | |
| 78 | + </button> | |
| 79 | + } | |
| 80 | + > | |
| 81 | + {t("noQuestionsYet")} | |
| 82 | + </Empty> | |
| 83 | + } | |
| 84 | + > | |
| 85 | + <div class="stack"> | |
| 86 | + <For each={list()}> | |
| 87 | + {(question, index) => ( | |
| 88 | + <div class="card stack"> | |
| 89 | + <Show | |
| 90 | + when={editing() !== question.id} | |
| 91 | + fallback={ | |
| 92 | + <QuestionForm | |
| 93 | + initial={question} | |
| 94 | + pending={save.pending()} | |
| 95 | + onCancel={() => setEditing(null)} | |
| 96 | + onSubmit={(draft) => void save.run(question.id, draft)} | |
| 97 | + /> | |
| 98 | + } | |
| 99 | + > | |
| 100 | + <header class="row"> | |
| 101 | + <strong>Q{index() + 1}</strong> | |
| 102 | + <span class="badge">{t("pts")(question.points)}</span> | |
| 103 | + <span class="badge">{t("questionKindWord")(question.kind)}</span> | |
| 104 | + <span class="row-actions push"> | |
| 105 | + <button class="ghost" onClick={() => setEditing(question.id)}> | |
| 106 | + {t("edit")} | |
| 107 | + </button> | |
| 108 | + <ConfirmButton | |
| 109 | + disabled={remove.pending()} | |
| 110 | + onConfirm={() => void remove.run(question.id)} | |
| 111 | + > | |
| 112 | + {t("deleteNote")} | |
| 113 | + </ConfirmButton> | |
| 114 | + </span> | |
| 115 | + </header> | |
| 116 | + <p class="prewrap">{question.text}</p> | |
| 117 | + <Show when={question.choices}> | |
| 118 | + <ol class="choices"> | |
| 119 | + <For each={question.choices}> | |
| 120 | + {(choice, choiceIndex) => ( | |
| 121 | + <li classList={{ correct: choiceIndex() === question.correct }}> | |
| 122 | + {choice} | |
| 123 | + <Show when={choiceIndex() === question.correct}> ✓</Show> | |
| 124 | + </li> | |
| 125 | + )} | |
| 126 | + </For> | |
| 127 | + </ol> | |
| 128 | + </Show> | |
| 129 | + </Show> | |
| 130 | + </div> | |
| 131 | + )} | |
| 132 | + </For> | |
| 133 | + </div> | |
| 134 | + </Show> | |
| 135 | + </Show> | |
| 136 | + </article> | |
| 137 | + ); | |
| 138 | +} | |
| 139 | + | |
| 140 | +/** Create/edit form; choice options are dynamic rows with a "right answer" radio. */ | |
| 141 | +function QuestionForm(props: { | |
| 142 | + initial?: ExamQuestion; | |
| 143 | + pending: boolean; | |
| 144 | + onSubmit: (draft: QuestionDraft) => void; | |
| 145 | + onCancel: () => void; | |
| 146 | +}) { | |
| 147 | + const [kind, setKind] = createSignal<QuestionKind>(props.initial?.kind ?? "choice"); | |
| 148 | + const [options, setOptions] = createSignal<string[]>( | |
| 149 | + props.initial?.choices ?? ["", ""], | |
| 150 | + ); | |
| 151 | + const [correct, setCorrect] = createSignal(props.initial?.correct ?? 0); | |
| 152 | + | |
| 153 | + const removeOption = (index: number) => { | |
| 154 | + setOptions((current) => current.filter((_, i) => i !== index)); | |
| 155 | + if (correct() === index) setCorrect(0); | |
| 156 | + else if (correct() > index) setCorrect(correct() - 1); | |
| 157 | + }; | |
| 158 | + | |
| 159 | + const submit = (form: HTMLFormElement) => { | |
| 160 | + const data = new FormData(form); | |
| 161 | + props.onSubmit({ | |
| 162 | + text: String(data.get("text")), | |
| 163 | + kind: kind(), | |
| 164 | + points: Number(data.get("points")), | |
| 165 | + choices: kind() === "choice" ? options() : null, | |
| 166 | + correct: kind() === "choice" ? correct() : null, | |
| 167 | + }); | |
| 168 | + }; | |
| 169 | + | |
| 170 | + return ( | |
| 171 | + <form | |
| 172 | + class="stack" | |
| 173 | + onSubmit={(e) => { | |
| 174 | + e.preventDefault(); | |
| 175 | + submit(e.currentTarget); | |
| 176 | + }} | |
| 177 | + > | |
| 178 | + <label> | |
| 179 | + {t("questionLabel")} | |
| 180 | + <textarea | |
| 181 | + name="text" | |
| 182 | + rows={2} | |
| 183 | + required | |
| 184 | + maxLength={LIMITS.questionText} | |
| 185 | + ref={(el) => queueMicrotask(() => el.focus())} | |
| 186 | + > | |
| 187 | + {props.initial?.text ?? ""} | |
| 188 | + </textarea> | |
| 189 | + </label> | |
| 190 | + <div class="row"> | |
| 191 | + <label> | |
| 192 | + {t("answerType")} | |
| 193 | + <select | |
| 194 | + value={kind()} | |
| 195 | + onChange={(e) => setKind(e.currentTarget.value as QuestionKind)} | |
| 196 | + > | |
| 197 | + <option value="choice">{t("answerTypeChoice")}</option> | |
| 198 | + <option value="text">{t("answerTypeText")}</option> | |
| 199 | + </select> | |
| 200 | + </label> | |
| 201 | + <label> | |
| 202 | + {t("points")} | |
| 203 | + <input | |
| 204 | + name="points" | |
| 205 | + type="number" | |
| 206 | + required | |
| 207 | + min={LIMITS.questionPoints.min} | |
| 208 | + max={LIMITS.questionPoints.max} | |
| 209 | + value={props.initial?.points ?? 10} | |
| 210 | + /> | |
| 211 | + </label> | |
| 212 | + </div> | |
| 213 | + | |
| 214 | + <Show when={kind() === "choice"}> | |
| 215 | + <div class="stack"> | |
| 216 | + <span class="hint">{t("tickRightAnswer")}</span> | |
| 217 | + <For each={options()}> | |
| 218 | + {(option, index) => ( | |
| 219 | + <div class="option-row"> | |
| 220 | + <input | |
| 221 | + type="radio" | |
| 222 | + name="correct-pick" | |
| 223 | + checked={correct() === index()} | |
| 224 | + onChange={() => setCorrect(index())} | |
| 225 | + aria-label={t("optionIsRight")(index() + 1)} | |
| 226 | + /> | |
| 227 | + <input | |
| 228 | + value={option} | |
| 229 | + required | |
| 230 | + maxLength={LIMITS.choiceText} | |
| 231 | + placeholder={t("optionN")(index() + 1)} | |
| 232 | + onInput={(e) => { | |
| 233 | + const value = e.currentTarget.value; | |
| 234 | + setOptions((current) => | |
| 235 | + current.map((v, i) => (i === index() ? value : v)), | |
| 236 | + ); | |
| 237 | + }} | |
| 238 | + /> | |
| 239 | + <button | |
| 240 | + type="button" | |
| 241 | + class="ghost icon-btn" | |
| 242 | + aria-label={t("removeOption")} | |
| 243 | + disabled={options().length <= LIMITS.questionChoices.min} | |
| 244 | + onClick={() => removeOption(index())} | |
| 245 | + > | |
| 246 | + × | |
| 247 | + </button> | |
| 248 | + </div> | |
| 249 | + )} | |
| 250 | + </For> | |
| 251 | + <span class="row-actions"> | |
| 252 | + <button | |
| 253 | + type="button" | |
| 254 | + class="ghost" | |
| 255 | + disabled={options().length >= LIMITS.questionChoices.max} | |
| 256 | + onClick={() => setOptions((current) => [...current, ""])} | |
| 257 | + > | |
| 258 | + <IconPlus /> {t("addOption")} | |
| 259 | + </button> | |
| 260 | + </span> | |
| 261 | + </div> | |
| 262 | + </Show> | |
| 263 | + | |
| 264 | + <span class="row-actions"> | |
| 265 | + <button type="submit" disabled={props.pending}> | |
| 266 | + {t("saveQuestion")} | |
| 267 | + </button> | |
| 268 | + <button type="button" class="ghost" onClick={props.onCancel}> | |
| 269 | + {t("cancel")} | |
| 270 | + </button> | |
| 271 | + </span> | |
| 272 | + </form> | |
| 273 | + ); | |
| 274 | +} |
src/components/Feedback.tsxmodified+7 -2
| @@ -20,6 +20,11 @@ export function Loading() { | ||
| 20 | 20 | ); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | -export function Empty(props: { children: JSX.Element }) { | |
| 24 | - return <p class="empty">{props.children}</p>; | |
| 23 | +export function Empty(props: { children: JSX.Element; action?: JSX.Element }) { | |
| 24 | + return ( | |
| 25 | + <div class="empty"> | |
| 26 | + <p>{props.children}</p> | |
| 27 | + {props.action} | |
| 28 | + </div> | |
| 29 | + ); | |
| 25 | 30 | } |
src/components/Icons.tsxmodified+16 -0
| @@ -114,3 +114,19 @@ export const IconArrow = () => ( | ||
| 114 | 114 | <path d="m13 6 6 6-6 6" /> |
| 115 | 115 | </Svg> |
| 116 | 116 | ); |
| 117 | + | |
| 118 | +export const IconEye = () => ( | |
| 119 | + <Svg> | |
| 120 | + <path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0" /> | |
| 121 | + <circle cx="12" cy="12" r="3" /> | |
| 122 | + </Svg> | |
| 123 | +); | |
| 124 | + | |
| 125 | +export const IconEyeOff = () => ( | |
| 126 | + <Svg> | |
| 127 | + <path d="M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49" /> | |
| 128 | + <path d="M14.084 14.158a3 3 0 0 1-4.242-4.242" /> | |
| 129 | + <path d="M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143" /> | |
| 130 | + <path d="m2 2 20 20" /> | |
| 131 | + </Svg> | |
| 132 | +); |
src/components/Layout.tsxmodified+49 -12
| @@ -1,9 +1,11 @@ | ||
| 1 | 1 | // App shell: sidebar with navigation, user chip, and logout. Collapses into a |
| 2 | -// top bar on narrow screens (pure CSS). Rendered only for authenticated routes. | |
| 2 | +// top bar on narrow screens (pure CSS), where the nav moves into a fixed | |
| 3 | +// bottom tab bar within thumb reach. Rendered only for authenticated routes. | |
| 3 | 4 | |
| 4 | 5 | import { A, useNavigate } from "@solidjs/router"; |
| 5 | 6 | import { Show, type ParentProps } from "solid-js"; |
| 6 | 7 | import { useAuth } from "../lib/auth"; |
| 8 | +import { lang, setLang, t } from "../lib/i18n"; | |
| 7 | 9 | import { |
| 8 | 10 | IconBook, |
| 9 | 11 | IconCalendar, |
| @@ -36,49 +38,84 @@ export function Layout(props: ParentProps) { | ||
| 36 | 38 | </A> |
| 37 | 39 | <nav> |
| 38 | 40 | <A href="/" end> |
| 39 | - <IconHome /> Home | |
| 41 | + <IconHome /> {t("navHome")} | |
| 40 | 42 | </A> |
| 41 | 43 | <A href="/notes"> |
| 42 | - <IconNote /> Notes | |
| 44 | + <IconNote /> {t("navNotes")} | |
| 43 | 45 | </A> |
| 44 | 46 | <A href="/events"> |
| 45 | - <IconCalendar /> Events | |
| 47 | + <IconCalendar /> {t("navEvents")} | |
| 46 | 48 | </A> |
| 47 | 49 | <A href="/courses"> |
| 48 | - <IconBook /> Courses | |
| 50 | + <IconBook /> {t("navCourses")} | |
| 49 | 51 | </A> |
| 50 | 52 | <A href="/exams"> |
| 51 | - <IconClipboard /> Exams | |
| 53 | + <IconClipboard /> {t("navExams")} | |
| 52 | 54 | </A> |
| 53 | 55 | <A href="/marks"> |
| 54 | - <IconChart /> Marks | |
| 56 | + <IconChart /> {t("navMarks")} | |
| 55 | 57 | </A> |
| 56 | 58 | <Show when={can("admin")}> |
| 57 | 59 | <A href="/users"> |
| 58 | - <IconUsers /> Users | |
| 60 | + <IconUsers /> {t("navUsers")} | |
| 59 | 61 | </A> |
| 60 | 62 | </Show> |
| 61 | 63 | </nav> |
| 62 | 64 | <div class="sidebar-end"> |
| 63 | 65 | <Show when={user()}> |
| 64 | 66 | {(current) => ( |
| 65 | - <A href="/profile" class="user-chip" title="Profile"> | |
| 67 | + <A href="/profile" class="user-chip" title={t("profileLink")}> | |
| 66 | 68 | <span class="avatar"> |
| 67 | 69 | {(current().name ?? current().username).slice(0, 1)} |
| 68 | 70 | </span> |
| 69 | 71 | <span class="user-meta"> |
| 70 | 72 | <strong>{current().name ?? current().username}</strong> |
| 71 | - <span>{current().role}</span> | |
| 73 | + <span>{t("roleWord")(current().role)}</span> | |
| 72 | 74 | </span> |
| 73 | 75 | </A> |
| 74 | 76 | )} |
| 75 | 77 | </Show> |
| 76 | - <button class="ghost icon-btn" onClick={onLogout} title="Log out"> | |
| 77 | - <IconLogout /> | |
| 78 | + <button | |
| 79 | + class="ghost lang-switch" | |
| 80 | + onClick={() => setLang(lang() === "tr" ? "en" : "tr")} | |
| 81 | + > | |
| 82 | + {t("otherLanguage")} | |
| 83 | + </button> | |
| 84 | + <button class="ghost logout" onClick={onLogout}> | |
| 85 | + <IconLogout /> <span>{t("logout")}</span> | |
| 78 | 86 | </button> |
| 79 | 87 | </div> |
| 80 | 88 | </header> |
| 81 | 89 | <main>{props.children}</main> |
| 90 | + | |
| 91 | + {/* Thumb-reach duplicate of the nav on small screens (CSS-hidden on | |
| 92 | + desktop); the sidebar collapses into a top bar with just the brand, | |
| 93 | + profile chip, and logout. */} | |
| 94 | + <nav class="tabbar"> | |
| 95 | + <A href="/" end> | |
| 96 | + <IconHome /> {t("navHome")} | |
| 97 | + </A> | |
| 98 | + <A href="/notes"> | |
| 99 | + <IconNote /> {t("navNotes")} | |
| 100 | + </A> | |
| 101 | + <A href="/events"> | |
| 102 | + <IconCalendar /> {t("navEvents")} | |
| 103 | + </A> | |
| 104 | + <A href="/courses"> | |
| 105 | + <IconBook /> {t("navCourses")} | |
| 106 | + </A> | |
| 107 | + <A href="/exams"> | |
| 108 | + <IconClipboard /> {t("navExams")} | |
| 109 | + </A> | |
| 110 | + <A href="/marks"> | |
| 111 | + <IconChart /> {t("navMarks")} | |
| 112 | + </A> | |
| 113 | + <Show when={can("admin")}> | |
| 114 | + <A href="/users"> | |
| 115 | + <IconUsers /> {t("navUsers")} | |
| 116 | + </A> | |
| 117 | + </Show> | |
| 118 | + </nav> | |
| 82 | 119 | </div> |
| 83 | 120 | ); |
| 84 | 121 | } |
src/components/ProfileFields.tsxmodified+7 -6
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | |
| 6 | 6 | import type { ProfilePatch } from "../lib/api"; |
| 7 | 7 | import { today } from "../lib/format"; |
| 8 | +import { t } from "../lib/i18n"; | |
| 8 | 9 | import { LIMITS, type User } from "../lib/types"; |
| 9 | 10 | |
| 10 | 11 | /** Matches the backend rule: optional leading +, separators, 7–15 digits. */ |
| @@ -26,16 +27,16 @@ export function ProfileFields(props: { user: User }) { | ||
| 26 | 27 | <> |
| 27 | 28 | <div class="row"> |
| 28 | 29 | <label style={{ flex: 1 }}> |
| 29 | - Name | |
| 30 | + {t("nameField")} | |
| 30 | 31 | <input name="name" value={props.user.name ?? ""} maxLength={LIMITS.personName} /> |
| 31 | 32 | </label> |
| 32 | 33 | <label style={{ flex: 1 }}> |
| 33 | - Surname | |
| 34 | + {t("surnameField")} | |
| 34 | 35 | <input name="surname" value={props.user.surname ?? ""} maxLength={LIMITS.personName} /> |
| 35 | 36 | </label> |
| 36 | 37 | </div> |
| 37 | 38 | <label> |
| 38 | ||
| 39 | + {t("emailField")} | |
| 39 | 40 | <input |
| 40 | 41 | name="email" |
| 41 | 42 | type="email" |
| @@ -46,18 +47,18 @@ export function ProfileFields(props: { user: User }) { | ||
| 46 | 47 | </label> |
| 47 | 48 | <div class="row"> |
| 48 | 49 | <label style={{ flex: 1 }}> |
| 49 | - Phone | |
| 50 | + {t("phoneField")} | |
| 50 | 51 | <input |
| 51 | 52 | name="phone" |
| 52 | 53 | type="tel" |
| 53 | 54 | value={props.user.phone ?? ""} |
| 54 | 55 | pattern={PHONE_PATTERN} |
| 55 | - title={`${LIMITS.phoneDigits.min} to ${LIMITS.phoneDigits.max} digits; +, spaces, dashes, and parentheses are allowed`} | |
| 56 | + title={t("phoneTitle")(LIMITS.phoneDigits.min, LIMITS.phoneDigits.max)} | |
| 56 | 57 | placeholder="+90 555 123 45 67" |
| 57 | 58 | /> |
| 58 | 59 | </label> |
| 59 | 60 | <label style={{ flex: 1 }}> |
| 60 | - Birth date | |
| 61 | + {t("birthDateField")} | |
| 61 | 62 | <input |
| 62 | 63 | name="birth_date" |
| 63 | 64 | type="date" |
src/components/ScheduleFields.tsxadded+105 -0
| @@ -0,0 +1,105 @@ | ||
| 1 | +// The scheduling block shared by the exam create and edit forms: a mode | |
| 2 | +// picker in plain words, the window, and — for flexible exams — the | |
| 3 | +// per-student time budget. Unscheduled stays the quiet default. | |
| 4 | + | |
| 5 | +import { Show, createSignal } from "solid-js"; | |
| 6 | +import { fromInputValue, toInputValue } from "../lib/format"; | |
| 7 | +import { t } from "../lib/i18n"; | |
| 8 | +import { LIMITS, type Exam, type ExamMode } from "../lib/types"; | |
| 9 | + | |
| 10 | +/** Read the schedule unit out of a submitted form (all-null when untimed). */ | |
| 11 | +export function scheduleFromForm(data: FormData): { | |
| 12 | + mode: string | null; | |
| 13 | + starts_at: number | null; | |
| 14 | + ends_at: number | null; | |
| 15 | + duration_ms: number | null; | |
| 16 | +} { | |
| 17 | + const mode = String(data.get("mode") ?? ""); | |
| 18 | + if (mode === "") { | |
| 19 | + return { mode: null, starts_at: null, ends_at: null, duration_ms: null }; | |
| 20 | + } | |
| 21 | + return { | |
| 22 | + mode, | |
| 23 | + starts_at: fromInputValue(String(data.get("starts_at") ?? "")), | |
| 24 | + ends_at: fromInputValue(String(data.get("ends_at") ?? "")), | |
| 25 | + duration_ms: | |
| 26 | + mode === "async" ? Number(data.get("duration_min")) * 60_000 : null, | |
| 27 | + }; | |
| 28 | +} | |
| 29 | + | |
| 30 | +export function ScheduleFields(props: { exam?: Exam }) { | |
| 31 | + const [mode, setMode] = createSignal<"" | ExamMode>(props.exam?.mode ?? ""); | |
| 32 | + let starts!: HTMLInputElement; | |
| 33 | + let ends!: HTMLInputElement; | |
| 34 | + | |
| 35 | + // "YYYY-MM-DDTHH:mm" compares chronologically as a string, so the browser | |
| 36 | + // can refuse a window that ends before it starts — before the server does. | |
| 37 | + const checkOrder = () => { | |
| 38 | + ends.setCustomValidity( | |
| 39 | + starts.value && ends.value && ends.value <= starts.value | |
| 40 | + ? t("endsAfterStarts") | |
| 41 | + : "", | |
| 42 | + ); | |
| 43 | + }; | |
| 44 | + | |
| 45 | + return ( | |
| 46 | + <div class="stack"> | |
| 47 | + <label> | |
| 48 | + {t("timing")} | |
| 49 | + <select | |
| 50 | + name="mode" | |
| 51 | + value={mode()} | |
| 52 | + onChange={(e) => setMode(e.currentTarget.value as "" | ExamMode)} | |
| 53 | + > | |
| 54 | + <option value="">{t("timingNone")}</option> | |
| 55 | + <option value="sync">{t("timingSync")}</option> | |
| 56 | + <option value="async">{t("timingAsync")}</option> | |
| 57 | + </select> | |
| 58 | + </label> | |
| 59 | + <Show when={mode()}> | |
| 60 | + <div class="row"> | |
| 61 | + <label> | |
| 62 | + {t("opens")} | |
| 63 | + <input | |
| 64 | + ref={starts} | |
| 65 | + name="starts_at" | |
| 66 | + type="datetime-local" | |
| 67 | + required | |
| 68 | + value={toInputValue(props.exam?.starts_at ?? null)} | |
| 69 | + onInput={checkOrder} | |
| 70 | + /> | |
| 71 | + </label> | |
| 72 | + <label> | |
| 73 | + {t("closes")} | |
| 74 | + <input | |
| 75 | + ref={ends} | |
| 76 | + name="ends_at" | |
| 77 | + type="datetime-local" | |
| 78 | + required | |
| 79 | + value={toInputValue(props.exam?.ends_at ?? null)} | |
| 80 | + onInput={checkOrder} | |
| 81 | + /> | |
| 82 | + </label> | |
| 83 | + <Show when={mode() === "async"}> | |
| 84 | + <label> | |
| 85 | + {t("minutesPerStudent")} | |
| 86 | + <input | |
| 87 | + name="duration_min" | |
| 88 | + type="number" | |
| 89 | + required | |
| 90 | + min={LIMITS.examDurationMin.min} | |
| 91 | + max={LIMITS.examDurationMin.max} | |
| 92 | + value={ | |
| 93 | + props.exam?.duration_ms | |
| 94 | + ? Math.round(props.exam.duration_ms / 60_000) | |
| 95 | + : 40 | |
| 96 | + } | |
| 97 | + /> | |
| 98 | + </label> | |
| 99 | + </Show> | |
| 100 | + </div> | |
| 101 | + <p class="hint">{mode() === "sync" ? t("syncHint") : t("asyncHint")}</p> | |
| 102 | + </Show> | |
| 103 | + </div> | |
| 104 | + ); | |
| 105 | +} |
src/components/UserPicker.tsxadded+101 -0
| @@ -0,0 +1,101 @@ | ||
| 1 | +// Search-as-you-type person picker: replaces every "paste a user id" input. | |
| 2 | +// The picked user's id travels in a hidden input, so forms keep reading | |
| 3 | +// FormData exactly as before. Native validation blocks submitting free text | |
| 4 | +// that was never picked from the list. | |
| 5 | + | |
| 6 | +import { For, Show, createSignal, onCleanup } from "solid-js"; | |
| 7 | +import { users } from "../lib/api"; | |
| 8 | +import { personLabel } from "../lib/format"; | |
| 9 | +import { t } from "../lib/i18n"; | |
| 10 | +import type { PersonRef } from "../lib/types"; | |
| 11 | + | |
| 12 | +export function UserPicker(props: { | |
| 13 | + /** Hidden field name the form reads, e.g. "user_id". */ | |
| 14 | + name: string; | |
| 15 | + label: string; | |
| 16 | + onPick?: (person: PersonRef | null) => void; | |
| 17 | +}) { | |
| 18 | + const [query, setQuery] = createSignal(""); | |
| 19 | + const [results, setResults] = createSignal<PersonRef[]>([]); | |
| 20 | + const [picked, setPicked] = createSignal<PersonRef | null>(null); | |
| 21 | + const [open, setOpen] = createSignal(false); | |
| 22 | + let input!: HTMLInputElement; | |
| 23 | + let timer: ReturnType<typeof setTimeout> | undefined; | |
| 24 | + let generation = 0; // an older search must never overwrite a newer one | |
| 25 | + onCleanup(() => clearTimeout(timer)); | |
| 26 | + | |
| 27 | + const validity = () => | |
| 28 | + input.setCustomValidity(picked() ? "" : t("pickFromList")); | |
| 29 | + | |
| 30 | + const choose = (person: PersonRef | null) => { | |
| 31 | + setPicked(person); | |
| 32 | + props.onPick?.(person); | |
| 33 | + validity(); | |
| 34 | + }; | |
| 35 | + | |
| 36 | + const onInput = (value: string) => { | |
| 37 | + setQuery(value); | |
| 38 | + choose(null); | |
| 39 | + clearTimeout(timer); | |
| 40 | + const needle = value.trim(); | |
| 41 | + if (!needle) { | |
| 42 | + setResults([]); | |
| 43 | + setOpen(false); | |
| 44 | + return; | |
| 45 | + } | |
| 46 | + timer = setTimeout(async () => { | |
| 47 | + const current = ++generation; | |
| 48 | + try { | |
| 49 | + const found = await users.search(needle); | |
| 50 | + if (current !== generation) return; | |
| 51 | + setResults(found); | |
| 52 | + setOpen(true); | |
| 53 | + } catch { | |
| 54 | + // A failed lookup just leaves the menu empty; submitting still | |
| 55 | + // requires a pick, so nothing wrong can go through. | |
| 56 | + if (current === generation) setResults([]); | |
| 57 | + } | |
| 58 | + }, 250); | |
| 59 | + }; | |
| 60 | + | |
| 61 | + const pick = (person: PersonRef) => { | |
| 62 | + choose(person); | |
| 63 | + setQuery(personLabel(person)); | |
| 64 | + setOpen(false); | |
| 65 | + }; | |
| 66 | + | |
| 67 | + return ( | |
| 68 | + <label class="picker"> | |
| 69 | + {props.label} | |
| 70 | + <span class="picker-box"> | |
| 71 | + <input | |
| 72 | + ref={input} | |
| 73 | + value={query()} | |
| 74 | + placeholder={t("typeAName")} | |
| 75 | + autocomplete="off" | |
| 76 | + required | |
| 77 | + onInput={(e) => onInput(e.currentTarget.value)} | |
| 78 | + onFocus={() => results().length && setOpen(true)} | |
| 79 | + onBlur={() => setOpen(false)} | |
| 80 | + onInvalid={validity} | |
| 81 | + /> | |
| 82 | + <input type="hidden" name={props.name} value={picked()?.id ?? ""} /> | |
| 83 | + <Show when={open()}> | |
| 84 | + <div class="picker-menu"> | |
| 85 | + <Show when={results().length} fallback={<p class="muted">{t("nobodyFound")}</p>}> | |
| 86 | + <For each={results()}> | |
| 87 | + {(person) => ( | |
| 88 | + // mousedown, not click: it must win against the input's blur. | |
| 89 | + <button type="button" onMouseDown={() => pick(person)}> | |
| 90 | + <strong>{personLabel(person)}</strong> | |
| 91 | + <span>{person.username}</span> | |
| 92 | + </button> | |
| 93 | + )} | |
| 94 | + </For> | |
| 95 | + </Show> | |
| 96 | + </div> | |
| 97 | + </Show> | |
| 98 | + </span> | |
| 99 | + </label> | |
| 100 | + ); | |
| 101 | +} |
src/lib/action.tsmodified+3 -2
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | |
| 4 | 4 | import { batch, createSignal, type Accessor } from "solid-js"; |
| 5 | 5 | import { ApiError } from "./api"; |
| 6 | +import { t } from "./i18n"; | |
| 6 | 7 | |
| 7 | 8 | export interface Action<Args extends unknown[]> { |
| 8 | 9 | run: (...args: Args) => Promise<boolean>; |
| @@ -42,8 +43,8 @@ export function createAction<Args extends unknown[]>( | ||
| 42 | 43 | function describe(err: unknown): string { |
| 43 | 44 | if (err instanceof ApiError) { |
| 44 | 45 | return err.retryAfterSecs !== undefined |
| 45 | - ? `${err.message} — retry in ${err.retryAfterSecs}s` | |
| 46 | + ? `${err.message} — ${t("retryIn")(err.retryAfterSecs)}` | |
| 46 | 47 | : err.message; |
| 47 | 48 | } |
| 48 | - return err instanceof Error ? err.message : "something went wrong"; | |
| 49 | + return err instanceof Error ? err.message : t("somethingWrong"); | |
| 49 | 50 | } |
src/lib/api.tsmodified+90 -3
| @@ -3,20 +3,29 @@ | ||
| 3 | 3 | // backend's `{ "error": "..." }` message and the HTTP status. |
| 4 | 4 | |
| 5 | 5 | import type { |
| 6 | + AnswerSaved, | |
| 6 | 7 | AppEvent, |
| 7 | 8 | Attendance, |
| 8 | 9 | AttendanceStatus, |
| 10 | + AttemptAnswers, | |
| 11 | + AttemptQuestion, | |
| 9 | 12 | Course, |
| 10 | 13 | Enrollment, |
| 11 | 14 | Exam, |
| 15 | + ExamAttempt, | |
| 16 | + ExamLive, | |
| 17 | + ExamQuestion, | |
| 12 | 18 | ExamResult, |
| 13 | 19 | ExamStatistics, |
| 14 | 20 | MarksReport, |
| 15 | 21 | Note, |
| 22 | + PersonRef, | |
| 16 | 23 | Role, |
| 17 | 24 | User, |
| 18 | 25 | } from "./types"; |
| 19 | 26 | |
| 27 | +import { t } from "./i18n"; | |
| 28 | + | |
| 20 | 29 | const BASE = import.meta.env.VITE_API_URL ?? "/api"; |
| 21 | 30 | |
| 22 | 31 | export class ApiError extends Error { |
| @@ -40,7 +49,7 @@ async function request<T>(method: string, path: string, body?: unknown): Promise | ||
| 40 | 49 | body: body === undefined ? undefined : JSON.stringify(body), |
| 41 | 50 | }); |
| 42 | 51 | } catch { |
| 43 | - throw new ApiError(0, "network error — is the backend up?"); | |
| 52 | + throw new ApiError(0, t("networkError")); | |
| 44 | 53 | } |
| 45 | 54 | |
| 46 | 55 | if (!res.ok) { |
| @@ -87,6 +96,8 @@ export interface ProfilePatch { | ||
| 87 | 96 | export const users = { |
| 88 | 97 | list: () => get<User[]>("/users"), |
| 89 | 98 | get: (id: string) => get<User>(`/users/${id}`), |
| 99 | + /** Fragment search over username/name/surname; teacher+, max 10 rows. */ | |
| 100 | + search: (q: string) => get<PersonRef[]>(`/users/search?q=${encodeURIComponent(q)}`), | |
| 90 | 101 | setRole: (id: string, role: Role) => patch<User>(`/users/${id}/role`, { role }), |
| 91 | 102 | /** The caller's own profile. */ |
| 92 | 103 | updateMyProfile: (body: ProfilePatch) => patch<User>("/users/me", body), |
| @@ -147,7 +158,17 @@ export const courses = { | ||
| 147 | 158 | exams: (id: string) => get<Exam[]>(`/courses/${id}/exams`), |
| 148 | 159 | createExam: ( |
| 149 | 160 | id: string, |
| 150 | - body: { title: string; description?: string; kind: string; weight: number }, | |
| 161 | + body: { | |
| 162 | + title: string; | |
| 163 | + description?: string; | |
| 164 | + kind: string; | |
| 165 | + weight: number; | |
| 166 | + /** Schedule as a unit: all null for an unscheduled exam. */ | |
| 167 | + mode: string | null; | |
| 168 | + starts_at: number | null; | |
| 169 | + ends_at: number | null; | |
| 170 | + duration_ms: number | null; | |
| 171 | + }, | |
| 151 | 172 | ) => post<Exam>(`/courses/${id}/exams`, body), |
| 152 | 173 | }; |
| 153 | 174 | |
| @@ -155,9 +176,19 @@ export const exams = { | ||
| 155 | 176 | list: () => get<Exam[]>("/exams"), |
| 156 | 177 | get: (id: string) => get<Exam>(`/exams/${id}`), |
| 157 | 178 | // Creation lives under the course: `courses.createExam`. |
| 179 | + /** Schedule fields are set-or-clear: explicit `null` clears, omit keeps. */ | |
| 158 | 180 | update: ( |
| 159 | 181 | id: string, |
| 160 | - body: { title?: string; description?: string; kind?: string; weight?: number }, | |
| 182 | + body: { | |
| 183 | + title?: string; | |
| 184 | + description?: string; | |
| 185 | + kind?: string; | |
| 186 | + weight?: number; | |
| 187 | + mode?: string | null; | |
| 188 | + starts_at?: number | null; | |
| 189 | + ends_at?: number | null; | |
| 190 | + duration_ms?: number | null; | |
| 191 | + }, | |
| 161 | 192 | ) => patch<Exam>(`/exams/${id}`, body), |
| 162 | 193 | remove: (id: string) => del(`/exams/${id}`), |
| 163 | 194 | |
| @@ -167,9 +198,65 @@ export const exams = { | ||
| 167 | 198 | post<ExamResult>(`/exams/${id}/results`, { mark, user_id: userId }), |
| 168 | 199 | removeResult: (id: string, userId: string) => del(`/exams/${id}/results/${userId}`), |
| 169 | 200 | statistics: (id: string) => get<ExamStatistics>(`/exams/${id}/statistics`), |
| 201 | + | |
| 202 | + // ---- attempts: sitting a scheduled exam ---- | |
| 203 | + /** Start or resume — the backend never resets a running clock. */ | |
| 204 | + startAttempt: (id: string) => post<ExamAttempt>(`/exams/${id}/attempt`), | |
| 205 | + /** 404 until started. */ | |
| 206 | + myAttempt: (id: string) => get<ExamAttempt>(`/exams/${id}/attempt`), | |
| 207 | + finishAttempt: (id: string) => post<ExamAttempt>(`/exams/${id}/attempt/finish`), | |
| 208 | + /** The sitting student's questions (no `correct`), own answers embedded. */ | |
| 209 | + attemptQuestions: (id: string) => get<AttemptQuestion[]>(`/exams/${id}/attempt/questions`), | |
| 210 | + saveAnswer: (id: string, body: { question_id: string; selected?: number; text?: string }) => | |
| 211 | + post<AnswerSaved>(`/exams/${id}/attempt/answers`, body), | |
| 212 | + | |
| 213 | + // ---- questions: authored by teacher+ with course-management rights ---- | |
| 214 | + questions: (id: string) => get<ExamQuestion[]>(`/exams/${id}/questions`), | |
| 215 | + createQuestion: ( | |
| 216 | + id: string, | |
| 217 | + body: { | |
| 218 | + text: string; | |
| 219 | + kind: string; | |
| 220 | + points: number; | |
| 221 | + choices: string[] | null; | |
| 222 | + correct: number | null; | |
| 223 | + }, | |
| 224 | + ) => post<ExamQuestion>(`/exams/${id}/questions`, body), | |
| 225 | + /** `choices`/`correct` are set-or-clear; send the full kind unit. */ | |
| 226 | + updateQuestion: ( | |
| 227 | + id: string, | |
| 228 | + qid: string, | |
| 229 | + body: { | |
| 230 | + text?: string; | |
| 231 | + points?: number; | |
| 232 | + kind?: string; | |
| 233 | + choices?: string[] | null; | |
| 234 | + correct?: number | null; | |
| 235 | + }, | |
| 236 | + ) => patch<ExamQuestion>(`/exams/${id}/questions/${qid}`, body), | |
| 237 | + removeQuestion: (id: string, qid: string) => del(`/exams/${id}/questions/${qid}`), | |
| 238 | + | |
| 239 | + // ---- live monitor (teacher+) ---- | |
| 240 | + live: (id: string) => get<ExamLive>(`/exams/${id}/live`), | |
| 241 | + /** SSE endpoint for `EventSource` — one `snapshot` event every ~2 s. */ | |
| 242 | + liveStreamUrl: (id: string) => `${BASE}/exams/${id}/live/stream`, | |
| 243 | + /** One student's judged answer sheet with the auto-score suggestion. */ | |
| 244 | + attemptAnswers: (id: string, userId: string) => | |
| 245 | + get<AttemptAnswers>(`/exams/${id}/attempts/${userId}/answers`), | |
| 246 | + /** The student exam room WebSocket (autosave acks + server countdown). */ | |
| 247 | + attemptSocketUrl: (id: string) => { | |
| 248 | + const proto = window.location.protocol === "https:" ? "wss:" : "ws:"; | |
| 249 | + const base = BASE.startsWith("http") ? BASE.replace(/^http/, "ws") : `${proto}//${window.location.host}${BASE}`; | |
| 250 | + return `${base}/exams/${id}/attempt/ws`; | |
| 251 | + }, | |
| 170 | 252 | }; |
| 171 | 253 | |
| 172 | 254 | export const marks = { |
| 173 | 255 | mine: () => get<MarksReport>("/marks/me"), |
| 174 | 256 | forUser: (id: string) => get<MarksReport>(`/marks/${id}`), |
| 175 | 257 | }; |
| 258 | + | |
| 259 | +export const meta = { | |
| 260 | + /** Server clock, UTC unix-milliseconds — see `lib/clock.ts`. */ | |
| 261 | + time: () => get<{ now: number }>("/time"), | |
| 262 | +}; |
src/lib/clock.tsadded+42 -0
| @@ -0,0 +1,42 @@ | ||
| 1 | +// Server-authoritative time. Every deadline in the API is judged by the | |
| 2 | +// backend clock, so countdowns and "is the window open?" checks must not | |
| 3 | +// trust the device clock: sync once, keep the offset, add it to Date.now(). | |
| 4 | + | |
| 5 | +import { createSignal } from "solid-js"; | |
| 6 | +import { meta } from "./api"; | |
| 7 | + | |
| 8 | +const [offset, setOffset] = createSignal(0); | |
| 9 | +let syncing: Promise<void> | undefined; | |
| 10 | + | |
| 11 | +/** Fetch `/time` once and remember `server - device`. Safe to call again. */ | |
| 12 | +export function syncClock(): Promise<void> { | |
| 13 | + syncing ??= (async () => { | |
| 14 | + try { | |
| 15 | + const before = Date.now(); | |
| 16 | + const { now } = await meta.time(); | |
| 17 | + // Split the round trip: the server read sits roughly mid-flight. | |
| 18 | + setOffset(now - (before + Date.now()) / 2); | |
| 19 | + } catch { | |
| 20 | + // Offline or backend down — fall back to the device clock (offset 0); | |
| 21 | + // the server still enforces every deadline itself. Allow a retry. | |
| 22 | + syncing = undefined; | |
| 23 | + } | |
| 24 | + })(); | |
| 25 | + return syncing; | |
| 26 | +} | |
| 27 | + | |
| 28 | +/** Best estimate of the server clock, UTC unix-milliseconds. Reactive. */ | |
| 29 | +export function serverNow(): number { | |
| 30 | + if (syncing === undefined) void syncClock(); | |
| 31 | + return Date.now() + offset(); | |
| 32 | +} | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * A signal ticking with the (offset-corrected) server clock — for countdowns | |
| 36 | + * and open/closed window checks that should re-render as time passes. | |
| 37 | + */ | |
| 38 | +export function createClock(intervalMs = 1000) { | |
| 39 | + const [now, setNow] = createSignal(serverNow()); | |
| 40 | + const timer = setInterval(() => setNow(serverNow()), intervalMs); | |
| 41 | + return { now, stop: () => clearInterval(timer) }; | |
| 42 | +} |
src/lib/format.tsmodified+28 -8
| @@ -1,21 +1,29 @@ | ||
| 1 | 1 | // Time helpers: the API speaks unix milliseconds, <input type="datetime-local"> |
| 2 | -// speaks "YYYY-MM-DDTHH:mm" in local time. | |
| 2 | +// speaks "YYYY-MM-DDTHH:mm" in local time. Plus the one person-display rule. | |
| 3 | 3 | |
| 4 | -const formatter = new Intl.DateTimeFormat(undefined, { | |
| 5 | - dateStyle: "medium", | |
| 6 | - timeStyle: "short", | |
| 7 | -}); | |
| 4 | +import { locale, t } from "./i18n"; | |
| 5 | +import type { PersonRef } from "./types"; | |
| 6 | + | |
| 7 | +/** What to call a person in the UI: their name if we have it, else username. */ | |
| 8 | +export function personLabel(person: PersonRef): string { | |
| 9 | + return person.display_name ?? person.username; | |
| 10 | +} | |
| 8 | 11 | |
| 9 | 12 | export function formatMillis(millis: number | null): string { |
| 10 | - return millis === null ? "—" : formatter.format(new Date(millis)); | |
| 13 | + return millis === null | |
| 14 | + ? "—" | |
| 15 | + : new Intl.DateTimeFormat(locale(), { | |
| 16 | + dateStyle: "medium", | |
| 17 | + timeStyle: "short", | |
| 18 | + }).format(new Date(millis)); | |
| 11 | 19 | } |
| 12 | 20 | |
| 13 | 21 | /** Human line for an event's time window. */ |
| 14 | 22 | export function formatWindow(starts: number | null, ends: number | null): string { |
| 15 | - if (starts === null && ends === null) return "Unscheduled"; | |
| 23 | + if (starts === null && ends === null) return t("unscheduled"); | |
| 16 | 24 | if (starts !== null && ends !== null) |
| 17 | 25 | return `${formatMillis(starts)} → ${formatMillis(ends)}`; |
| 18 | - return starts !== null ? formatMillis(starts) : `Until ${formatMillis(ends)}`; | |
| 26 | + return starts !== null ? formatMillis(starts) : t("until")(formatMillis(ends)); | |
| 19 | 27 | } |
| 20 | 28 | |
| 21 | 29 | /** Unix ms → value for a datetime-local input ("" when null). */ |
| @@ -34,6 +42,18 @@ export function fromInputValue(value: string): number | null { | ||
| 34 | 42 | return value === "" ? null : new Date(value).getTime(); |
| 35 | 43 | } |
| 36 | 44 | |
| 45 | +/** Milliseconds left → "m:ss" (or "h:mm:ss"), floored at zero. */ | |
| 46 | +export function formatCountdown(ms: number): string { | |
| 47 | + const total = Math.max(0, Math.floor(ms / 1000)); | |
| 48 | + const hours = Math.floor(total / 3600); | |
| 49 | + const minutes = Math.floor((total % 3600) / 60); | |
| 50 | + const seconds = total % 60; | |
| 51 | + const pad = (n: number) => String(n).padStart(2, "0"); | |
| 52 | + return hours > 0 | |
| 53 | + ? `${hours}:${pad(minutes)}:${pad(seconds)}` | |
| 54 | + : `${minutes}:${pad(seconds)}`; | |
| 55 | +} | |
| 56 | + | |
| 37 | 57 | /** The local date as "YYYY-MM-DD" — e.g. the max for a birth-date input. */ |
| 38 | 58 | export function today(): string { |
| 39 | 59 | const date = new Date(); |
src/lib/i18n.tsadded+606 -0
| @@ -0,0 +1,606 @@ | ||
| 1 | +// Two-language UI: English and Turkish, picked from what the device asks for | |
| 2 | +// and switchable in one tap (persisted). `t("key")` returns the entry in the | |
| 3 | +// current language — a plain string, or a function for parameterized lines — | |
| 4 | +// and re-runs reactively because it reads the `lang` signal. | |
| 5 | +// | |
| 6 | +// Server-sent error messages pass through untranslated: the backend speaks | |
| 7 | +// English, and inventing translations for unknown strings would lie to users. | |
| 8 | + | |
| 9 | +import { createSignal } from "solid-js"; | |
| 10 | +import type { | |
| 11 | + AttendanceStatus, | |
| 12 | + ExamKind, | |
| 13 | + LiveStudent, | |
| 14 | + QuestionKind, | |
| 15 | + Role, | |
| 16 | +} from "./types"; | |
| 17 | + | |
| 18 | +export type Lang = "en" | "tr"; | |
| 19 | + | |
| 20 | +const STORAGE_KEY = "hezarfen-lang"; | |
| 21 | + | |
| 22 | +function initialLang(): Lang { | |
| 23 | + const stored = localStorage.getItem(STORAGE_KEY); | |
| 24 | + if (stored === "en" || stored === "tr") return stored; | |
| 25 | + return navigator.language.toLowerCase().startsWith("tr") ? "tr" : "en"; | |
| 26 | +} | |
| 27 | + | |
| 28 | +const [lang, setLangSignal] = createSignal<Lang>(initialLang()); | |
| 29 | +export { lang }; | |
| 30 | + | |
| 31 | +// The document language drives CSS text-transform casing rules — Turkish | |
| 32 | +// uppercases i → İ only when the browser knows the text is Turkish. | |
| 33 | +document.documentElement.lang = lang(); | |
| 34 | + | |
| 35 | +export function setLang(next: Lang): void { | |
| 36 | + setLangSignal(next); | |
| 37 | + document.documentElement.lang = next; | |
| 38 | + localStorage.setItem(STORAGE_KEY, next); | |
| 39 | +} | |
| 40 | + | |
| 41 | +/** BCP-47 tag for date formatting; undefined lets English follow the OS. */ | |
| 42 | +export const locale = (): string | undefined => | |
| 43 | + lang() === "tr" ? "tr-TR" : undefined; | |
| 44 | + | |
| 45 | +const en = { | |
| 46 | + // navigation & shell | |
| 47 | + navHome: "Home", | |
| 48 | + navNotes: "Notes", | |
| 49 | + navEvents: "Events", | |
| 50 | + navCourses: "Courses", | |
| 51 | + navExams: "Exams", | |
| 52 | + navMarks: "Marks", | |
| 53 | + navUsers: "Users", | |
| 54 | + logout: "Log out", | |
| 55 | + profileLink: "Profile", | |
| 56 | + otherLanguage: "Türkçe", | |
| 57 | + | |
| 58 | + // shared bits | |
| 59 | + save: "Save", | |
| 60 | + cancel: "Cancel", | |
| 61 | + close: "Close", | |
| 62 | + edit: "Edit", | |
| 63 | + remove: "Remove", | |
| 64 | + apply: "Apply", | |
| 65 | + you: " (you)", | |
| 66 | + title: "Title", | |
| 67 | + description: "Description", | |
| 68 | + status: "Status", | |
| 69 | + reallyDelete: "Really delete?", | |
| 70 | + reallyRemove: "Really remove?", | |
| 71 | + somethingWrong: "something went wrong", | |
| 72 | + retryIn: (s: number) => `retry in ${s}s`, | |
| 73 | + networkError: "network error — is the backend up?", | |
| 74 | + unscheduled: "Unscheduled", | |
| 75 | + until: (time: string) => `Until ${time}`, | |
| 76 | + | |
| 77 | + // login | |
| 78 | + loginWelcome: "Welcome back — log in to continue.", | |
| 79 | + registerWelcome: "Create an account to get started.", | |
| 80 | + username: "Username", | |
| 81 | + password: "Password", | |
| 82 | + showPassword: "Show password", | |
| 83 | + hidePassword: "Hide password", | |
| 84 | + atLeastChars: (n: number) => `At least ${n} characters.`, | |
| 85 | + logIn: "Log in", | |
| 86 | + createAccount: "Create account", | |
| 87 | + switchToRegister: "New here? Register", | |
| 88 | + switchToLogin: "Have an account? Log in", | |
| 89 | + | |
| 90 | + // home | |
| 91 | + greeting: (name: string, hour: number) => | |
| 92 | + `Good ${hour < 12 ? "morning" : hour < 18 ? "afternoon" : "evening"}, ${name}`, | |
| 93 | + statNotes: "Notes", | |
| 94 | + statUpcoming: "Upcoming events", | |
| 95 | + statMyCourses: "My courses", | |
| 96 | + statAverage: "Average", | |
| 97 | + upcomingEvents: "Upcoming events", | |
| 98 | + myCourses: "My courses", | |
| 99 | + viewAll: "View all", | |
| 100 | + nothingScheduled: "Nothing scheduled.", | |
| 101 | + notEnrolledYet: "Not enrolled in any course yet.", | |
| 102 | + | |
| 103 | + // notes | |
| 104 | + notesTitle: "Notes", | |
| 105 | + notesSub: "Your personal scratchpad — visible only to you.", | |
| 106 | + newNote: "New note", | |
| 107 | + content: "Content", | |
| 108 | + writeSomething: "Write something…", | |
| 109 | + addNote: "Add note", | |
| 110 | + noNotesYet: "No notes yet — write your first one.", | |
| 111 | + deleteNote: "Delete", | |
| 112 | + | |
| 113 | + // events | |
| 114 | + eventsTitle: "Events", | |
| 115 | + eventsSub: "What's happening — open one to see or mark attendance.", | |
| 116 | + newEvent: "New event", | |
| 117 | + starts: "Starts", | |
| 118 | + ends: "Ends", | |
| 119 | + addEvent: "Add event", | |
| 120 | + noEventsYet: "No events yet.", | |
| 121 | + attendance: "Attendance", | |
| 122 | + iAm: (status: AttendanceStatus) => | |
| 123 | + ({ present: "I'm here", absent: "I'm absent", late: "I'm late", excused: "I'm excused" })[status], | |
| 124 | + attendanceWord: (status: AttendanceStatus) => | |
| 125 | + ({ present: "present", absent: "absent", late: "late", excused: "excused" })[status], | |
| 126 | + person: "Person", | |
| 127 | + markUser: "Mark user", | |
| 128 | + nobodyMarkedYet: "Nobody marked yet.", | |
| 129 | + userCol: "User", | |
| 130 | + deleteEvent: "Delete event", | |
| 131 | + reallyDeleteEvent: "Really delete event?", | |
| 132 | + eventMissing: "This event does not exist.", | |
| 133 | + eventLoadFailed: "Failed to load the event.", | |
| 134 | + | |
| 135 | + // courses | |
| 136 | + coursesTitle: "Courses", | |
| 137 | + coursesSub: "Everything on offer — your enrollments are tagged.", | |
| 138 | + newCourse: "New course", | |
| 139 | + addCourse: "Add course", | |
| 140 | + noCoursesYet: "No courses yet.", | |
| 141 | + enrolledBadge: "enrolled", | |
| 142 | + deleteCourse: "Delete course", | |
| 143 | + reallyDeleteCourse: "Really delete course?", | |
| 144 | + courseMissing: "This course does not exist.", | |
| 145 | + courseLoadFailed: "Failed to load the course.", | |
| 146 | + roster: "Roster", | |
| 147 | + student: "Student", | |
| 148 | + enrolledBy: "Enrolled by", | |
| 149 | + enroll: "Enroll", | |
| 150 | + unenroll: "Unenroll", | |
| 151 | + nobodyEnrolledYet: "Nobody enrolled yet.", | |
| 152 | + | |
| 153 | + // exams | |
| 154 | + examsTitle: "Exams", | |
| 155 | + examsSubAll: "All exams across courses.", | |
| 156 | + examsSubCreate: "New ones are created inside a course.", | |
| 157 | + coursePrefix: "Course:", | |
| 158 | + newExam: "New exam", | |
| 159 | + addExam: "Add exam", | |
| 160 | + noExamsYet: "No exams yet.", | |
| 161 | + kind: "Kind", | |
| 162 | + weight: "Weight", | |
| 163 | + kindWord: (kind: ExamKind) => | |
| 164 | + ({ homework: "homework", quiz: "quiz", midterm: "midterm", final: "final", project: "project", oral: "oral" })[kind], | |
| 165 | + weightBadge: (n: number) => `counts ×${n}`, | |
| 166 | + weightTitle: "how many times this exam counts toward the course average", | |
| 167 | + deleteExam: "Delete exam", | |
| 168 | + reallyDeleteExam: "Really delete exam?", | |
| 169 | + examMissing: "This exam does not exist.", | |
| 170 | + examLoadFailed: "Failed to load the exam.", | |
| 171 | + myResult: "My result", | |
| 172 | + notGradedYet: "Not graded yet.", | |
| 173 | + statistics: "Statistics", | |
| 174 | + gradedStat: "Graded", | |
| 175 | + averageStat: "Average", | |
| 176 | + minStat: "Min", | |
| 177 | + maxStat: "Max", | |
| 178 | + results: "Results", | |
| 179 | + mark0100: "Mark (0–100)", | |
| 180 | + gradeAction: "Grade", | |
| 181 | + noResultsYet: "No results yet.", | |
| 182 | + | |
| 183 | + // exam scheduling | |
| 184 | + timing: "Timing", | |
| 185 | + timingNone: "No timer — held outside the app", | |
| 186 | + timingSync: "Live — everyone at the same time", | |
| 187 | + timingAsync: "Flexible — own timer inside a window", | |
| 188 | + opens: "Opens", | |
| 189 | + closes: "Closes", | |
| 190 | + minutesPerStudent: "Minutes per student", | |
| 191 | + syncHint: "Students sit it together: everyone's time runs out when the exam closes.", | |
| 192 | + asyncHint: "Each student's own timer starts when they enter, inside the open window.", | |
| 193 | + endsAfterStarts: "The closing time must be after the opening time", | |
| 194 | + | |
| 195 | + // sitting card | |
| 196 | + examTime: "Exam time", | |
| 197 | + phaseWord: (phase: "upcoming" | "open" | "closed") => | |
| 198 | + ({ upcoming: "Opens soon", open: "Open now", closed: "Closed" })[phase], | |
| 199 | + minutesEach: (n: number) => `${n} minutes each`, | |
| 200 | + turnedInAt: (time: string) => `Turned in ✓ ${time}`, | |
| 201 | + seeMyAnswers: "See my answers", | |
| 202 | + timeRanOut: "Time ran out — everything saved up to the end still counts.", | |
| 203 | + continueExam: "Continue exam", | |
| 204 | + answeredOf: (a: number, b: number) => `${a} / ${b} answered`, | |
| 205 | + timeLeftShort: (countdown: string) => `${countdown} left`, | |
| 206 | + enterExam: "Enter exam", | |
| 207 | + startTimerConfirm: (n: number) => `Start now? Your ${n} minutes begin`, | |
| 208 | + opensAt: (time: string) => `Opens ${time}.`, | |
| 209 | + examOver: "This exam is over.", | |
| 210 | + | |
| 211 | + // exam room | |
| 212 | + notEnteredYet: "You haven't entered this exam yet.", | |
| 213 | + backToExam: "Back to the exam", | |
| 214 | + turnIn: "Turn in", | |
| 215 | + turnInNow: "Turn in now?", | |
| 216 | + turnInUnanswered: (n: number) => `Turn in with ${n} unanswered?`, | |
| 217 | + turnedInBanner: (time: string) => | |
| 218 | + `Turned in ✓ ${time} — you can still read your answers below.`, | |
| 219 | + timeUpBanner: "Time is up. Everything saved before the end still counts.", | |
| 220 | + noQuestionsRoom: "No questions here — your teacher grades this exam by hand.", | |
| 221 | + writeAnswerHere: "Write your answer here…", | |
| 222 | + savingState: "Saving…", | |
| 223 | + savedState: "Saved ✓", | |
| 224 | + notSavedState: "Not saved!", | |
| 225 | + turnedInChip: "Turned in", | |
| 226 | + timeUpChip: "Time up", | |
| 227 | + pts: (n: number) => `${n} pts`, | |
| 228 | + savingFailed: "saving failed", | |
| 229 | + | |
| 230 | + // question authoring | |
| 231 | + questionsTitle: "Questions", | |
| 232 | + totalPoints: (n: number) => `${n} points`, | |
| 233 | + addQuestion: "Add question", | |
| 234 | + noQuestionsYet: "No questions yet — students will see an empty exam.", | |
| 235 | + questionLabel: "Question", | |
| 236 | + answerType: "Answer type", | |
| 237 | + answerTypeChoice: "Pick one option", | |
| 238 | + answerTypeText: "Written answer", | |
| 239 | + points: "Points", | |
| 240 | + questionKindWord: (kind: QuestionKind) => | |
| 241 | + ({ choice: "choice", text: "written" })[kind], | |
| 242 | + tickRightAnswer: "Tick the circle next to the right answer.", | |
| 243 | + optionN: (n: number) => `Option ${n}`, | |
| 244 | + optionIsRight: (n: number) => `Option ${n} is the right answer`, | |
| 245 | + removeOption: "Remove this option", | |
| 246 | + addOption: "Add option", | |
| 247 | + saveQuestion: "Save question", | |
| 248 | + | |
| 249 | + // live monitor | |
| 250 | + liveMonitor: "Live monitor", | |
| 251 | + countEnrolled: (n: number) => `${n} enrolled`, | |
| 252 | + countWriting: (n: number) => `${n} writing`, | |
| 253 | + countTurnedIn: (n: number) => `${n} turned in`, | |
| 254 | + countNotStarted: (n: number) => `${n} not started`, | |
| 255 | + countTimeUp: (n: number) => `${n} time up`, | |
| 256 | + countGraded: (n: number) => `${n} graded`, | |
| 257 | + liveStatusWord: (status: LiveStudent["status"]) => | |
| 258 | + ({ not_started: "Not started", in_progress: "Writing", submitted: "Turned in", expired: "Time up" })[status], | |
| 259 | + answeredCol: "Answered", | |
| 260 | + timeLeftCol: "Time left", | |
| 261 | + lastSaveCol: "Last save", | |
| 262 | + markCol: "Mark", | |
| 263 | + review: "Review", | |
| 264 | + nobodyEnrolledCourse: "Nobody is enrolled in this course yet.", | |
| 265 | + sheetTitle: (name: string) => `${name}'s answers`, | |
| 266 | + noAnswer: "No answer.", | |
| 267 | + rightAnswerIs: (text: string) => ` ✗ (right: ${text})`, | |
| 268 | + autoScoreLine: (earned: number, possible: number) => | |
| 269 | + `Auto-score over choice questions: ${earned} / ${possible} points — a suggestion, the mark below is yours to give.`, | |
| 270 | + noQuestionsSheet: "This exam has no questions.", | |
| 271 | + agoSeconds: (s: number) => `${s}s ago`, | |
| 272 | + agoMinutes: (m: number) => `${m}m ago`, | |
| 273 | + | |
| 274 | + // marks | |
| 275 | + marksTitle: "My marks", | |
| 276 | + marksSub: "Graded exams per course, weighted averages included.", | |
| 277 | + marksLoadFailed: "Failed to load your marks.", | |
| 278 | + overallAverage: "Overall average", | |
| 279 | + courseAverageTitle: "weighted course average", | |
| 280 | + overallAverageTitle: "mean of the course averages", | |
| 281 | + studentLookup: "Student lookup", | |
| 282 | + showMarks: "Show marks", | |
| 283 | + reportFor: (name: string) => `Report for ${name}`, | |
| 284 | + notEnrolledAny: "Not enrolled in any course.", | |
| 285 | + nothingGradedYet: "Nothing graded yet.", | |
| 286 | + examCol: "Exam", | |
| 287 | + | |
| 288 | + // profile & users | |
| 289 | + personalInfo: "Personal info", | |
| 290 | + leaveEmptyToClear: "Leave a field empty to clear it.", | |
| 291 | + nameField: "Name", | |
| 292 | + surnameField: "Surname", | |
| 293 | + emailField: "Email", | |
| 294 | + phoneField: "Phone", | |
| 295 | + birthDateField: "Birth date", | |
| 296 | + savedDot: "Saved.", | |
| 297 | + phoneTitle: (min: number, max: number) => | |
| 298 | + `${min} to ${max} digits; +, spaces, dashes, and parentheses are allowed`, | |
| 299 | + usersTitle: "Users", | |
| 300 | + usersSub: "Every account, with roles and personal records.", | |
| 301 | + adminsOnly: "Admins only.", | |
| 302 | + idCol: "Id", | |
| 303 | + contactCol: "Contact", | |
| 304 | + bornCol: "Born", | |
| 305 | + roleCol: "Role", | |
| 306 | + roleWord: (role: Role) => | |
| 307 | + ({ student: "student", teacher: "teacher", manager: "manager", admin: "admin" })[role], | |
| 308 | + saveProfile: "Save profile", | |
| 309 | + noUsers: "No users.", | |
| 310 | + | |
| 311 | + // user picker | |
| 312 | + typeAName: "Type a name…", | |
| 313 | + nobodyFound: "Nobody found.", | |
| 314 | + pickFromList: "Pick a person from the list", | |
| 315 | + | |
| 316 | + // not found | |
| 317 | + pageFlewAway: "This page flew away.", | |
| 318 | + backHome: "Back home", | |
| 319 | +}; | |
| 320 | + | |
| 321 | +type Dict = typeof en; | |
| 322 | + | |
| 323 | +const tr: Dict = { | |
| 324 | + // navigation & shell | |
| 325 | + navHome: "Ana sayfa", | |
| 326 | + navNotes: "Not defteri", | |
| 327 | + navEvents: "Etkinlikler", | |
| 328 | + navCourses: "Dersler", | |
| 329 | + navExams: "Sınavlar", | |
| 330 | + navMarks: "Karnem", | |
| 331 | + navUsers: "Kullanıcılar", | |
| 332 | + logout: "Çıkış yap", | |
| 333 | + profileLink: "Profilim", | |
| 334 | + otherLanguage: "English", | |
| 335 | + | |
| 336 | + // shared bits | |
| 337 | + save: "Kaydet", | |
| 338 | + cancel: "Vazgeç", | |
| 339 | + close: "Kapat", | |
| 340 | + edit: "Düzenle", | |
| 341 | + remove: "Kaldır", | |
| 342 | + apply: "Uygula", | |
| 343 | + you: " (sen)", | |
| 344 | + title: "Başlık", | |
| 345 | + description: "Açıklama", | |
| 346 | + status: "Durum", | |
| 347 | + reallyDelete: "Silinsin mi?", | |
| 348 | + reallyRemove: "Kaldırılsın mı?", | |
| 349 | + somethingWrong: "bir şeyler ters gitti", | |
| 350 | + retryIn: (s: number) => `${s} sn sonra tekrar dene`, | |
| 351 | + networkError: "ağ hatası — sunucu çalışıyor mu?", | |
| 352 | + unscheduled: "Tarihsiz", | |
| 353 | + until: (time: string) => `Bitiş: ${time}`, | |
| 354 | + | |
| 355 | + // login | |
| 356 | + loginWelcome: "Tekrar hoş geldin — devam etmek için giriş yap.", | |
| 357 | + registerWelcome: "Başlamak için bir hesap oluştur.", | |
| 358 | + username: "Kullanıcı adı", | |
| 359 | + password: "Şifre", | |
| 360 | + showPassword: "Şifreyi göster", | |
| 361 | + hidePassword: "Şifreyi gizle", | |
| 362 | + atLeastChars: (n: number) => `En az ${n} karakter.`, | |
| 363 | + logIn: "Giriş yap", | |
| 364 | + createAccount: "Hesap oluştur", | |
| 365 | + switchToRegister: "Yeni misin? Kayıt ol", | |
| 366 | + switchToLogin: "Hesabın var mı? Giriş yap", | |
| 367 | + | |
| 368 | + // home | |
| 369 | + greeting: (name: string, hour: number) => | |
| 370 | + hour < 12 ? `Günaydın ${name}` : hour < 18 ? `İyi günler ${name}` : `İyi akşamlar ${name}`, | |
| 371 | + statNotes: "Not defteri", | |
| 372 | + statUpcoming: "Yaklaşan etkinlik", | |
| 373 | + statMyCourses: "Derslerim", | |
| 374 | + statAverage: "Ortalamam", | |
| 375 | + upcomingEvents: "Yaklaşan etkinlikler", | |
| 376 | + myCourses: "Derslerim", | |
| 377 | + viewAll: "Tümünü gör", | |
| 378 | + nothingScheduled: "Planlanmış bir şey yok.", | |
| 379 | + notEnrolledYet: "Henüz bir derse kayıtlı değilsin.", | |
| 380 | + | |
| 381 | + // notes | |
| 382 | + notesTitle: "Not defteri", | |
| 383 | + notesSub: "Kişisel defterin — sadece sen görürsün.", | |
| 384 | + newNote: "Yeni not", | |
| 385 | + content: "İçerik", | |
| 386 | + writeSomething: "Bir şeyler yaz…", | |
| 387 | + addNote: "Not ekle", | |
| 388 | + noNotesYet: "Henüz not yok — ilkini yaz.", | |
| 389 | + deleteNote: "Sil", | |
| 390 | + | |
| 391 | + // events | |
| 392 | + eventsTitle: "Etkinlikler", | |
| 393 | + eventsSub: "Neler oluyor — yoklamayı görmek ya da işaretlemek için birine gir.", | |
| 394 | + newEvent: "Yeni etkinlik", | |
| 395 | + starts: "Başlangıç", | |
| 396 | + ends: "Bitiş", | |
| 397 | + addEvent: "Etkinlik ekle", | |
| 398 | + noEventsYet: "Henüz etkinlik yok.", | |
| 399 | + attendance: "Yoklama", | |
| 400 | + iAm: (status: AttendanceStatus) => | |
| 401 | + ({ present: "Buradayım", absent: "Yokum", late: "Geç kaldım", excused: "İzinliyim" })[status], | |
| 402 | + attendanceWord: (status: AttendanceStatus) => | |
| 403 | + ({ present: "geldi", absent: "gelmedi", late: "geç", excused: "izinli" })[status], | |
| 404 | + person: "Kişi", | |
| 405 | + markUser: "Kişiyi işaretle", | |
| 406 | + nobodyMarkedYet: "Henüz kimse işaretlenmedi.", | |
| 407 | + userCol: "Kullanıcı", | |
| 408 | + deleteEvent: "Etkinliği sil", | |
| 409 | + reallyDeleteEvent: "Etkinlik silinsin mi?", | |
| 410 | + eventMissing: "Böyle bir etkinlik yok.", | |
| 411 | + eventLoadFailed: "Etkinlik yüklenemedi.", | |
| 412 | + | |
| 413 | + // courses | |
| 414 | + coursesTitle: "Dersler", | |
| 415 | + coursesSub: "Tüm dersler — kayıtlı oldukların işaretli.", | |
| 416 | + newCourse: "Yeni ders", | |
| 417 | + addCourse: "Ders ekle", | |
| 418 | + noCoursesYet: "Henüz ders yok.", | |
| 419 | + enrolledBadge: "kayıtlısın", | |
| 420 | + deleteCourse: "Dersi sil", | |
| 421 | + reallyDeleteCourse: "Ders silinsin mi?", | |
| 422 | + courseMissing: "Böyle bir ders yok.", | |
| 423 | + courseLoadFailed: "Ders yüklenemedi.", | |
| 424 | + roster: "Sınıf listesi", | |
| 425 | + student: "Öğrenci", | |
| 426 | + enrolledBy: "Kaydeden", | |
| 427 | + enroll: "Derse ekle", | |
| 428 | + unenroll: "Dersten çıkar", | |
| 429 | + nobodyEnrolledYet: "Henüz kimse kayıtlı değil.", | |
| 430 | + | |
| 431 | + // exams | |
| 432 | + examsTitle: "Sınavlar", | |
| 433 | + examsSubAll: "Bütün derslerin sınavları.", | |
| 434 | + examsSubCreate: "Yeni sınav ders sayfasında açılır.", | |
| 435 | + coursePrefix: "Ders:", | |
| 436 | + newExam: "Yeni sınav", | |
| 437 | + addExam: "Sınav ekle", | |
| 438 | + noExamsYet: "Henüz sınav yok.", | |
| 439 | + kind: "Tür", | |
| 440 | + weight: "Ağırlık", | |
| 441 | + kindWord: (kind: ExamKind) => | |
| 442 | + ({ homework: "ödev", quiz: "küçük sınav", midterm: "ara sınav", final: "dönem sonu", project: "proje", oral: "sözlü" })[kind], | |
| 443 | + weightBadge: (n: number) => `×${n} sayılır`, | |
| 444 | + weightTitle: "bu sınav ders ortalamasına kaç kez sayılır", | |
| 445 | + deleteExam: "Sınavı sil", | |
| 446 | + reallyDeleteExam: "Sınav silinsin mi?", | |
| 447 | + examMissing: "Böyle bir sınav yok.", | |
| 448 | + examLoadFailed: "Sınav yüklenemedi.", | |
| 449 | + myResult: "Sonucum", | |
| 450 | + notGradedYet: "Henüz notlanmadı.", | |
| 451 | + statistics: "İstatistik", | |
| 452 | + gradedStat: "Notlanan", | |
| 453 | + averageStat: "Ortalama", | |
| 454 | + minStat: "En düşük", | |
| 455 | + maxStat: "En yüksek", | |
| 456 | + results: "Sonuçlar", | |
| 457 | + mark0100: "Not (0–100)", | |
| 458 | + gradeAction: "Notla", | |
| 459 | + noResultsYet: "Henüz sonuç yok.", | |
| 460 | + | |
| 461 | + // exam scheduling | |
| 462 | + timing: "Zamanlama", | |
| 463 | + timingNone: "Zamansız — uygulama dışında yapılır", | |
| 464 | + timingSync: "Canlı — herkes aynı anda", | |
| 465 | + timingAsync: "Esnek — açık aralıkta kendi süresi", | |
| 466 | + opens: "Açılış", | |
| 467 | + closes: "Kapanış", | |
| 468 | + minutesPerStudent: "Öğrenci başına dakika", | |
| 469 | + syncHint: "Herkes birlikte yazar: süre, sınav kapanınca herkes için biter.", | |
| 470 | + asyncHint: "Her öğrencinin süresi, açık aralık içinde girdiği anda başlar.", | |
| 471 | + endsAfterStarts: "Kapanış, açılıştan sonra olmalı", | |
| 472 | + | |
| 473 | + // sitting card | |
| 474 | + examTime: "Sınav zamanı", | |
| 475 | + phaseWord: (phase: "upcoming" | "open" | "closed") => | |
| 476 | + ({ upcoming: "Yakında açılır", open: "Şimdi açık", closed: "Kapandı" })[phase], | |
| 477 | + minutesEach: (n: number) => `herkese ${n} dakika`, | |
| 478 | + turnedInAt: (time: string) => `Teslim edildi ✓ ${time}`, | |
| 479 | + seeMyAnswers: "Cevaplarımı gör", | |
| 480 | + timeRanOut: "Süre doldu — sona kadar kaydedilenler geçerli.", | |
| 481 | + continueExam: "Sınava devam et", | |
| 482 | + answeredOf: (a: number, b: number) => `${a} / ${b} cevaplandı`, | |
| 483 | + timeLeftShort: (countdown: string) => `${countdown} kaldı`, | |
| 484 | + enterExam: "Sınava gir", | |
| 485 | + startTimerConfirm: (n: number) => `Başlasın mı? ${n} dakikan şimdi başlar`, | |
| 486 | + opensAt: (time: string) => `${time} açılır.`, | |
| 487 | + examOver: "Bu sınav bitti.", | |
| 488 | + | |
| 489 | + // exam room | |
| 490 | + notEnteredYet: "Bu sınava henüz girmedin.", | |
| 491 | + backToExam: "Sınav sayfasına dön", | |
| 492 | + turnIn: "Teslim et", | |
| 493 | + turnInNow: "Teslim edilsin mi?", | |
| 494 | + turnInUnanswered: (n: number) => `${n} soru boş — teslim edilsin mi?`, | |
| 495 | + turnedInBanner: (time: string) => | |
| 496 | + `Teslim edildi ✓ ${time} — cevaplarını aşağıda görebilirsin.`, | |
| 497 | + timeUpBanner: "Süre doldu. Bitmeden kaydedilen her şey geçerli.", | |
| 498 | + noQuestionsRoom: "Burada soru yok — öğretmenin bu sınavı elden notlayacak.", | |
| 499 | + writeAnswerHere: "Cevabını buraya yaz…", | |
| 500 | + savingState: "Kaydediliyor…", | |
| 501 | + savedState: "Kaydedildi ✓", | |
| 502 | + notSavedState: "Kaydedilemedi!", | |
| 503 | + turnedInChip: "Teslim edildi", | |
| 504 | + timeUpChip: "Süre doldu", | |
| 505 | + pts: (n: number) => `${n} puan`, | |
| 506 | + savingFailed: "kaydedilemedi", | |
| 507 | + | |
| 508 | + // question authoring | |
| 509 | + questionsTitle: "Sorular", | |
| 510 | + totalPoints: (n: number) => `${n} puan`, | |
| 511 | + addQuestion: "Soru ekle", | |
| 512 | + noQuestionsYet: "Henüz soru yok — öğrenciler boş sınav görür.", | |
| 513 | + questionLabel: "Soru", | |
| 514 | + answerType: "Cevap türü", | |
| 515 | + answerTypeChoice: "Şıklı (tek doğru)", | |
| 516 | + answerTypeText: "Yazılı cevap", | |
| 517 | + points: "Puan", | |
| 518 | + questionKindWord: (kind: QuestionKind) => | |
| 519 | + ({ choice: "şıklı", text: "yazılı" })[kind], | |
| 520 | + tickRightAnswer: "Doğru cevabın yanındaki yuvarlağı işaretle.", | |
| 521 | + optionN: (n: number) => `Seçenek ${n}`, | |
| 522 | + optionIsRight: (n: number) => `Doğru cevap ${n}. seçenek`, | |
| 523 | + removeOption: "Bu seçeneği kaldır", | |
| 524 | + addOption: "Seçenek ekle", | |
| 525 | + saveQuestion: "Soruyu kaydet", | |
| 526 | + | |
| 527 | + // live monitor | |
| 528 | + liveMonitor: "Canlı izleme", | |
| 529 | + countEnrolled: (n: number) => `${n} kayıtlı`, | |
| 530 | + countWriting: (n: number) => `${n} yazıyor`, | |
| 531 | + countTurnedIn: (n: number) => `${n} teslim etti`, | |
| 532 | + countNotStarted: (n: number) => `${n} başlamadı`, | |
| 533 | + countTimeUp: (n: number) => `${n} süresi doldu`, | |
| 534 | + countGraded: (n: number) => `${n} notlandı`, | |
| 535 | + liveStatusWord: (status: LiveStudent["status"]) => | |
| 536 | + ({ not_started: "Başlamadı", in_progress: "Yazıyor", submitted: "Teslim etti", expired: "Süresi doldu" })[status], | |
| 537 | + answeredCol: "Cevaplanan", | |
| 538 | + timeLeftCol: "Kalan süre", | |
| 539 | + lastSaveCol: "Son kayıt", | |
| 540 | + markCol: "Not", | |
| 541 | + review: "İncele", | |
| 542 | + nobodyEnrolledCourse: "Bu derse henüz kimse kayıtlı değil.", | |
| 543 | + sheetTitle: (name: string) => `${name} — cevaplar`, | |
| 544 | + noAnswer: "Cevap yok.", | |
| 545 | + rightAnswerIs: (text: string) => ` ✗ (doğrusu: ${text})`, | |
| 546 | + autoScoreLine: (earned: number, possible: number) => | |
| 547 | + `Şıklı sorularda otomatik puan: ${earned} / ${possible} — sadece bir öneri, aşağıdaki notu sen verirsin.`, | |
| 548 | + noQuestionsSheet: "Bu sınavda soru yok.", | |
| 549 | + agoSeconds: (s: number) => `${s} sn önce`, | |
| 550 | + agoMinutes: (m: number) => `${m} dk önce`, | |
| 551 | + | |
| 552 | + // marks | |
| 553 | + marksTitle: "Karnem", | |
| 554 | + marksSub: "Ders ders notların, ağırlıklı ortalamalarınla birlikte.", | |
| 555 | + marksLoadFailed: "Karnen yüklenemedi.", | |
| 556 | + overallAverage: "Genel ortalama", | |
| 557 | + courseAverageTitle: "ağırlıklı ders ortalaması", | |
| 558 | + overallAverageTitle: "ders ortalamalarının ortalaması", | |
| 559 | + studentLookup: "Öğrenci ara", | |
| 560 | + showMarks: "Karneyi gör", | |
| 561 | + reportFor: (name: string) => `${name} — karne`, | |
| 562 | + notEnrolledAny: "Hiçbir derse kayıtlı değil.", | |
| 563 | + nothingGradedYet: "Henüz not girilmedi.", | |
| 564 | + examCol: "Sınav", | |
| 565 | + | |
| 566 | + // profile & users | |
| 567 | + personalInfo: "Kişisel bilgiler", | |
| 568 | + leaveEmptyToClear: "Boş bıraktığın alan silinir.", | |
| 569 | + nameField: "Ad", | |
| 570 | + surnameField: "Soyad", | |
| 571 | + emailField: "E-posta", | |
| 572 | + phoneField: "Telefon", | |
| 573 | + birthDateField: "Doğum tarihi", | |
| 574 | + savedDot: "Kaydedildi.", | |
| 575 | + phoneTitle: (min: number, max: number) => | |
| 576 | + `${min}–${max} rakam; +, boşluk, tire ve parantez kullanılabilir`, | |
| 577 | + usersTitle: "Kullanıcılar", | |
| 578 | + usersSub: "Bütün hesaplar: roller ve kişisel kayıtlar.", | |
| 579 | + adminsOnly: "Sadece adminler.", | |
| 580 | + idCol: "Kimlik", | |
| 581 | + contactCol: "İletişim", | |
| 582 | + bornCol: "Doğum", | |
| 583 | + roleCol: "Rol", | |
| 584 | + roleWord: (role: Role) => | |
| 585 | + ({ student: "öğrenci", teacher: "öğretmen", manager: "müdür", admin: "admin" })[role], | |
| 586 | + saveProfile: "Profili kaydet", | |
| 587 | + noUsers: "Kullanıcı yok.", | |
| 588 | + | |
| 589 | + // user picker | |
| 590 | + typeAName: "Bir isim yaz…", | |
| 591 | + nobodyFound: "Kimse bulunamadı.", | |
| 592 | + pickFromList: "Listeden birini seç", | |
| 593 | + | |
| 594 | + // not found | |
| 595 | + pageFlewAway: "Bu sayfa uçup gitmiş.", | |
| 596 | + backHome: "Ana sayfaya dön", | |
| 597 | +}; | |
| 598 | + | |
| 599 | +/** | |
| 600 | + * The current-language entry for `key`: a string for plain lines, a function | |
| 601 | + * for parameterized ones (call it: `t("pts")(10)`). Reactive — any JSX or | |
| 602 | + * memo reading it re-renders on language switch. | |
| 603 | + */ | |
| 604 | +export function t<K extends keyof Dict>(key: K): Dict[K] { | |
| 605 | + return (lang() === "tr" ? tr : en)[key]; | |
| 606 | +} |
src/lib/types.tsmodified+149 -6
| @@ -22,6 +22,14 @@ export interface User { | ||
| 22 | 22 | birth_date: string | null; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | +/** Who a row points at: the id plus something a human can read. */ | |
| 26 | +export interface PersonRef { | |
| 27 | + id: string; | |
| 28 | + username: string; | |
| 29 | + /** "Name Surname" when the profile has either; null otherwise. */ | |
| 30 | + display_name: string | null; | |
| 31 | +} | |
| 32 | + | |
| 25 | 33 | export interface Note { |
| 26 | 34 | id: string; |
| 27 | 35 | title: string; |
| @@ -44,9 +52,9 @@ export type AttendanceStatus = (typeof ATTENDANCE_STATUSES)[number]; | ||
| 44 | 52 | export interface Attendance { |
| 45 | 53 | id: string; |
| 46 | 54 | event: string; |
| 47 | - user: string; | |
| 55 | + user: PersonRef; | |
| 48 | 56 | status: AttendanceStatus; |
| 49 | - marked_by: string; | |
| 57 | + marked_by: PersonRef; | |
| 50 | 58 | } |
| 51 | 59 | |
| 52 | 60 | export interface Course { |
| @@ -59,8 +67,8 @@ export interface Course { | ||
| 59 | 67 | export interface Enrollment { |
| 60 | 68 | id: string; |
| 61 | 69 | course: string; |
| 62 | - user: string; | |
| 63 | - enrolled_by: string; | |
| 70 | + user: PersonRef; | |
| 71 | + enrolled_by: PersonRef; | |
| 64 | 72 | } |
| 65 | 73 | |
| 66 | 74 | /** Informational metadata only — `weight` drives the course average. */ |
| @@ -74,6 +82,12 @@ export const EXAM_KINDS = [ | ||
| 74 | 82 | ] as const; |
| 75 | 83 | export type ExamKind = (typeof EXAM_KINDS)[number]; |
| 76 | 84 | |
| 85 | +/** | |
| 86 | + * How a scheduled exam is sat: `sync` (everyone shares one fixed window) or | |
| 87 | + * `async` (each student starts inside the window and gets `duration_ms`). | |
| 88 | + */ | |
| 89 | +export type ExamMode = "sync" | "async"; | |
| 90 | + | |
| 77 | 91 | export interface Exam { |
| 78 | 92 | id: string; |
| 79 | 93 | creator: string; |
| @@ -83,15 +97,137 @@ export interface Exam { | ||
| 83 | 97 | kind: ExamKind; |
| 84 | 98 | /** Counts `weight` times into the course average, 1–100. */ |
| 85 | 99 | weight: number; |
| 100 | + /** Null on an unscheduled (offline-graded) exam — so are the fields below. */ | |
| 101 | + mode: ExamMode | null; | |
| 102 | + /** Window open, UTC unix-milliseconds. */ | |
| 103 | + starts_at: number | null; | |
| 104 | + /** Window close, UTC unix-milliseconds. */ | |
| 105 | + ends_at: number | null; | |
| 106 | + /** Per-student time budget in milliseconds (async exams only). */ | |
| 107 | + duration_ms: number | null; | |
| 108 | +} | |
| 109 | + | |
| 110 | +export type AttemptStatus = "in_progress" | "submitted" | "expired"; | |
| 111 | + | |
| 112 | +/** The caller's sitting of an exam; `now` is the server clock at response time. */ | |
| 113 | +export interface ExamAttempt { | |
| 114 | + id: string; | |
| 115 | + exam: string; | |
| 116 | + user: PersonRef; | |
| 117 | + started_at: number; | |
| 118 | + finished_at: number | null; | |
| 119 | + status: AttemptStatus; | |
| 120 | + /** When the attempt closes, recomputed live from the exam's schedule. */ | |
| 121 | + deadline: number | null; | |
| 122 | + /** `deadline - now`, floored at 0; null unless in progress. */ | |
| 123 | + remaining_ms: number | null; | |
| 124 | + /** The caller's mark, once graded. */ | |
| 125 | + mark: number | null; | |
| 126 | + answered: number; | |
| 127 | + question_count: number; | |
| 128 | + /** Server clock, UTC unix-milliseconds. */ | |
| 129 | + now: number; | |
| 130 | +} | |
| 131 | + | |
| 132 | +export type QuestionKind = "choice" | "text"; | |
| 133 | + | |
| 134 | +/** A question as its author sees it — `correct` included. Teacher+ only. */ | |
| 135 | +export interface ExamQuestion { | |
| 136 | + id: string; | |
| 137 | + exam: string; | |
| 138 | + text: string; | |
| 139 | + kind: QuestionKind; | |
| 140 | + /** This question's share of the auto-score, 1–100. */ | |
| 141 | + points: number; | |
| 142 | + /** The options of a `choice` question (2–10); null for `text`. */ | |
| 143 | + choices: string[] | null; | |
| 144 | + /** Zero-based index of the right option; null for `text`. */ | |
| 145 | + correct: number | null; | |
| 146 | +} | |
| 147 | + | |
| 148 | +/** A student's own saved answer, embedded in their question view. */ | |
| 149 | +export interface AnswerState { | |
| 150 | + selected: number | null; | |
| 151 | + text: string | null; | |
| 152 | + updated_at: number; | |
| 153 | +} | |
| 154 | + | |
| 155 | +/** A question as the sitting student sees it: no `correct`, answer embedded. */ | |
| 156 | +export interface AttemptQuestion { | |
| 157 | + id: string; | |
| 158 | + text: string; | |
| 159 | + kind: QuestionKind; | |
| 160 | + points: number; | |
| 161 | + choices: string[] | null; | |
| 162 | + answer: AnswerState | null; | |
| 163 | +} | |
| 164 | + | |
| 165 | +export interface AnswerSaved { | |
| 166 | + question: string; | |
| 167 | + selected: number | null; | |
| 168 | + text: string | null; | |
| 169 | + updated_at: number; | |
| 170 | +} | |
| 171 | + | |
| 172 | +/** One roster row of the teacher's live exam monitor. */ | |
| 173 | +export interface LiveStudent { | |
| 174 | + user: PersonRef; | |
| 175 | + status: "not_started" | AttemptStatus; | |
| 176 | + started_at: number | null; | |
| 177 | + finished_at: number | null; | |
| 178 | + deadline: number | null; | |
| 179 | + remaining_ms: number | null; | |
| 180 | + mark: number | null; | |
| 181 | + answered: number; | |
| 182 | + /** When this student last saved an answer; null before the first save. */ | |
| 183 | + last_activity: number | null; | |
| 184 | +} | |
| 185 | + | |
| 186 | +export interface LiveCounts { | |
| 187 | + enrolled: number; | |
| 188 | + not_started: number; | |
| 189 | + in_progress: number; | |
| 190 | + submitted: number; | |
| 191 | + expired: number; | |
| 192 | + graded: number; | |
| 193 | +} | |
| 194 | + | |
| 195 | +/** One SSE `snapshot` frame of `GET /exams/{id}/live/stream`. */ | |
| 196 | +export interface ExamLive { | |
| 197 | + exam: Exam; | |
| 198 | + /** Server clock the snapshot was judged at. */ | |
| 199 | + now: number; | |
| 200 | + question_count: number; | |
| 201 | + counts: LiveCounts; | |
| 202 | + students: LiveStudent[]; | |
| 203 | +} | |
| 204 | + | |
| 205 | +/** One row of a student's answer sheet, as the grader sees it. */ | |
| 206 | +export interface StudentAnswer { | |
| 207 | + question: string; | |
| 208 | + selected: number | null; | |
| 209 | + text: string | null; | |
| 210 | + updated_at: number; | |
| 211 | + /** Whether `selected` hits `correct`; null for text questions. */ | |
| 212 | + is_correct: boolean | null; | |
| 213 | +} | |
| 214 | + | |
| 215 | +/** A student's full answer sheet with the machine's scoring suggestion. */ | |
| 216 | +export interface AttemptAnswers { | |
| 217 | + exam: string; | |
| 218 | + user: PersonRef; | |
| 219 | + answers: StudentAnswer[]; | |
| 220 | + /** Suggested score over choice questions — never the final mark. */ | |
| 221 | + auto_score: { earned: number; possible: number }; | |
| 86 | 222 | } |
| 87 | 223 | |
| 88 | 224 | export interface ExamResult { |
| 89 | 225 | id: string; |
| 90 | 226 | exam: string; |
| 91 | - user: string; | |
| 227 | + user: PersonRef; | |
| 92 | 228 | /** 0–100 inclusive. */ |
| 93 | 229 | mark: number; |
| 94 | - graded_by: string; | |
| 230 | + graded_by: PersonRef; | |
| 95 | 231 | } |
| 96 | 232 | |
| 97 | 233 | export interface ExamStatistics { |
| @@ -146,4 +282,11 @@ export const LIMITS = { | ||
| 146 | 282 | courseDescription: 2_000, |
| 147 | 283 | mark: { min: 0, max: 100 }, |
| 148 | 284 | weight: { min: 1, max: 100 }, |
| 285 | + /** Async per-student budget, minutes (backend: 60 s – 24 h in ms). */ | |
| 286 | + examDurationMin: { min: 1, max: 24 * 60 }, | |
| 287 | + questionText: 2_000, | |
| 288 | + questionPoints: { min: 1, max: 100 }, | |
| 289 | + questionChoices: { min: 2, max: 10 }, | |
| 290 | + choiceText: 500, | |
| 291 | + answerText: 10_000, | |
| 149 | 292 | } as const; |
src/pages/CourseDetail.tsxmodified+95 -62
| @@ -4,11 +4,16 @@ | ||
| 4 | 4 | |
| 5 | 5 | import { A, useNavigate, useParams } from "@solidjs/router"; |
| 6 | 6 | import { For, Show, createResource, createSignal } from "solid-js"; |
| 7 | +import { ConfirmButton } from "../components/ConfirmButton"; | |
| 7 | 8 | import { Empty, ErrorLine, Loading } from "../components/Feedback"; |
| 8 | 9 | import { IconEdit, IconPlus } from "../components/Icons"; |
| 10 | +import { ScheduleFields, scheduleFromForm } from "../components/ScheduleFields"; | |
| 11 | +import { UserPicker } from "../components/UserPicker"; | |
| 9 | 12 | import { createAction } from "../lib/action"; |
| 10 | 13 | import { ApiError, courses } from "../lib/api"; |
| 11 | 14 | import { useAuth } from "../lib/auth"; |
| 15 | +import { personLabel } from "../lib/format"; | |
| 16 | +import { t } from "../lib/i18n"; | |
| 12 | 17 | import { EXAM_KINDS, LIMITS, type Enrollment } from "../lib/types"; |
| 13 | 18 | |
| 14 | 19 | export default function CourseDetail() { |
| @@ -52,7 +57,7 @@ export default function CourseDetail() { | ||
| 52 | 57 | </div> |
| 53 | 58 | <Show when={canManage()}> |
| 54 | 59 | <button class="ghost" onClick={() => setEditing((open) => !open)}> |
| 55 | - <IconEdit /> {editing() ? "Close" : "Edit"} | |
| 60 | + <IconEdit /> {editing() ? t("close") : t("edit")} | |
| 56 | 61 | </button> |
| 57 | 62 | </Show> |
| 58 | 63 | </header> |
| @@ -69,31 +74,37 @@ export default function CourseDetail() { | ||
| 69 | 74 | void save.run(e.currentTarget); |
| 70 | 75 | }} |
| 71 | 76 | > |
| 72 | - <input | |
| 73 | - name="title" | |
| 74 | - value={current().title} | |
| 75 | - required | |
| 76 | - maxLength={LIMITS.courseTitle} | |
| 77 | - /> | |
| 78 | - <textarea name="description" rows={3} maxLength={LIMITS.courseDescription}> | |
| 79 | - {current().description} | |
| 80 | - </textarea> | |
| 77 | + <label> | |
| 78 | + {t("title")} | |
| 79 | + <input | |
| 80 | + name="title" | |
| 81 | + value={current().title} | |
| 82 | + required | |
| 83 | + maxLength={LIMITS.courseTitle} | |
| 84 | + /> | |
| 85 | + </label> | |
| 86 | + <label> | |
| 87 | + {t("description")} | |
| 88 | + <textarea name="description" rows={3} maxLength={LIMITS.courseDescription}> | |
| 89 | + {current().description} | |
| 90 | + </textarea> | |
| 91 | + </label> | |
| 81 | 92 | <ErrorLine error={save.error() ?? remove.error()} /> |
| 82 | 93 | <span class="row-actions"> |
| 83 | 94 | <button type="submit" disabled={save.pending()}> |
| 84 | - Save | |
| 95 | + {t("save")} | |
| 85 | 96 | </button> |
| 86 | 97 | <button type="button" class="ghost" onClick={() => setEditing(false)}> |
| 87 | - Cancel | |
| 98 | + {t("cancel")} | |
| 88 | 99 | </button> |
| 89 | - <button | |
| 90 | - type="button" | |
| 100 | + <ConfirmButton | |
| 91 | 101 | class="ghost danger push" |
| 102 | + confirmText={t("reallyDeleteCourse")} | |
| 92 | 103 | disabled={remove.pending()} |
| 93 | - onClick={() => void remove.run()} | |
| 104 | + onConfirm={() => void remove.run()} | |
| 94 | 105 | > |
| 95 | - Delete course | |
| 96 | - </button> | |
| 106 | + {t("deleteCourse")} | |
| 107 | + </ConfirmButton> | |
| 97 | 108 | </span> |
| 98 | 109 | </form> |
| 99 | 110 | </Show> |
| @@ -120,6 +131,7 @@ function CourseExams(props: { courseId: string; canManage: boolean }) { | ||
| 120 | 131 | description: String(data.get("description")), |
| 121 | 132 | kind: String(data.get("kind")), |
| 122 | 133 | weight: Number(data.get("weight")), |
| 134 | + ...scheduleFromForm(data), | |
| 123 | 135 | }); |
| 124 | 136 | mutate((current) => [created, ...(current ?? [])]); |
| 125 | 137 | form.reset(); |
| @@ -129,10 +141,10 @@ function CourseExams(props: { courseId: string; canManage: boolean }) { | ||
| 129 | 141 | return ( |
| 130 | 142 | <article class="stack gap-top"> |
| 131 | 143 | <div class="section-head"> |
| 132 | - <h2>Exams</h2> | |
| 144 | + <h2>{t("examsTitle")}</h2> | |
| 133 | 145 | <Show when={props.canManage}> |
| 134 | 146 | <button class="ghost" onClick={() => setCreating((open) => !open)}> |
| 135 | - <IconPlus /> New exam | |
| 147 | + <IconPlus /> {t("newExam")} | |
| 136 | 148 | </button> |
| 137 | 149 | </Show> |
| 138 | 150 | </div> |
| @@ -145,28 +157,30 @@ function CourseExams(props: { courseId: string; canManage: boolean }) { | ||
| 145 | 157 | void create.run(e.currentTarget); |
| 146 | 158 | }} |
| 147 | 159 | > |
| 148 | - <input | |
| 149 | - name="title" | |
| 150 | - placeholder="Title" | |
| 151 | - required | |
| 152 | - maxLength={LIMITS.examTitle} | |
| 153 | - ref={(el) => queueMicrotask(() => el.focus())} | |
| 154 | - /> | |
| 155 | - <textarea | |
| 156 | - name="description" | |
| 157 | - placeholder="Description" | |
| 158 | - rows={2} | |
| 159 | - maxLength={LIMITS.examDescription} | |
| 160 | - /> | |
| 160 | + <label> | |
| 161 | + {t("title")} | |
| 162 | + <input | |
| 163 | + name="title" | |
| 164 | + required | |
| 165 | + maxLength={LIMITS.examTitle} | |
| 166 | + ref={(el) => queueMicrotask(() => el.focus())} | |
| 167 | + /> | |
| 168 | + </label> | |
| 169 | + <label> | |
| 170 | + {t("description")} | |
| 171 | + <textarea name="description" rows={2} maxLength={LIMITS.examDescription} /> | |
| 172 | + </label> | |
| 161 | 173 | <div class="row"> |
| 162 | 174 | <label> |
| 163 | - Kind | |
| 175 | + {t("kind")} | |
| 164 | 176 | <select name="kind"> |
| 165 | - <For each={EXAM_KINDS}>{(kind) => <option value={kind}>{kind}</option>}</For> | |
| 177 | + <For each={EXAM_KINDS}> | |
| 178 | + {(kind) => <option value={kind}>{t("kindWord")(kind)}</option>} | |
| 179 | + </For> | |
| 166 | 180 | </select> |
| 167 | 181 | </label> |
| 168 | 182 | <label> |
| 169 | - Weight | |
| 183 | + {t("weight")} | |
| 170 | 184 | <input |
| 171 | 185 | name="weight" |
| 172 | 186 | type="number" |
| @@ -177,29 +191,45 @@ function CourseExams(props: { courseId: string; canManage: boolean }) { | ||
| 177 | 191 | /> |
| 178 | 192 | </label> |
| 179 | 193 | </div> |
| 194 | + <ScheduleFields /> | |
| 180 | 195 | <ErrorLine error={create.error()} /> |
| 181 | 196 | <span class="row-actions"> |
| 182 | 197 | <button type="submit" disabled={create.pending()}> |
| 183 | - Add exam | |
| 198 | + {t("addExam")} | |
| 184 | 199 | </button> |
| 185 | 200 | <button type="button" class="ghost" onClick={() => setCreating(false)}> |
| 186 | - Cancel | |
| 201 | + {t("cancel")} | |
| 187 | 202 | </button> |
| 188 | 203 | </span> |
| 189 | 204 | </form> |
| 190 | 205 | </Show> |
| 191 | 206 | |
| 192 | 207 | <Show when={!list.loading} fallback={<Loading />}> |
| 193 | - <Show when={list()?.length} fallback={<Empty>No exams yet.</Empty>}> | |
| 208 | + <Show | |
| 209 | + when={list()?.length} | |
| 210 | + fallback={ | |
| 211 | + <Empty | |
| 212 | + action={ | |
| 213 | + props.canManage ? ( | |
| 214 | + <button onClick={() => setCreating(true)}> | |
| 215 | + <IconPlus /> {t("newExam")} | |
| 216 | + </button> | |
| 217 | + ) : undefined | |
| 218 | + } | |
| 219 | + > | |
| 220 | + {t("noExamsYet")} | |
| 221 | + </Empty> | |
| 222 | + } | |
| 223 | + > | |
| 194 | 224 | <div class="grid"> |
| 195 | 225 | <For each={list()}> |
| 196 | 226 | {(exam) => ( |
| 197 | 227 | <A href={`/exams/${exam.id}`} class="card link-card stack"> |
| 198 | 228 | <header class="row"> |
| 199 | 229 | <h3>{exam.title}</h3> |
| 200 | - <span class="badge">{exam.kind}</span> | |
| 201 | - <span class="badge" title="weight in the course average"> | |
| 202 | - ×{exam.weight} | |
| 230 | + <span class="badge">{t("kindWord")(exam.kind)}</span> | |
| 231 | + <span class="badge" title={t("weightTitle")}> | |
| 232 | + {t("weightBadge")(exam.weight)} | |
| 203 | 233 | </span> |
| 204 | 234 | </header> |
| 205 | 235 | <Show when={exam.description}> |
| @@ -225,45 +255,45 @@ function Roster(props: { courseId: string; canManage: boolean }) { | ||
| 225 | 255 | const enrolled = await courses.enroll(props.courseId, String(data.get("user_id"))); |
| 226 | 256 | // Enrolling is an idempotent upsert; one row per (course, user). |
| 227 | 257 | mutate((current) => [ |
| 228 | - ...(current ?? []).filter((e) => e.user !== enrolled.user), | |
| 258 | + ...(current ?? []).filter((e) => e.user.id !== enrolled.user.id), | |
| 229 | 259 | enrolled, |
| 230 | 260 | ]); |
| 231 | 261 | form.reset(); |
| 232 | 262 | }); |
| 233 | 263 | |
| 234 | 264 | const unenroll = createAction(async (entry: Enrollment) => { |
| 235 | - await courses.unenroll(props.courseId, entry.user); | |
| 236 | - mutate((current) => current?.filter((e) => e.user !== entry.user)); | |
| 265 | + await courses.unenroll(props.courseId, entry.user.id); | |
| 266 | + mutate((current) => current?.filter((e) => e.user.id !== entry.user.id)); | |
| 237 | 267 | }); |
| 238 | 268 | |
| 239 | 269 | return ( |
| 240 | 270 | <article class="stack gap-top"> |
| 241 | - <h2>Roster</h2> | |
| 271 | + <h2>{t("roster")}</h2> | |
| 242 | 272 | |
| 243 | 273 | <Show when={props.canManage}> |
| 244 | 274 | <form |
| 245 | - class="row" | |
| 275 | + class="row row-end" | |
| 246 | 276 | onSubmit={(e) => { |
| 247 | 277 | e.preventDefault(); |
| 248 | 278 | void enroll.run(e.currentTarget); |
| 249 | 279 | }} |
| 250 | 280 | > |
| 251 | - <input name="user_id" placeholder="Student id" required /> | |
| 281 | + <UserPicker name="user_id" label={t("student")} /> | |
| 252 | 282 | <button type="submit" disabled={enroll.pending()}> |
| 253 | - Enroll | |
| 283 | + {t("enroll")} | |
| 254 | 284 | </button> |
| 255 | 285 | </form> |
| 256 | 286 | <ErrorLine error={enroll.error() ?? unenroll.error()} /> |
| 257 | 287 | </Show> |
| 258 | 288 | |
| 259 | 289 | <Show when={!roster.loading} fallback={<Loading />}> |
| 260 | - <Show when={roster()?.length} fallback={<Empty>Nobody enrolled yet.</Empty>}> | |
| 290 | + <Show when={roster()?.length} fallback={<Empty>{t("nobodyEnrolledYet")}</Empty>}> | |
| 261 | 291 | <div class="table-wrap"> |
| 262 | 292 | <table> |
| 263 | 293 | <thead> |
| 264 | 294 | <tr> |
| 265 | - <th>Student</th> | |
| 266 | - <th>Enrolled by</th> | |
| 295 | + <th>{t("student")}</th> | |
| 296 | + <th>{t("enrolledBy")}</th> | |
| 267 | 297 | <Show when={props.canManage}> |
| 268 | 298 | <th /> |
| 269 | 299 | </Show> |
| @@ -273,17 +303,20 @@ function Roster(props: { courseId: string; canManage: boolean }) { | ||
| 273 | 303 | <For each={roster()}> |
| 274 | 304 | {(entry) => ( |
| 275 | 305 | <tr> |
| 276 | - <td class="mono">{entry.user === user()?.id ? "you" : entry.user}</td> | |
| 277 | - <td class="mono">{entry.enrolled_by}</td> | |
| 306 | + <td> | |
| 307 | + {personLabel(entry.user)} | |
| 308 | + <Show when={entry.user.id === user()?.id}>{t("you")}</Show> | |
| 309 | + </td> | |
| 310 | + <td class="meta">{personLabel(entry.enrolled_by)}</td> | |
| 278 | 311 | <Show when={props.canManage}> |
| 279 | 312 | <td> |
| 280 | - <button | |
| 281 | - class="ghost danger" | |
| 313 | + <ConfirmButton | |
| 314 | + confirmText={t("reallyRemove")} | |
| 282 | 315 | disabled={unenroll.pending()} |
| 283 | - onClick={() => void unenroll.run(entry)} | |
| 316 | + onConfirm={() => void unenroll.run(entry)} | |
| 284 | 317 | > |
| 285 | - Unenroll | |
| 286 | - </button> | |
| 318 | + {t("unenroll")} | |
| 319 | + </ConfirmButton> | |
| 287 | 320 | </td> |
| 288 | 321 | </Show> |
| 289 | 322 | </tr> |
| @@ -299,9 +332,9 @@ function Roster(props: { courseId: string; canManage: boolean }) { | ||
| 299 | 332 | } |
| 300 | 333 | |
| 301 | 334 | function NotFoundMessage(props: { error: unknown }) { |
| 302 | - const message = | |
| 335 | + const message = () => | |
| 303 | 336 | props.error instanceof ApiError && props.error.status === 404 |
| 304 | - ? "This course does not exist." | |
| 305 | - : "Failed to load the course."; | |
| 306 | - return <Empty>{message}</Empty>; | |
| 337 | + ? t("courseMissing") | |
| 338 | + : t("courseLoadFailed"); | |
| 339 | + return <Empty>{message()}</Empty>; | |
| 307 | 340 | } |
src/pages/Courses.tsxmodified+36 -20
| @@ -8,6 +8,7 @@ import { IconPlus } from "../components/Icons"; | ||
| 8 | 8 | import { createAction } from "../lib/action"; |
| 9 | 9 | import { courses } from "../lib/api"; |
| 10 | 10 | import { useAuth } from "../lib/auth"; |
| 11 | +import { t } from "../lib/i18n"; | |
| 11 | 12 | import { LIMITS } from "../lib/types"; |
| 12 | 13 | |
| 13 | 14 | export default function Courses() { |
| @@ -32,12 +33,12 @@ export default function Courses() { | ||
| 32 | 33 | <section class="page"> |
| 33 | 34 | <header class="page-head"> |
| 34 | 35 | <div> |
| 35 | - <h1>Courses</h1> | |
| 36 | - <p class="sub">Everything on offer — your enrollments are tagged.</p> | |
| 36 | + <h1>{t("coursesTitle")}</h1> | |
| 37 | + <p class="sub">{t("coursesSub")}</p> | |
| 37 | 38 | </div> |
| 38 | 39 | <Show when={can("teacher")}> |
| 39 | 40 | <button onClick={() => setCreating((open) => !open)}> |
| 40 | - <IconPlus /> New course | |
| 41 | + <IconPlus /> {t("newCourse")} | |
| 41 | 42 | </button> |
| 42 | 43 | </Show> |
| 43 | 44 | </header> |
| @@ -50,33 +51,48 @@ export default function Courses() { | ||
| 50 | 51 | void create.run(e.currentTarget); |
| 51 | 52 | }} |
| 52 | 53 | > |
| 53 | - <input | |
| 54 | - name="title" | |
| 55 | - placeholder="Title" | |
| 56 | - required | |
| 57 | - maxLength={LIMITS.courseTitle} | |
| 58 | - ref={(el) => queueMicrotask(() => el.focus())} | |
| 59 | - /> | |
| 60 | - <textarea | |
| 61 | - name="description" | |
| 62 | - placeholder="Description" | |
| 63 | - rows={2} | |
| 64 | - maxLength={LIMITS.courseDescription} | |
| 65 | - /> | |
| 54 | + <label> | |
| 55 | + {t("title")} | |
| 56 | + <input | |
| 57 | + name="title" | |
| 58 | + required | |
| 59 | + maxLength={LIMITS.courseTitle} | |
| 60 | + ref={(el) => queueMicrotask(() => el.focus())} | |
| 61 | + /> | |
| 62 | + </label> | |
| 63 | + <label> | |
| 64 | + {t("description")} | |
| 65 | + <textarea name="description" rows={2} maxLength={LIMITS.courseDescription} /> | |
| 66 | + </label> | |
| 66 | 67 | <ErrorLine error={create.error()} /> |
| 67 | 68 | <span class="row-actions"> |
| 68 | 69 | <button type="submit" disabled={create.pending()}> |
| 69 | - Add course | |
| 70 | + {t("addCourse")} | |
| 70 | 71 | </button> |
| 71 | 72 | <button type="button" class="ghost" onClick={() => setCreating(false)}> |
| 72 | - Cancel | |
| 73 | + {t("cancel")} | |
| 73 | 74 | </button> |
| 74 | 75 | </span> |
| 75 | 76 | </form> |
| 76 | 77 | </Show> |
| 77 | 78 | |
| 78 | 79 | <Show when={!list.loading} fallback={<Loading />}> |
| 79 | - <Show when={list()?.length} fallback={<Empty>No courses yet.</Empty>}> | |
| 80 | + <Show | |
| 81 | + when={list()?.length} | |
| 82 | + fallback={ | |
| 83 | + <Empty | |
| 84 | + action={ | |
| 85 | + can("teacher") ? ( | |
| 86 | + <button onClick={() => setCreating(true)}> | |
| 87 | + <IconPlus /> {t("newCourse")} | |
| 88 | + </button> | |
| 89 | + ) : undefined | |
| 90 | + } | |
| 91 | + > | |
| 92 | + {t("noCoursesYet")} | |
| 93 | + </Empty> | |
| 94 | + } | |
| 95 | + > | |
| 80 | 96 | <div class="grid"> |
| 81 | 97 | <For each={list()}> |
| 82 | 98 | {(course) => ( |
| @@ -84,7 +100,7 @@ export default function Courses() { | ||
| 84 | 100 | <header class="row"> |
| 85 | 101 | <h3>{course.title}</h3> |
| 86 | 102 | <Show when={enrolled().has(course.id)}> |
| 87 | - <span class="badge">enrolled</span> | |
| 103 | + <span class="badge">{t("enrolledBadge")}</span> | |
| 88 | 104 | </Show> |
| 89 | 105 | </header> |
| 90 | 106 | <Show when={course.description}> |
src/pages/EventDetail.tsxmodified+63 -48
| @@ -4,12 +4,15 @@ | ||
| 4 | 4 | |
| 5 | 5 | import { useNavigate, useParams } from "@solidjs/router"; |
| 6 | 6 | import { For, Show, createResource, createSignal } from "solid-js"; |
| 7 | +import { ConfirmButton } from "../components/ConfirmButton"; | |
| 7 | 8 | import { Empty, ErrorLine, Loading } from "../components/Feedback"; |
| 8 | 9 | import { IconEdit } from "../components/Icons"; |
| 10 | +import { UserPicker } from "../components/UserPicker"; | |
| 9 | 11 | import { createAction } from "../lib/action"; |
| 10 | 12 | import { ApiError, events } from "../lib/api"; |
| 11 | 13 | import { useAuth } from "../lib/auth"; |
| 12 | -import { formatWindow, fromInputValue, toInputValue } from "../lib/format"; | |
| 14 | +import { formatWindow, fromInputValue, personLabel, toInputValue } from "../lib/format"; | |
| 15 | +import { t } from "../lib/i18n"; | |
| 13 | 16 | import { ATTENDANCE_STATUSES, LIMITS, type AttendanceStatus } from "../lib/types"; |
| 14 | 17 | |
| 15 | 18 | export default function EventDetail() { |
| @@ -25,7 +28,7 @@ export default function EventDetail() { | ||
| 25 | 28 | const current = event(); |
| 26 | 29 | return current !== undefined && (current.creator === user()?.id || can("manager")); |
| 27 | 30 | }; |
| 28 | - const myStatus = () => roster()?.find((a) => a.user === user()?.id)?.status; | |
| 31 | + const myStatus = () => roster()?.find((a) => a.user.id === user()?.id)?.status; | |
| 29 | 32 | |
| 30 | 33 | const save = createAction(async (form: HTMLFormElement) => { |
| 31 | 34 | const data = new FormData(form); |
| @@ -49,14 +52,14 @@ export default function EventDetail() { | ||
| 49 | 52 | const marked = await events.mark(params.id, status, userId); |
| 50 | 53 | // The backend upserts one row per (event, user); mirror that. |
| 51 | 54 | setRoster((current) => [ |
| 52 | - ...(current ?? []).filter((a) => a.user !== marked.user), | |
| 55 | + ...(current ?? []).filter((a) => a.user.id !== marked.user.id), | |
| 53 | 56 | marked, |
| 54 | 57 | ]); |
| 55 | 58 | }); |
| 56 | 59 | |
| 57 | 60 | const unmark = createAction(async (userId: string) => { |
| 58 | 61 | await events.unmark(params.id, userId); |
| 59 | - setRoster((current) => current?.filter((a) => a.user !== userId)); | |
| 62 | + setRoster((current) => current?.filter((a) => a.user.id !== userId)); | |
| 60 | 63 | }); |
| 61 | 64 | |
| 62 | 65 | return ( |
| @@ -73,7 +76,7 @@ export default function EventDetail() { | ||
| 73 | 76 | </div> |
| 74 | 77 | <Show when={canManage()}> |
| 75 | 78 | <button class="ghost" onClick={() => setEditing((open) => !open)}> |
| 76 | - <IconEdit /> {editing() ? "Close" : "Edit"} | |
| 79 | + <IconEdit /> {editing() ? t("close") : t("edit")} | |
| 77 | 80 | </button> |
| 78 | 81 | </Show> |
| 79 | 82 | </header> |
| @@ -90,18 +93,24 @@ export default function EventDetail() { | ||
| 90 | 93 | void save.run(e.currentTarget); |
| 91 | 94 | }} |
| 92 | 95 | > |
| 93 | - <input | |
| 94 | - name="title" | |
| 95 | - value={current().title} | |
| 96 | - required | |
| 97 | - maxLength={LIMITS.eventTitle} | |
| 98 | - /> | |
| 99 | - <textarea name="description" rows={3} maxLength={LIMITS.eventDescription}> | |
| 100 | - {current().description} | |
| 101 | - </textarea> | |
| 96 | + <label> | |
| 97 | + {t("title")} | |
| 98 | + <input | |
| 99 | + name="title" | |
| 100 | + value={current().title} | |
| 101 | + required | |
| 102 | + maxLength={LIMITS.eventTitle} | |
| 103 | + /> | |
| 104 | + </label> | |
| 105 | + <label> | |
| 106 | + {t("description")} | |
| 107 | + <textarea name="description" rows={3} maxLength={LIMITS.eventDescription}> | |
| 108 | + {current().description} | |
| 109 | + </textarea> | |
| 110 | + </label> | |
| 102 | 111 | <div class="row"> |
| 103 | 112 | <label> |
| 104 | - Starts | |
| 113 | + {t("starts")} | |
| 105 | 114 | <input |
| 106 | 115 | name="starts_at" |
| 107 | 116 | type="datetime-local" |
| @@ -109,7 +118,7 @@ export default function EventDetail() { | ||
| 109 | 118 | /> |
| 110 | 119 | </label> |
| 111 | 120 | <label> |
| 112 | - Ends | |
| 121 | + {t("ends")} | |
| 113 | 122 | <input |
| 114 | 123 | name="ends_at" |
| 115 | 124 | type="datetime-local" |
| @@ -120,25 +129,25 @@ export default function EventDetail() { | ||
| 120 | 129 | <ErrorLine error={save.error() ?? remove.error()} /> |
| 121 | 130 | <span class="row-actions"> |
| 122 | 131 | <button type="submit" disabled={save.pending()}> |
| 123 | - Save | |
| 132 | + {t("save")} | |
| 124 | 133 | </button> |
| 125 | 134 | <button type="button" class="ghost" onClick={() => setEditing(false)}> |
| 126 | - Cancel | |
| 135 | + {t("cancel")} | |
| 127 | 136 | </button> |
| 128 | - <button | |
| 129 | - type="button" | |
| 137 | + <ConfirmButton | |
| 130 | 138 | class="ghost danger push" |
| 139 | + confirmText={t("reallyDeleteEvent")} | |
| 131 | 140 | disabled={remove.pending()} |
| 132 | - onClick={() => void remove.run()} | |
| 141 | + onConfirm={() => void remove.run()} | |
| 133 | 142 | > |
| 134 | - Delete event | |
| 135 | - </button> | |
| 143 | + {t("deleteEvent")} | |
| 144 | + </ConfirmButton> | |
| 136 | 145 | </span> |
| 137 | 146 | </form> |
| 138 | 147 | </Show> |
| 139 | 148 | |
| 140 | 149 | <article class="stack gap-top"> |
| 141 | - <h2>Attendance</h2> | |
| 150 | + <h2>{t("attendance")}</h2> | |
| 142 | 151 | <div class="row-actions"> |
| 143 | 152 | <For each={ATTENDANCE_STATUSES}> |
| 144 | 153 | {(status) => ( |
| @@ -147,7 +156,7 @@ export default function EventDetail() { | ||
| 147 | 156 | disabled={mark.pending()} |
| 148 | 157 | onClick={() => void mark.run(status)} |
| 149 | 158 | > |
| 150 | - I'm {status} | |
| 159 | + {t("iAm")(status)} | |
| 151 | 160 | </button> |
| 152 | 161 | )} |
| 153 | 162 | </For> |
| @@ -155,7 +164,7 @@ export default function EventDetail() { | ||
| 155 | 164 | |
| 156 | 165 | <Show when={can("teacher")}> |
| 157 | 166 | <form |
| 158 | - class="row" | |
| 167 | + class="row row-end" | |
| 159 | 168 | onSubmit={(e) => { |
| 160 | 169 | e.preventDefault(); |
| 161 | 170 | const data = new FormData(e.currentTarget); |
| @@ -165,27 +174,30 @@ export default function EventDetail() { | ||
| 165 | 174 | ); |
| 166 | 175 | }} |
| 167 | 176 | > |
| 168 | - <input name="user_id" placeholder="User id" required /> | |
| 169 | - <select name="status"> | |
| 170 | - <For each={ATTENDANCE_STATUSES}> | |
| 171 | - {(status) => <option value={status}>{status}</option>} | |
| 172 | - </For> | |
| 173 | - </select> | |
| 177 | + <UserPicker name="user_id" label={t("person")} /> | |
| 178 | + <label> | |
| 179 | + {t("status")} | |
| 180 | + <select name="status"> | |
| 181 | + <For each={ATTENDANCE_STATUSES}> | |
| 182 | + {(status) => <option value={status}>{t("attendanceWord")(status)}</option>} | |
| 183 | + </For> | |
| 184 | + </select> | |
| 185 | + </label> | |
| 174 | 186 | <button type="submit" disabled={mark.pending()}> |
| 175 | - Mark user | |
| 187 | + {t("markUser")} | |
| 176 | 188 | </button> |
| 177 | 189 | </form> |
| 178 | 190 | </Show> |
| 179 | 191 | <ErrorLine error={mark.error() ?? unmark.error()} /> |
| 180 | 192 | |
| 181 | 193 | <Show when={!roster.loading} fallback={<Loading />}> |
| 182 | - <Show when={roster()?.length} fallback={<Empty>Nobody marked yet.</Empty>}> | |
| 194 | + <Show when={roster()?.length} fallback={<Empty>{t("nobodyMarkedYet")}</Empty>}> | |
| 183 | 195 | <div class="table-wrap"> |
| 184 | 196 | <table> |
| 185 | 197 | <thead> |
| 186 | 198 | <tr> |
| 187 | - <th>User</th> | |
| 188 | - <th>Status</th> | |
| 199 | + <th>{t("userCol")}</th> | |
| 200 | + <th>{t("status")}</th> | |
| 189 | 201 | <Show when={can("teacher")}> |
| 190 | 202 | <th /> |
| 191 | 203 | </Show> |
| @@ -195,21 +207,24 @@ export default function EventDetail() { | ||
| 195 | 207 | <For each={roster()}> |
| 196 | 208 | {(entry) => ( |
| 197 | 209 | <tr> |
| 198 | - <td class="mono"> | |
| 199 | - {entry.user === user()?.id ? "you" : entry.user} | |
| 210 | + <td> | |
| 211 | + {personLabel(entry.user)} | |
| 212 | + <Show when={entry.user.id === user()?.id}>{t("you")}</Show> | |
| 200 | 213 | </td> |
| 201 | 214 | <td> |
| 202 | - <span class={`badge badge-${entry.status}`}>{entry.status}</span> | |
| 215 | + <span class={`badge badge-${entry.status}`}> | |
| 216 | + {t("attendanceWord")(entry.status)} | |
| 217 | + </span> | |
| 203 | 218 | </td> |
| 204 | 219 | <Show when={can("teacher")}> |
| 205 | 220 | <td> |
| 206 | - <button | |
| 207 | - class="ghost danger" | |
| 221 | + <ConfirmButton | |
| 222 | + confirmText={t("reallyRemove")} | |
| 208 | 223 | disabled={unmark.pending()} |
| 209 | - onClick={() => void unmark.run(entry.user)} | |
| 224 | + onConfirm={() => void unmark.run(entry.user.id)} | |
| 210 | 225 | > |
| 211 | - Remove | |
| 212 | - </button> | |
| 226 | + {t("remove")} | |
| 227 | + </ConfirmButton> | |
| 213 | 228 | </td> |
| 214 | 229 | </Show> |
| 215 | 230 | </tr> |
| @@ -228,9 +243,9 @@ export default function EventDetail() { | ||
| 228 | 243 | } |
| 229 | 244 | |
| 230 | 245 | function NotFoundMessage(props: { error: unknown }) { |
| 231 | - const message = | |
| 246 | + const message = () => | |
| 232 | 247 | props.error instanceof ApiError && props.error.status === 404 |
| 233 | - ? "This event does not exist." | |
| 234 | - : "Failed to load the event."; | |
| 235 | - return <Empty>{message}</Empty>; | |
| 248 | + ? t("eventMissing") | |
| 249 | + : t("eventLoadFailed"); | |
| 250 | + return <Empty>{message()}</Empty>; | |
| 236 | 251 | } |
src/pages/Events.tsxmodified+37 -21
| @@ -9,6 +9,7 @@ import { createAction } from "../lib/action"; | ||
| 9 | 9 | import { events } from "../lib/api"; |
| 10 | 10 | import { useAuth } from "../lib/auth"; |
| 11 | 11 | import { formatWindow, fromInputValue } from "../lib/format"; |
| 12 | +import { t } from "../lib/i18n"; | |
| 12 | 13 | import { LIMITS } from "../lib/types"; |
| 13 | 14 | |
| 14 | 15 | export default function Events() { |
| @@ -35,12 +36,12 @@ export default function Events() { | ||
| 35 | 36 | <section class="page"> |
| 36 | 37 | <header class="page-head"> |
| 37 | 38 | <div> |
| 38 | - <h1>Events</h1> | |
| 39 | - <p class="sub">What's happening — open one to see or mark attendance.</p> | |
| 39 | + <h1>{t("eventsTitle")}</h1> | |
| 40 | + <p class="sub">{t("eventsSub")}</p> | |
| 40 | 41 | </div> |
| 41 | 42 | <Show when={can("teacher")}> |
| 42 | 43 | <button onClick={() => setCreating((open) => !open)}> |
| 43 | - <IconPlus /> New event | |
| 44 | + <IconPlus /> {t("newEvent")} | |
| 44 | 45 | </button> |
| 45 | 46 | </Show> |
| 46 | 47 | </header> |
| @@ -53,43 +54,58 @@ export default function Events() { | ||
| 53 | 54 | void create.run(e.currentTarget); |
| 54 | 55 | }} |
| 55 | 56 | > |
| 56 | - <input | |
| 57 | - name="title" | |
| 58 | - placeholder="Title" | |
| 59 | - required | |
| 60 | - maxLength={LIMITS.eventTitle} | |
| 61 | - ref={(el) => queueMicrotask(() => el.focus())} | |
| 62 | - /> | |
| 63 | - <textarea | |
| 64 | - name="description" | |
| 65 | - placeholder="Description" | |
| 66 | - rows={2} | |
| 67 | - maxLength={LIMITS.eventDescription} | |
| 68 | - /> | |
| 57 | + <label> | |
| 58 | + {t("title")} | |
| 59 | + <input | |
| 60 | + name="title" | |
| 61 | + required | |
| 62 | + maxLength={LIMITS.eventTitle} | |
| 63 | + ref={(el) => queueMicrotask(() => el.focus())} | |
| 64 | + /> | |
| 65 | + </label> | |
| 66 | + <label> | |
| 67 | + {t("description")} | |
| 68 | + <textarea name="description" rows={2} maxLength={LIMITS.eventDescription} /> | |
| 69 | + </label> | |
| 69 | 70 | <div class="row"> |
| 70 | 71 | <label> |
| 71 | - Starts | |
| 72 | + {t("starts")} | |
| 72 | 73 | <input name="starts_at" type="datetime-local" /> |
| 73 | 74 | </label> |
| 74 | 75 | <label> |
| 75 | - Ends | |
| 76 | + {t("ends")} | |
| 76 | 77 | <input name="ends_at" type="datetime-local" /> |
| 77 | 78 | </label> |
| 78 | 79 | </div> |
| 79 | 80 | <ErrorLine error={create.error()} /> |
| 80 | 81 | <span class="row-actions"> |
| 81 | 82 | <button type="submit" disabled={create.pending()}> |
| 82 | - Add event | |
| 83 | + {t("addEvent")} | |
| 83 | 84 | </button> |
| 84 | 85 | <button type="button" class="ghost" onClick={() => setCreating(false)}> |
| 85 | - Cancel | |
| 86 | + {t("cancel")} | |
| 86 | 87 | </button> |
| 87 | 88 | </span> |
| 88 | 89 | </form> |
| 89 | 90 | </Show> |
| 90 | 91 | |
| 91 | 92 | <Show when={!list.loading} fallback={<Loading />}> |
| 92 | - <Show when={list()?.length} fallback={<Empty>No events yet.</Empty>}> | |
| 93 | + <Show | |
| 94 | + when={list()?.length} | |
| 95 | + fallback={ | |
| 96 | + <Empty | |
| 97 | + action={ | |
| 98 | + can("teacher") ? ( | |
| 99 | + <button onClick={() => setCreating(true)}> | |
| 100 | + <IconPlus /> {t("newEvent")} | |
| 101 | + </button> | |
| 102 | + ) : undefined | |
| 103 | + } | |
| 104 | + > | |
| 105 | + {t("noEventsYet")} | |
| 106 | + </Empty> | |
| 107 | + } | |
| 108 | + > | |
| 93 | 109 | <div class="grid"> |
| 94 | 110 | <For each={list()}> |
| 95 | 111 | {(event) => ( |
src/pages/ExamDetail.tsxmodified+240 -62
| @@ -3,13 +3,34 @@ | ||
| 3 | 3 | // results, statistics. |
| 4 | 4 | |
| 5 | 5 | import { A, useNavigate, useParams } from "@solidjs/router"; |
| 6 | -import { For, Show, createResource, createSignal } from "solid-js"; | |
| 6 | +import { | |
| 7 | + For, | |
| 8 | + Match, | |
| 9 | + Show, | |
| 10 | + Switch, | |
| 11 | + createResource, | |
| 12 | + createSignal, | |
| 13 | + onCleanup, | |
| 14 | +} from "solid-js"; | |
| 15 | +import { ConfirmButton } from "../components/ConfirmButton"; | |
| 16 | +import { ExamMonitor } from "../components/ExamMonitor"; | |
| 17 | +import { ExamQuestions } from "../components/ExamQuestions"; | |
| 7 | 18 | import { Empty, ErrorLine, Loading } from "../components/Feedback"; |
| 8 | 19 | import { IconEdit } from "../components/Icons"; |
| 20 | +import { ScheduleFields, scheduleFromForm } from "../components/ScheduleFields"; | |
| 21 | +import { UserPicker } from "../components/UserPicker"; | |
| 9 | 22 | import { createAction } from "../lib/action"; |
| 10 | 23 | import { ApiError, courses, exams } from "../lib/api"; |
| 11 | 24 | import { useAuth } from "../lib/auth"; |
| 12 | -import { EXAM_KINDS, LIMITS, type ExamResult } from "../lib/types"; | |
| 25 | +import { createClock } from "../lib/clock"; | |
| 26 | +import { t } from "../lib/i18n"; | |
| 27 | +import { | |
| 28 | + formatCountdown, | |
| 29 | + formatMillis, | |
| 30 | + formatWindow, | |
| 31 | + personLabel, | |
| 32 | +} from "../lib/format"; | |
| 33 | +import { EXAM_KINDS, LIMITS, type Exam, type ExamResult } from "../lib/types"; | |
| 13 | 34 | |
| 14 | 35 | export default function ExamDetail() { |
| 15 | 36 | const params = useParams<{ id: string }>(); |
| @@ -33,6 +54,7 @@ export default function ExamDetail() { | ||
| 33 | 54 | description: String(data.get("description")), |
| 34 | 55 | kind: String(data.get("kind")), |
| 35 | 56 | weight: Number(data.get("weight")), |
| 57 | + ...scheduleFromForm(data), | |
| 36 | 58 | }), |
| 37 | 59 | ); |
| 38 | 60 | setEditing(false); |
| @@ -54,13 +76,13 @@ export default function ExamDetail() { | ||
| 54 | 76 | <div> |
| 55 | 77 | <div class="row"> |
| 56 | 78 | <h1>{current().title}</h1> |
| 57 | - <span class="badge">{current().kind}</span> | |
| 58 | - <span class="badge" title="weight in the course average"> | |
| 59 | - ×{current().weight} | |
| 79 | + <span class="badge">{t("kindWord")(current().kind)}</span> | |
| 80 | + <span class="badge" title={t("weightTitle")}> | |
| 81 | + {t("weightBadge")(current().weight)} | |
| 60 | 82 | </span> |
| 61 | 83 | </div> |
| 62 | 84 | <p class="sub"> |
| 63 | - Course:{" "} | |
| 85 | + {t("coursePrefix")}{" "} | |
| 64 | 86 | <A href={`/courses/${current().course}`}> |
| 65 | 87 | {course()?.title ?? current().course} |
| 66 | 88 | </A> |
| @@ -68,7 +90,7 @@ export default function ExamDetail() { | ||
| 68 | 90 | </div> |
| 69 | 91 | <Show when={canManage()}> |
| 70 | 92 | <button class="ghost" onClick={() => setEditing((open) => !open)}> |
| 71 | - <IconEdit /> {editing() ? "Close" : "Edit"} | |
| 93 | + <IconEdit /> {editing() ? t("close") : t("edit")} | |
| 72 | 94 | </button> |
| 73 | 95 | </Show> |
| 74 | 96 | </header> |
| @@ -85,30 +107,36 @@ export default function ExamDetail() { | ||
| 85 | 107 | void save.run(e.currentTarget); |
| 86 | 108 | }} |
| 87 | 109 | > |
| 88 | - <input | |
| 89 | - name="title" | |
| 90 | - value={current().title} | |
| 91 | - required | |
| 92 | - maxLength={LIMITS.examTitle} | |
| 93 | - /> | |
| 94 | - <textarea name="description" rows={3} maxLength={LIMITS.examDescription}> | |
| 95 | - {current().description} | |
| 96 | - </textarea> | |
| 110 | + <label> | |
| 111 | + {t("title")} | |
| 112 | + <input | |
| 113 | + name="title" | |
| 114 | + value={current().title} | |
| 115 | + required | |
| 116 | + maxLength={LIMITS.examTitle} | |
| 117 | + /> | |
| 118 | + </label> | |
| 119 | + <label> | |
| 120 | + {t("description")} | |
| 121 | + <textarea name="description" rows={3} maxLength={LIMITS.examDescription}> | |
| 122 | + {current().description} | |
| 123 | + </textarea> | |
| 124 | + </label> | |
| 97 | 125 | <div class="row"> |
| 98 | 126 | <label> |
| 99 | - Kind | |
| 127 | + {t("kind")} | |
| 100 | 128 | <select name="kind" value={current().kind}> |
| 101 | 129 | <For each={EXAM_KINDS}> |
| 102 | 130 | {(kind) => ( |
| 103 | 131 | <option value={kind} selected={kind === current().kind}> |
| 104 | - {kind} | |
| 132 | + {t("kindWord")(kind)} | |
| 105 | 133 | </option> |
| 106 | 134 | )} |
| 107 | 135 | </For> |
| 108 | 136 | </select> |
| 109 | 137 | </label> |
| 110 | 138 | <label> |
| 111 | - Weight | |
| 139 | + {t("weight")} | |
| 112 | 140 | <input |
| 113 | 141 | name="weight" |
| 114 | 142 | type="number" |
| @@ -119,28 +147,38 @@ export default function ExamDetail() { | ||
| 119 | 147 | /> |
| 120 | 148 | </label> |
| 121 | 149 | </div> |
| 150 | + <ScheduleFields exam={current()} /> | |
| 122 | 151 | <ErrorLine error={save.error() ?? remove.error()} /> |
| 123 | 152 | <span class="row-actions"> |
| 124 | 153 | <button type="submit" disabled={save.pending()}> |
| 125 | - Save | |
| 154 | + {t("save")} | |
| 126 | 155 | </button> |
| 127 | 156 | <button type="button" class="ghost" onClick={() => setEditing(false)}> |
| 128 | - Cancel | |
| 157 | + {t("cancel")} | |
| 129 | 158 | </button> |
| 130 | - <button | |
| 131 | - type="button" | |
| 159 | + <ConfirmButton | |
| 132 | 160 | class="ghost danger push" |
| 161 | + confirmText={t("reallyDeleteExam")} | |
| 133 | 162 | disabled={remove.pending()} |
| 134 | - onClick={() => void remove.run()} | |
| 163 | + onConfirm={() => void remove.run()} | |
| 135 | 164 | > |
| 136 | - Delete exam | |
| 137 | - </button> | |
| 165 | + {t("deleteExam")} | |
| 166 | + </ConfirmButton> | |
| 138 | 167 | </span> |
| 139 | 168 | </form> |
| 140 | 169 | </Show> |
| 141 | 170 | |
| 171 | + <Show when={current().mode}> | |
| 172 | + <Sitting exam={current()} /> | |
| 173 | + </Show> | |
| 142 | 174 | <MyResult examId={params.id} /> |
| 175 | + <Show when={canManage()}> | |
| 176 | + <ExamQuestions examId={params.id} /> | |
| 177 | + </Show> | |
| 143 | 178 | <Show when={can("teacher")}> |
| 179 | + <Show when={current().mode}> | |
| 180 | + <ExamMonitor exam={current()} /> | |
| 181 | + </Show> | |
| 144 | 182 | <Statistics examId={params.id} /> |
| 145 | 183 | <Results examId={params.id} /> |
| 146 | 184 | </Show> |
| @@ -150,6 +188,141 @@ export default function ExamDetail() { | ||
| 150 | 188 | ); |
| 151 | 189 | } |
| 152 | 190 | |
| 191 | +/** | |
| 192 | + * The student-facing "exam time" card of a scheduled exam: the window, whether | |
| 193 | + * it is open right now (by the server clock), and the one action that makes | |
| 194 | + * sense — enter, continue, or review what was written. | |
| 195 | + */ | |
| 196 | +function Sitting(props: { exam: Exam }) { | |
| 197 | + const navigate = useNavigate(); | |
| 198 | + const clock = createClock(); | |
| 199 | + onCleanup(clock.stop); | |
| 200 | + | |
| 201 | + const [attempt] = createResource( | |
| 202 | + () => props.exam.id, | |
| 203 | + async (id) => { | |
| 204 | + try { | |
| 205 | + return await exams.myAttempt(id); | |
| 206 | + } catch (err) { | |
| 207 | + if (err instanceof ApiError && err.status === 404) return null; | |
| 208 | + throw err; | |
| 209 | + } | |
| 210 | + }, | |
| 211 | + ); | |
| 212 | + | |
| 213 | + const phase = () => { | |
| 214 | + if (clock.now() < (props.exam.starts_at ?? 0)) return "upcoming" as const; | |
| 215 | + if (clock.now() >= (props.exam.ends_at ?? 0)) return "closed" as const; | |
| 216 | + return "open" as const; | |
| 217 | + }; | |
| 218 | + | |
| 219 | + // The live view of a running attempt: the server said in_progress, but the | |
| 220 | + // deadline may have passed since — judge it against the ticking clock. | |
| 221 | + const running = () => { | |
| 222 | + const current = attempt(); | |
| 223 | + return current?.status === "in_progress" && | |
| 224 | + (current.deadline === null || clock.now() < current.deadline) | |
| 225 | + ? current | |
| 226 | + : undefined; | |
| 227 | + }; | |
| 228 | + const ranOut = () => { | |
| 229 | + const current = attempt(); | |
| 230 | + return ( | |
| 231 | + current?.status === "expired" || | |
| 232 | + (current?.status === "in_progress" && !running()) | |
| 233 | + ); | |
| 234 | + }; | |
| 235 | + | |
| 236 | + const enter = createAction(async () => { | |
| 237 | + // Idempotent on the backend: re-entering never resets the clock. | |
| 238 | + await exams.startAttempt(props.exam.id); | |
| 239 | + navigate(`/exams/${props.exam.id}/room`); | |
| 240 | + }); | |
| 241 | + | |
| 242 | + const minutes = () => Math.round((props.exam.duration_ms ?? 0) / 60_000); | |
| 243 | + | |
| 244 | + return ( | |
| 245 | + <article class="card stack sitting"> | |
| 246 | + <header class="row"> | |
| 247 | + <h2>{t("examTime")}</h2> | |
| 248 | + <span class={`badge phase-${phase()}`}>{t("phaseWord")(phase())}</span> | |
| 249 | + </header> | |
| 250 | + <p class="meta"> | |
| 251 | + {formatWindow(props.exam.starts_at, props.exam.ends_at)} | |
| 252 | + <Show when={props.exam.mode === "async"}> · {t("minutesEach")(minutes())}</Show> | |
| 253 | + </p> | |
| 254 | + | |
| 255 | + <Show when={!attempt.loading}> | |
| 256 | + <Switch> | |
| 257 | + <Match when={attempt()?.status === "submitted"}> | |
| 258 | + <p>{t("turnedInAt")(formatMillis(attempt()!.finished_at))}</p> | |
| 259 | + <span class="row-actions"> | |
| 260 | + <button class="ghost" onClick={() => navigate(`/exams/${props.exam.id}/room`)}> | |
| 261 | + {t("seeMyAnswers")} | |
| 262 | + </button> | |
| 263 | + </span> | |
| 264 | + </Match> | |
| 265 | + <Match when={ranOut()}> | |
| 266 | + <p>{t("timeRanOut")}</p> | |
| 267 | + <span class="row-actions"> | |
| 268 | + <button class="ghost" onClick={() => navigate(`/exams/${props.exam.id}/room`)}> | |
| 269 | + {t("seeMyAnswers")} | |
| 270 | + </button> | |
| 271 | + </span> | |
| 272 | + </Match> | |
| 273 | + <Match when={running()}> | |
| 274 | + {(current) => ( | |
| 275 | + <span class="row-actions"> | |
| 276 | + <button | |
| 277 | + class="cta" | |
| 278 | + onClick={() => navigate(`/exams/${props.exam.id}/room`)} | |
| 279 | + > | |
| 280 | + {t("continueExam")} | |
| 281 | + </button> | |
| 282 | + <span class="meta"> | |
| 283 | + {t("answeredOf")(current().answered, current().question_count)} | |
| 284 | + <Show when={current().deadline !== null}> | |
| 285 | + {" · "} | |
| 286 | + {t("timeLeftShort")(formatCountdown(current().deadline! - clock.now()))} | |
| 287 | + </Show> | |
| 288 | + </span> | |
| 289 | + </span> | |
| 290 | + )} | |
| 291 | + </Match> | |
| 292 | + <Match when={attempt() === null && phase() === "open"}> | |
| 293 | + <span class="row-actions"> | |
| 294 | + <Show | |
| 295 | + when={props.exam.mode === "async"} | |
| 296 | + fallback={ | |
| 297 | + <button class="cta" disabled={enter.pending()} onClick={() => void enter.run()}> | |
| 298 | + {t("enterExam")} | |
| 299 | + </button> | |
| 300 | + } | |
| 301 | + > | |
| 302 | + <ConfirmButton | |
| 303 | + class="cta" | |
| 304 | + confirmText={t("startTimerConfirm")(minutes())} | |
| 305 | + disabled={enter.pending()} | |
| 306 | + onConfirm={() => void enter.run()} | |
| 307 | + > | |
| 308 | + {t("enterExam")} | |
| 309 | + </ConfirmButton> | |
| 310 | + </Show> | |
| 311 | + </span> | |
| 312 | + </Match> | |
| 313 | + <Match when={attempt() === null && phase() === "upcoming"}> | |
| 314 | + <p class="muted">{t("opensAt")(formatMillis(props.exam.starts_at))}</p> | |
| 315 | + </Match> | |
| 316 | + <Match when={attempt() === null && phase() === "closed"}> | |
| 317 | + <p class="muted">{t("examOver")}</p> | |
| 318 | + </Match> | |
| 319 | + </Switch> | |
| 320 | + </Show> | |
| 321 | + <ErrorLine error={enter.error()} /> | |
| 322 | + </article> | |
| 323 | + ); | |
| 324 | +} | |
| 325 | + | |
| 153 | 326 | /** The caller's own mark; the backend answers 404 while ungraded. */ |
| 154 | 327 | function MyResult(props: { examId: string }) { |
| 155 | 328 | const [result] = createResource( |
| @@ -166,9 +339,9 @@ function MyResult(props: { examId: string }) { | ||
| 166 | 339 | |
| 167 | 340 | return ( |
| 168 | 341 | <article class="stack gap-top"> |
| 169 | - <h2>My result</h2> | |
| 342 | + <h2>{t("myResult")}</h2> | |
| 170 | 343 | <Show when={!result.loading} fallback={<Loading />}> |
| 171 | - <Show when={result()} fallback={<Empty>Not graded yet.</Empty>}> | |
| 344 | + <Show when={result()} fallback={<Empty>{t("notGradedYet")}</Empty>}> | |
| 172 | 345 | {(mine) => ( |
| 173 | 346 | <p class="mark"> |
| 174 | 347 | {mine().mark} |
| @@ -188,26 +361,26 @@ function Statistics(props: { examId: string }) { | ||
| 188 | 361 | |
| 189 | 362 | return ( |
| 190 | 363 | <article class="stack gap-top"> |
| 191 | - <h2>Statistics</h2> | |
| 364 | + <h2>{t("statistics")}</h2> | |
| 192 | 365 | <Show when={!stats.loading} fallback={<Loading />}> |
| 193 | 366 | <Show when={stats()}> |
| 194 | 367 | {(current) => ( |
| 195 | - <Show when={current().graded > 0} fallback={<Empty>Nothing graded yet.</Empty>}> | |
| 368 | + <Show when={current().graded > 0} fallback={<Empty>{t("nothingGradedYet")}</Empty>}> | |
| 196 | 369 | <div class="stats"> |
| 197 | 370 | <div class="card stat"> |
| 198 | - <span class="stat-label">Graded</span> | |
| 371 | + <span class="stat-label">{t("gradedStat")}</span> | |
| 199 | 372 | <span class="stat-value">{current().graded}</span> |
| 200 | 373 | </div> |
| 201 | 374 | <div class="card stat"> |
| 202 | - <span class="stat-label">Average</span> | |
| 375 | + <span class="stat-label">{t("averageStat")}</span> | |
| 203 | 376 | <span class="stat-value">{round(current().average ?? 0)}</span> |
| 204 | 377 | </div> |
| 205 | 378 | <div class="card stat"> |
| 206 | - <span class="stat-label">Min</span> | |
| 379 | + <span class="stat-label">{t("minStat")}</span> | |
| 207 | 380 | <span class="stat-value">{current().min}</span> |
| 208 | 381 | </div> |
| 209 | 382 | <div class="card stat"> |
| 210 | - <span class="stat-label">Max</span> | |
| 383 | + <span class="stat-label">{t("maxStat")}</span> | |
| 211 | 384 | <span class="stat-value">{current().max}</span> |
| 212 | 385 | </div> |
| 213 | 386 | </div> |
| @@ -234,50 +407,52 @@ function Results(props: { examId: string }) { | ||
| 234 | 407 | ); |
| 235 | 408 | // One result per (exam, user); grading again overwrites. |
| 236 | 409 | mutate((current) => [ |
| 237 | - ...(current ?? []).filter((r) => r.user !== graded.user), | |
| 410 | + ...(current ?? []).filter((r) => r.user.id !== graded.user.id), | |
| 238 | 411 | graded, |
| 239 | 412 | ]); |
| 240 | 413 | form.reset(); |
| 241 | 414 | }); |
| 242 | 415 | |
| 243 | 416 | const removeResult = createAction(async (result: ExamResult) => { |
| 244 | - await exams.removeResult(props.examId, result.user); | |
| 245 | - mutate((current) => current?.filter((r) => r.user !== result.user)); | |
| 417 | + await exams.removeResult(props.examId, result.user.id); | |
| 418 | + mutate((current) => current?.filter((r) => r.user.id !== result.user.id)); | |
| 246 | 419 | }); |
| 247 | 420 | |
| 248 | 421 | return ( |
| 249 | 422 | <article class="stack gap-top"> |
| 250 | - <h2>Results</h2> | |
| 423 | + <h2>{t("results")}</h2> | |
| 251 | 424 | <form |
| 252 | - class="row" | |
| 425 | + class="row row-end" | |
| 253 | 426 | onSubmit={(e) => { |
| 254 | 427 | e.preventDefault(); |
| 255 | 428 | void grade.run(e.currentTarget); |
| 256 | 429 | }} |
| 257 | 430 | > |
| 258 | - <input name="user_id" placeholder="Student id" required /> | |
| 259 | - <input | |
| 260 | - name="mark" | |
| 261 | - type="number" | |
| 262 | - placeholder="Mark" | |
| 263 | - required | |
| 264 | - min={LIMITS.mark.min} | |
| 265 | - max={LIMITS.mark.max} | |
| 266 | - /> | |
| 431 | + <UserPicker name="user_id" label={t("student")} /> | |
| 432 | + <label> | |
| 433 | + {t("mark0100")} | |
| 434 | + <input | |
| 435 | + name="mark" | |
| 436 | + type="number" | |
| 437 | + required | |
| 438 | + min={LIMITS.mark.min} | |
| 439 | + max={LIMITS.mark.max} | |
| 440 | + /> | |
| 441 | + </label> | |
| 267 | 442 | <button type="submit" disabled={grade.pending()}> |
| 268 | - Grade | |
| 443 | + {t("gradeAction")} | |
| 269 | 444 | </button> |
| 270 | 445 | </form> |
| 271 | 446 | <ErrorLine error={grade.error() ?? removeResult.error()} /> |
| 272 | 447 | |
| 273 | 448 | <Show when={!results.loading} fallback={<Loading />}> |
| 274 | - <Show when={results()?.length} fallback={<Empty>No results yet.</Empty>}> | |
| 449 | + <Show when={results()?.length} fallback={<Empty>{t("noResultsYet")}</Empty>}> | |
| 275 | 450 | <div class="table-wrap"> |
| 276 | 451 | <table> |
| 277 | 452 | <thead> |
| 278 | 453 | <tr> |
| 279 | - <th>Student</th> | |
| 280 | - <th>Mark</th> | |
| 454 | + <th>{t("student")}</th> | |
| 455 | + <th>{t("markCol")}</th> | |
| 281 | 456 | <th /> |
| 282 | 457 | </tr> |
| 283 | 458 | </thead> |
| @@ -285,16 +460,19 @@ function Results(props: { examId: string }) { | ||
| 285 | 460 | <For each={results()}> |
| 286 | 461 | {(result) => ( |
| 287 | 462 | <tr> |
| 288 | - <td class="mono">{result.user === user()?.id ? "you" : result.user}</td> | |
| 463 | + <td> | |
| 464 | + {personLabel(result.user)} | |
| 465 | + <Show when={result.user.id === user()?.id}>{t("you")}</Show> | |
| 466 | + </td> | |
| 289 | 467 | <td>{result.mark}</td> |
| 290 | 468 | <td> |
| 291 | - <button | |
| 292 | - class="ghost danger" | |
| 469 | + <ConfirmButton | |
| 470 | + confirmText={t("reallyRemove")} | |
| 293 | 471 | disabled={removeResult.pending()} |
| 294 | - onClick={() => void removeResult.run(result)} | |
| 472 | + onConfirm={() => void removeResult.run(result)} | |
| 295 | 473 | > |
| 296 | - Remove | |
| 297 | - </button> | |
| 474 | + {t("remove")} | |
| 475 | + </ConfirmButton> | |
| 298 | 476 | </td> |
| 299 | 477 | </tr> |
| 300 | 478 | )} |
| @@ -309,9 +487,9 @@ function Results(props: { examId: string }) { | ||
| 309 | 487 | } |
| 310 | 488 | |
| 311 | 489 | function NotFoundMessage(props: { error: unknown }) { |
| 312 | - const message = | |
| 490 | + const message = () => | |
| 313 | 491 | props.error instanceof ApiError && props.error.status === 404 |
| 314 | - ? "This exam does not exist." | |
| 315 | - : "Failed to load the exam."; | |
| 316 | - return <Empty>{message}</Empty>; | |
| 492 | + ? t("examMissing") | |
| 493 | + : t("examLoadFailed"); | |
| 494 | + return <Empty>{message()}</Empty>; | |
| 317 | 495 | } |
src/pages/ExamRoom.tsxadded+370 -0
| @@ -0,0 +1,370 @@ | ||
| 1 | +// The room a student sits a scheduled exam in: a server-judged countdown, | |
| 2 | +// one card per question, and autosave on every change — over the exam | |
| 3 | +// WebSocket when it's up, plain REST when it isn't. The page never *starts* | |
| 4 | +// an attempt (entering is an explicit choice on the exam page, because an | |
| 5 | +// async timer starts ticking); it resumes, reviews, or bounces back. | |
| 6 | + | |
| 7 | +import { A, useParams } from "@solidjs/router"; | |
| 8 | +import { | |
| 9 | + For, | |
| 10 | + Match, | |
| 11 | + Show, | |
| 12 | + Switch, | |
| 13 | + createEffect, | |
| 14 | + createResource, | |
| 15 | + createSignal, | |
| 16 | + onCleanup, | |
| 17 | +} from "solid-js"; | |
| 18 | +import { ConfirmButton } from "../components/ConfirmButton"; | |
| 19 | +import { Empty, ErrorLine, Loading } from "../components/Feedback"; | |
| 20 | +import { createAction } from "../lib/action"; | |
| 21 | +import { ApiError, exams } from "../lib/api"; | |
| 22 | +import { createClock } from "../lib/clock"; | |
| 23 | +import { formatCountdown, formatMillis } from "../lib/format"; | |
| 24 | +import { t } from "../lib/i18n"; | |
| 25 | +import type { AttemptQuestion, AttemptStatus } from "../lib/types"; | |
| 26 | +import { LIMITS } from "../lib/types"; | |
| 27 | + | |
| 28 | +type SaveState = "saving" | "saved" | "error"; | |
| 29 | + | |
| 30 | +export default function ExamRoom() { | |
| 31 | + const params = useParams<{ id: string }>(); | |
| 32 | + const clock = createClock(); | |
| 33 | + onCleanup(clock.stop); | |
| 34 | + | |
| 35 | + const [exam] = createResource(() => params.id, exams.get); | |
| 36 | + const [attempt, { mutate: setAttempt }] = createResource( | |
| 37 | + () => params.id, | |
| 38 | + async (id) => { | |
| 39 | + try { | |
| 40 | + return await exams.myAttempt(id); | |
| 41 | + } catch (err) { | |
| 42 | + if (err instanceof ApiError && err.status === 404) return null; | |
| 43 | + throw err; | |
| 44 | + } | |
| 45 | + }, | |
| 46 | + ); | |
| 47 | + const [questions, { mutate: setQuestions }] = createResource( | |
| 48 | + // Questions 404 until an attempt exists — gate on it. | |
| 49 | + () => (attempt() ? params.id : undefined), | |
| 50 | + exams.attemptQuestions, | |
| 51 | + ); | |
| 52 | + | |
| 53 | + // Live attempt state: seeded by the REST fetch, then driven by WS frames. | |
| 54 | + const [status, setStatus] = createSignal<AttemptStatus | null>(null); | |
| 55 | + const [deadline, setDeadline] = createSignal<number | null>(null); | |
| 56 | + const [saveStates, setSaveStates] = createSignal<Record<string, SaveState>>({}); | |
| 57 | + const [roomError, setRoomError] = createSignal<string | null>(null); | |
| 58 | + createEffect(() => { | |
| 59 | + const current = attempt(); | |
| 60 | + if (current) { | |
| 61 | + setStatus(current.status); | |
| 62 | + setDeadline(current.deadline); | |
| 63 | + } | |
| 64 | + }); | |
| 65 | + | |
| 66 | + /** `in_progress` by the server, but also judged against the ticking clock. */ | |
| 67 | + const effectiveStatus = () => { | |
| 68 | + const current = status(); | |
| 69 | + const until = deadline(); | |
| 70 | + return current === "in_progress" && until !== null && clock.now() >= until | |
| 71 | + ? "expired" | |
| 72 | + : current; | |
| 73 | + }; | |
| 74 | + const running = () => effectiveStatus() === "in_progress"; | |
| 75 | + const remaining = () => (deadline() === null ? null : deadline()! - clock.now()); | |
| 76 | + | |
| 77 | + const answered = () => | |
| 78 | + (questions() ?? []).filter( | |
| 79 | + (q) => q.answer !== null && (q.answer.selected !== null || (q.answer.text ?? "") !== ""), | |
| 80 | + ).length; | |
| 81 | + const total = () => questions()?.length ?? 0; | |
| 82 | + | |
| 83 | + // ---- autosave plumbing ---------------------------------------------------- | |
| 84 | + let socket: WebSocket | undefined; | |
| 85 | + let reconnect: ReturnType<typeof setTimeout> | undefined; | |
| 86 | + let disposed = false; | |
| 87 | + const textTimers = new Map<string, ReturnType<typeof setTimeout>>(); | |
| 88 | + onCleanup(() => { | |
| 89 | + disposed = true; | |
| 90 | + clearTimeout(reconnect); | |
| 91 | + for (const timer of textTimers.values()) clearTimeout(timer); | |
| 92 | + socket?.close(); | |
| 93 | + }); | |
| 94 | + | |
| 95 | + const markSave = (id: string, state: SaveState) => | |
| 96 | + setSaveStates((current) => ({ ...current, [id]: state })); | |
| 97 | + | |
| 98 | + const connect = () => { | |
| 99 | + if (disposed || socket !== undefined) return; | |
| 100 | + const ws = new WebSocket(exams.attemptSocketUrl(params.id)); | |
| 101 | + socket = ws; | |
| 102 | + ws.onmessage = (event) => { | |
| 103 | + const frame = JSON.parse(String(event.data)) as Record<string, unknown>; | |
| 104 | + switch (frame.type) { | |
| 105 | + case "state": | |
| 106 | + setStatus(frame.status as AttemptStatus); | |
| 107 | + setDeadline((frame.deadline as number | null) ?? null); | |
| 108 | + break; | |
| 109 | + case "saved": | |
| 110 | + markSave(String(frame.question_id), "saved"); | |
| 111 | + setRoomError(null); | |
| 112 | + break; | |
| 113 | + case "finished": | |
| 114 | + setStatus("submitted"); | |
| 115 | + break; | |
| 116 | + case "expired": | |
| 117 | + setStatus("expired"); | |
| 118 | + break; | |
| 119 | + case "error": | |
| 120 | + setRoomError(String(frame.message)); | |
| 121 | + break; | |
| 122 | + } | |
| 123 | + }; | |
| 124 | + ws.onclose = () => { | |
| 125 | + if (socket === ws) socket = undefined; | |
| 126 | + // While the exam still runs, quietly retry; REST keeps saves flowing. | |
| 127 | + if (!disposed && running()) reconnect = setTimeout(connect, 3000); | |
| 128 | + }; | |
| 129 | + }; | |
| 130 | + createEffect(() => { | |
| 131 | + if (running()) connect(); | |
| 132 | + }); | |
| 133 | + | |
| 134 | + /** Save one answer: WS when open (acked by a `saved` frame), REST otherwise. */ | |
| 135 | + const push = (questionId: string, payload: { selected?: number; text?: string }) => { | |
| 136 | + markSave(questionId, "saving"); | |
| 137 | + if (socket?.readyState === WebSocket.OPEN) { | |
| 138 | + socket.send(JSON.stringify({ type: "answer", question_id: questionId, ...payload })); | |
| 139 | + return; | |
| 140 | + } | |
| 141 | + exams | |
| 142 | + .saveAnswer(params.id, { question_id: questionId, ...payload }) | |
| 143 | + .then(() => { | |
| 144 | + markSave(questionId, "saved"); | |
| 145 | + setRoomError(null); | |
| 146 | + }) | |
| 147 | + .catch((err: unknown) => { | |
| 148 | + markSave(questionId, "error"); | |
| 149 | + setRoomError(err instanceof Error ? err.message : t("savingFailed")); | |
| 150 | + }); | |
| 151 | + }; | |
| 152 | + | |
| 153 | + const patchAnswer = (questionId: string, patch: { selected?: number; text?: string }) => | |
| 154 | + setQuestions((current) => | |
| 155 | + current?.map((q) => | |
| 156 | + q.id === questionId | |
| 157 | + ? { | |
| 158 | + ...q, | |
| 159 | + answer: { | |
| 160 | + selected: patch.selected ?? null, | |
| 161 | + text: patch.text ?? null, | |
| 162 | + updated_at: clock.now(), | |
| 163 | + }, | |
| 164 | + } | |
| 165 | + : q, | |
| 166 | + ), | |
| 167 | + ); | |
| 168 | + | |
| 169 | + const pickChoice = (questionId: string, index: number) => { | |
| 170 | + patchAnswer(questionId, { selected: index }); | |
| 171 | + push(questionId, { selected: index }); | |
| 172 | + }; | |
| 173 | + | |
| 174 | + const typeText = (questionId: string, value: string) => { | |
| 175 | + patchAnswer(questionId, { text: value }); | |
| 176 | + markSave(questionId, "saving"); | |
| 177 | + clearTimeout(textTimers.get(questionId)); | |
| 178 | + textTimers.set( | |
| 179 | + questionId, | |
| 180 | + setTimeout(() => push(questionId, { text: value }), 800), | |
| 181 | + ); | |
| 182 | + }; | |
| 183 | + | |
| 184 | + const finish = createAction(async () => { | |
| 185 | + const finished = await exams.finishAttempt(params.id); | |
| 186 | + setAttempt(finished); | |
| 187 | + }); | |
| 188 | + | |
| 189 | + return ( | |
| 190 | + <section class="page room"> | |
| 191 | + <Show when={!attempt.loading && exam()} fallback={<Loading />}> | |
| 192 | + <Switch> | |
| 193 | + <Match when={attempt() === null}> | |
| 194 | + <Empty | |
| 195 | + action={ | |
| 196 | + <A class="button-link" href={`/exams/${params.id}`}> | |
| 197 | + {t("backToExam")} | |
| 198 | + </A> | |
| 199 | + } | |
| 200 | + > | |
| 201 | + {t("notEnteredYet")} | |
| 202 | + </Empty> | |
| 203 | + </Match> | |
| 204 | + <Match when={attempt()}> | |
| 205 | + <> | |
| 206 | + <header class="room-head card"> | |
| 207 | + <div class="room-title"> | |
| 208 | + <h1>{exam()?.title}</h1> | |
| 209 | + <span class="meta">{t("answeredOf")(answered(), total())}</span> | |
| 210 | + </div> | |
| 211 | + <Show when={running()} fallback={<StatusChip status={effectiveStatus()} />}> | |
| 212 | + <div class="room-side"> | |
| 213 | + <Show when={remaining() !== null}> | |
| 214 | + <span | |
| 215 | + class="countdown" | |
| 216 | + classList={{ | |
| 217 | + warn: remaining()! < 5 * 60_000, | |
| 218 | + danger: remaining()! < 60_000, | |
| 219 | + }} | |
| 220 | + > | |
| 221 | + {formatCountdown(remaining()!)} | |
| 222 | + </span> | |
| 223 | + </Show> | |
| 224 | + <ConfirmButton | |
| 225 | + class="cta" | |
| 226 | + confirmText={ | |
| 227 | + answered() < total() | |
| 228 | + ? t("turnInUnanswered")(total() - answered()) | |
| 229 | + : t("turnInNow") | |
| 230 | + } | |
| 231 | + disabled={finish.pending()} | |
| 232 | + onConfirm={() => void finish.run()} | |
| 233 | + > | |
| 234 | + {t("turnIn")} | |
| 235 | + </ConfirmButton> | |
| 236 | + </div> | |
| 237 | + </Show> | |
| 238 | + </header> | |
| 239 | + | |
| 240 | + <Show when={effectiveStatus() === "submitted"}> | |
| 241 | + <div class="card notice-ok"> | |
| 242 | + {t("turnedInBanner")(formatMillis(attempt()!.finished_at))} | |
| 243 | + </div> | |
| 244 | + </Show> | |
| 245 | + <Show when={effectiveStatus() === "expired"}> | |
| 246 | + <div class="card notice-warn">{t("timeUpBanner")}</div> | |
| 247 | + </Show> | |
| 248 | + <ErrorLine error={roomError() ?? finish.error()} /> | |
| 249 | + | |
| 250 | + <Show when={!questions.loading} fallback={<Loading />}> | |
| 251 | + <Show | |
| 252 | + when={total()} | |
| 253 | + fallback={<Empty>{t("noQuestionsRoom")}</Empty>} | |
| 254 | + > | |
| 255 | + <div class="stack"> | |
| 256 | + <For each={questions()}> | |
| 257 | + {(question, index) => ( | |
| 258 | + <QuestionCard | |
| 259 | + question={question} | |
| 260 | + number={index() + 1} | |
| 261 | + disabled={!running()} | |
| 262 | + saveState={saveStates()[question.id]} | |
| 263 | + onPick={(choice) => pickChoice(question.id, choice)} | |
| 264 | + onType={(value) => typeText(question.id, value)} | |
| 265 | + /> | |
| 266 | + )} | |
| 267 | + </For> | |
| 268 | + </div> | |
| 269 | + <Show when={running()}> | |
| 270 | + <span class="row-actions room-foot"> | |
| 271 | + <ConfirmButton | |
| 272 | + class="cta" | |
| 273 | + confirmText={ | |
| 274 | + answered() < total() | |
| 275 | + ? t("turnInUnanswered")(total() - answered()) | |
| 276 | + : t("turnInNow") | |
| 277 | + } | |
| 278 | + disabled={finish.pending()} | |
| 279 | + onConfirm={() => void finish.run()} | |
| 280 | + > | |
| 281 | + {t("turnIn")} | |
| 282 | + </ConfirmButton> | |
| 283 | + </span> | |
| 284 | + </Show> | |
| 285 | + </Show> | |
| 286 | + </Show> | |
| 287 | + | |
| 288 | + <p class="meta"> | |
| 289 | + <A href={`/exams/${params.id}`}>← {t("backToExam")}</A> | |
| 290 | + </p> | |
| 291 | + </> | |
| 292 | + </Match> | |
| 293 | + </Switch> | |
| 294 | + </Show> | |
| 295 | + </section> | |
| 296 | + ); | |
| 297 | +} | |
| 298 | + | |
| 299 | +function StatusChip(props: { status: AttemptStatus | null }) { | |
| 300 | + return ( | |
| 301 | + <Switch> | |
| 302 | + <Match when={props.status === "submitted"}> | |
| 303 | + <span class="badge phase-closed">{t("turnedInChip")}</span> | |
| 304 | + </Match> | |
| 305 | + <Match when={props.status === "expired"}> | |
| 306 | + <span class="badge phase-closed">{t("timeUpChip")}</span> | |
| 307 | + </Match> | |
| 308 | + </Switch> | |
| 309 | + ); | |
| 310 | +} | |
| 311 | + | |
| 312 | +function QuestionCard(props: { | |
| 313 | + question: AttemptQuestion; | |
| 314 | + number: number; | |
| 315 | + disabled: boolean; | |
| 316 | + saveState: SaveState | undefined; | |
| 317 | + onPick: (choice: number) => void; | |
| 318 | + onType: (value: string) => void; | |
| 319 | +}) { | |
| 320 | + return ( | |
| 321 | + <div class="card stack question"> | |
| 322 | + <header class="row"> | |
| 323 | + <strong>Q{props.number}</strong> | |
| 324 | + <span class="badge">{t("pts")(props.question.points)}</span> | |
| 325 | + <span class="push save-state" classList={{ error: props.saveState === "error" }}> | |
| 326 | + <Switch> | |
| 327 | + <Match when={props.saveState === "saving"}>{t("savingState")}</Match> | |
| 328 | + <Match when={props.saveState === "saved"}>{t("savedState")}</Match> | |
| 329 | + <Match when={props.saveState === "error"}>{t("notSavedState")}</Match> | |
| 330 | + </Switch> | |
| 331 | + </span> | |
| 332 | + </header> | |
| 333 | + <p class="prewrap qtext">{props.question.text}</p> | |
| 334 | + <Show | |
| 335 | + when={props.question.kind === "choice"} | |
| 336 | + fallback={ | |
| 337 | + <textarea | |
| 338 | + rows={4} | |
| 339 | + maxLength={LIMITS.answerText} | |
| 340 | + placeholder={t("writeAnswerHere")} | |
| 341 | + disabled={props.disabled} | |
| 342 | + onInput={(e) => props.onType(e.currentTarget.value)} | |
| 343 | + > | |
| 344 | + {props.question.answer?.text ?? ""} | |
| 345 | + </textarea> | |
| 346 | + } | |
| 347 | + > | |
| 348 | + <div class="stack choice-pick"> | |
| 349 | + <For each={props.question.choices}> | |
| 350 | + {(choice, index) => ( | |
| 351 | + <label | |
| 352 | + class="choice-row" | |
| 353 | + classList={{ picked: props.question.answer?.selected === index() }} | |
| 354 | + > | |
| 355 | + <input | |
| 356 | + type="radio" | |
| 357 | + name={`q-${props.question.id}`} | |
| 358 | + checked={props.question.answer?.selected === index()} | |
| 359 | + disabled={props.disabled} | |
| 360 | + onChange={() => props.onPick(index())} | |
| 361 | + /> | |
| 362 | + <span>{choice}</span> | |
| 363 | + </label> | |
| 364 | + )} | |
| 365 | + </For> | |
| 366 | + </div> | |
| 367 | + </Show> | |
| 368 | + </div> | |
| 369 | + ); | |
| 370 | +} |
src/pages/Exams.tsxmodified+8 -7
| @@ -6,6 +6,7 @@ import { For, Show, createResource } from "solid-js"; | ||
| 6 | 6 | import { Empty, Loading } from "../components/Feedback"; |
| 7 | 7 | import { exams } from "../lib/api"; |
| 8 | 8 | import { useAuth } from "../lib/auth"; |
| 9 | +import { t } from "../lib/i18n"; | |
| 9 | 10 | |
| 10 | 11 | export default function Exams() { |
| 11 | 12 | const { can } = useAuth(); |
| @@ -15,28 +16,28 @@ export default function Exams() { | ||
| 15 | 16 | <section class="page"> |
| 16 | 17 | <header class="page-head"> |
| 17 | 18 | <div> |
| 18 | - <h1>Exams</h1> | |
| 19 | + <h1>{t("examsTitle")}</h1> | |
| 19 | 20 | <p class="sub"> |
| 20 | - All exams across courses. | |
| 21 | + {t("examsSubAll")} | |
| 21 | 22 | <Show when={can("teacher")}> |
| 22 | 23 | {" "} |
| 23 | - New ones are created inside a <A href="/courses">course</A>. | |
| 24 | + <A href="/courses">{t("examsSubCreate")}</A> | |
| 24 | 25 | </Show> |
| 25 | 26 | </p> |
| 26 | 27 | </div> |
| 27 | 28 | </header> |
| 28 | 29 | |
| 29 | 30 | <Show when={!list.loading} fallback={<Loading />}> |
| 30 | - <Show when={list()?.length} fallback={<Empty>No exams yet.</Empty>}> | |
| 31 | + <Show when={list()?.length} fallback={<Empty>{t("noExamsYet")}</Empty>}> | |
| 31 | 32 | <div class="grid"> |
| 32 | 33 | <For each={list()}> |
| 33 | 34 | {(exam) => ( |
| 34 | 35 | <A href={`/exams/${exam.id}`} class="card link-card stack"> |
| 35 | 36 | <header class="row"> |
| 36 | 37 | <h3>{exam.title}</h3> |
| 37 | - <span class="badge">{exam.kind}</span> | |
| 38 | - <span class="badge" title="weight in the course average"> | |
| 39 | - ×{exam.weight} | |
| 38 | + <span class="badge">{t("kindWord")(exam.kind)}</span> | |
| 39 | + <span class="badge" title={t("weightTitle")}> | |
| 40 | + {t("weightBadge")(exam.weight)} | |
| 40 | 41 | </span> |
| 41 | 42 | </header> |
| 42 | 43 | <Show when={exam.description}> |
src/pages/Home.tsxmodified+16 -19
| @@ -8,6 +8,7 @@ import { IconBook, IconCalendar, IconChart, IconNote } from "../components/Icons | ||
| 8 | 8 | import { courses, events, marks, notes } from "../lib/api"; |
| 9 | 9 | import { useAuth } from "../lib/auth"; |
| 10 | 10 | import { formatWindow } from "../lib/format"; |
| 11 | +import { locale, t } from "../lib/i18n"; | |
| 11 | 12 | |
| 12 | 13 | export default function Home() { |
| 13 | 14 | const { user } = useAuth(); |
| @@ -24,14 +25,10 @@ export default function Home() { | ||
| 24 | 25 | .sort((a, b) => (a.starts_at ?? Infinity) - (b.starts_at ?? Infinity)); |
| 25 | 26 | }; |
| 26 | 27 | |
| 27 | - const greeting = () => { | |
| 28 | - const hour = new Date().getHours(); | |
| 29 | - const part = hour < 12 ? "morning" : hour < 18 ? "afternoon" : "evening"; | |
| 30 | - return `Good ${part}, ${user()?.name ?? user()?.username}`; | |
| 31 | - }; | |
| 32 | - const today = new Intl.DateTimeFormat(undefined, { dateStyle: "full" }).format( | |
| 33 | - new Date(), | |
| 34 | - ); | |
| 28 | + const greeting = () => | |
| 29 | + t("greeting")(user()?.name ?? user()?.username ?? "", new Date().getHours()); | |
| 30 | + const today = () => | |
| 31 | + new Intl.DateTimeFormat(locale(), { dateStyle: "full" }).format(new Date()); | |
| 35 | 32 | |
| 36 | 33 | const average = () => { |
| 37 | 34 | const value = report()?.overall_average; |
| @@ -43,32 +40,32 @@ export default function Home() { | ||
| 43 | 40 | <header class="page-head"> |
| 44 | 41 | <div> |
| 45 | 42 | <h1>{greeting()}</h1> |
| 46 | - <p class="sub">{today}</p> | |
| 43 | + <p class="sub">{today()}</p> | |
| 47 | 44 | </div> |
| 48 | 45 | </header> |
| 49 | 46 | |
| 50 | 47 | <div class="stats"> |
| 51 | 48 | <A href="/notes" class="card link-card stat"> |
| 52 | 49 | <span class="stat-label"> |
| 53 | - <IconNote /> Notes | |
| 50 | + <IconNote /> {t("statNotes")} | |
| 54 | 51 | </span> |
| 55 | 52 | <span class="stat-value">{noteList()?.length ?? "—"}</span> |
| 56 | 53 | </A> |
| 57 | 54 | <A href="/events" class="card link-card stat"> |
| 58 | 55 | <span class="stat-label"> |
| 59 | - <IconCalendar /> Upcoming events | |
| 56 | + <IconCalendar /> {t("statUpcoming")} | |
| 60 | 57 | </span> |
| 61 | 58 | <span class="stat-value">{eventList() ? upcoming().length : "—"}</span> |
| 62 | 59 | </A> |
| 63 | 60 | <A href="/courses" class="card link-card stat"> |
| 64 | 61 | <span class="stat-label"> |
| 65 | - <IconBook /> My courses | |
| 62 | + <IconBook /> {t("statMyCourses")} | |
| 66 | 63 | </span> |
| 67 | 64 | <span class="stat-value">{myCourses()?.length ?? "—"}</span> |
| 68 | 65 | </A> |
| 69 | 66 | <A href="/marks" class="card link-card stat"> |
| 70 | 67 | <span class="stat-label"> |
| 71 | - <IconChart /> Average | |
| 68 | + <IconChart /> {t("statAverage")} | |
| 72 | 69 | </span> |
| 73 | 70 | <span class="stat-value"> |
| 74 | 71 | {average() ?? "—"} |
| @@ -82,11 +79,11 @@ export default function Home() { | ||
| 82 | 79 | <div class="cols"> |
| 83 | 80 | <section class="stack"> |
| 84 | 81 | <div class="section-head"> |
| 85 | - <h2>Upcoming events</h2> | |
| 86 | - <A href="/events">View all</A> | |
| 82 | + <h2>{t("upcomingEvents")}</h2> | |
| 83 | + <A href="/events">{t("viewAll")}</A> | |
| 87 | 84 | </div> |
| 88 | 85 | <Show when={!eventList.loading} fallback={<Loading />}> |
| 89 | - <Show when={upcoming().length} fallback={<Empty>Nothing scheduled.</Empty>}> | |
| 86 | + <Show when={upcoming().length} fallback={<Empty>{t("nothingScheduled")}</Empty>}> | |
| 90 | 87 | <For each={upcoming().slice(0, 4)}> |
| 91 | 88 | {(event) => ( |
| 92 | 89 | <A href={`/events/${event.id}`} class="card link-card stack"> |
| @@ -101,13 +98,13 @@ export default function Home() { | ||
| 101 | 98 | |
| 102 | 99 | <section class="stack"> |
| 103 | 100 | <div class="section-head"> |
| 104 | - <h2>My courses</h2> | |
| 105 | - <A href="/courses">View all</A> | |
| 101 | + <h2>{t("myCourses")}</h2> | |
| 102 | + <A href="/courses">{t("viewAll")}</A> | |
| 106 | 103 | </div> |
| 107 | 104 | <Show when={!myCourses.loading} fallback={<Loading />}> |
| 108 | 105 | <Show |
| 109 | 106 | when={myCourses()?.length} |
| 110 | - fallback={<Empty>Not enrolled in any course yet.</Empty>} | |
| 107 | + fallback={<Empty>{t("notEnrolledYet")}</Empty>} | |
| 111 | 108 | > |
| 112 | 109 | <For each={myCourses()?.slice(0, 4)}> |
| 113 | 110 | {(course) => ( |
src/pages/Login.tsxmodified+36 -18
| @@ -4,15 +4,17 @@ | ||
| 4 | 4 | import { Navigate, useNavigate } from "@solidjs/router"; |
| 5 | 5 | import { Show, createSignal } from "solid-js"; |
| 6 | 6 | import { ErrorLine } from "../components/Feedback"; |
| 7 | -import { IconPlane } from "../components/Icons"; | |
| 7 | +import { IconEye, IconEyeOff, IconPlane } from "../components/Icons"; | |
| 8 | 8 | import { createAction } from "../lib/action"; |
| 9 | 9 | import { useAuth } from "../lib/auth"; |
| 10 | +import { lang, setLang, t } from "../lib/i18n"; | |
| 10 | 11 | import { LIMITS } from "../lib/types"; |
| 11 | 12 | |
| 12 | 13 | export default function Login() { |
| 13 | 14 | const { user, login, register } = useAuth(); |
| 14 | 15 | const navigate = useNavigate(); |
| 15 | 16 | const [mode, setMode] = createSignal<"login" | "register">("login"); |
| 17 | + const [showPassword, setShowPassword] = createSignal(false); | |
| 16 | 18 | |
| 17 | 19 | const submit = createAction(async (form: HTMLFormElement) => { |
| 18 | 20 | const data = new FormData(form); |
| @@ -44,14 +46,10 @@ export default function Login() { | ||
| 44 | 46 | <IconPlane /> |
| 45 | 47 | </span> |
| 46 | 48 | <h1>Hezarfen</h1> |
| 47 | - <p> | |
| 48 | - {mode() === "login" | |
| 49 | - ? "Welcome back — log in to continue." | |
| 50 | - : "Create an account to get started."} | |
| 51 | - </p> | |
| 49 | + <p>{mode() === "login" ? t("loginWelcome") : t("registerWelcome")}</p> | |
| 52 | 50 | </header> |
| 53 | 51 | <label> |
| 54 | - Username | |
| 52 | + {t("username")} | |
| 55 | 53 | <input |
| 56 | 54 | name="username" |
| 57 | 55 | required |
| @@ -62,22 +60,42 @@ export default function Login() { | ||
| 62 | 60 | /> |
| 63 | 61 | </label> |
| 64 | 62 | <label> |
| 65 | - Password | |
| 66 | - <input | |
| 67 | - name="password" | |
| 68 | - type="password" | |
| 69 | - required | |
| 70 | - minLength={LIMITS.password.min} | |
| 71 | - maxLength={LIMITS.password.max} | |
| 72 | - autocomplete={mode() === "login" ? "current-password" : "new-password"} | |
| 73 | - /> | |
| 63 | + {t("password")} | |
| 64 | + <span class="input-group"> | |
| 65 | + <input | |
| 66 | + name="password" | |
| 67 | + type={showPassword() ? "text" : "password"} | |
| 68 | + required | |
| 69 | + minLength={LIMITS.password.min} | |
| 70 | + maxLength={LIMITS.password.max} | |
| 71 | + autocomplete={mode() === "login" ? "current-password" : "new-password"} | |
| 72 | + /> | |
| 73 | + <button | |
| 74 | + type="button" | |
| 75 | + class="ghost icon-btn" | |
| 76 | + aria-label={showPassword() ? t("hidePassword") : t("showPassword")} | |
| 77 | + onClick={() => setShowPassword((shown) => !shown)} | |
| 78 | + > | |
| 79 | + {showPassword() ? <IconEyeOff /> : <IconEye />} | |
| 80 | + </button> | |
| 81 | + </span> | |
| 82 | + <Show when={mode() === "register"}> | |
| 83 | + <span class="hint">{t("atLeastChars")(LIMITS.password.min)}</span> | |
| 84 | + </Show> | |
| 74 | 85 | </label> |
| 75 | 86 | <ErrorLine error={submit.error()} /> |
| 76 | 87 | <button type="submit" disabled={submit.pending()}> |
| 77 | - {mode() === "login" ? "Log in" : "Create account"} | |
| 88 | + {mode() === "login" ? t("logIn") : t("createAccount")} | |
| 78 | 89 | </button> |
| 79 | 90 | <button type="button" class="ghost" onClick={switchMode}> |
| 80 | - {mode() === "login" ? "New here? Register" : "Have an account? Log in"} | |
| 91 | + {mode() === "login" ? t("switchToRegister") : t("switchToLogin")} | |
| 92 | + </button> | |
| 93 | + <button | |
| 94 | + type="button" | |
| 95 | + class="ghost lang-switch" | |
| 96 | + onClick={() => setLang(lang() === "tr" ? "en" : "tr")} | |
| 97 | + > | |
| 98 | + {t("otherLanguage")} | |
| 81 | 99 | </button> |
| 82 | 100 | </form> |
| 83 | 101 | </main> |
src/pages/Marks.tsxmodified+27 -23
| @@ -4,10 +4,13 @@ | ||
| 4 | 4 | import { A } from "@solidjs/router"; |
| 5 | 5 | import { For, Show, createResource, createSignal } from "solid-js"; |
| 6 | 6 | import { Empty, ErrorLine, Loading } from "../components/Feedback"; |
| 7 | +import { UserPicker } from "../components/UserPicker"; | |
| 7 | 8 | import { createAction } from "../lib/action"; |
| 8 | 9 | import { marks } from "../lib/api"; |
| 9 | 10 | import { useAuth } from "../lib/auth"; |
| 10 | -import type { MarksReport } from "../lib/types"; | |
| 11 | +import { personLabel } from "../lib/format"; | |
| 12 | +import { t } from "../lib/i18n"; | |
| 13 | +import type { MarksReport, PersonRef } from "../lib/types"; | |
| 11 | 14 | |
| 12 | 15 | const round = (value: number) => (Math.round(value * 100) / 100).toString(); |
| 13 | 16 | |
| @@ -19,13 +22,13 @@ export default function Marks() { | ||
| 19 | 22 | <section class="page"> |
| 20 | 23 | <header class="page-head"> |
| 21 | 24 | <div> |
| 22 | - <h1>My marks</h1> | |
| 23 | - <p class="sub">Graded exams per course, weighted averages included.</p> | |
| 25 | + <h1>{t("marksTitle")}</h1> | |
| 26 | + <p class="sub">{t("marksSub")}</p> | |
| 24 | 27 | </div> |
| 25 | 28 | </header> |
| 26 | 29 | |
| 27 | 30 | <Show when={!mine.loading} fallback={<Loading />}> |
| 28 | - <Show when={mine()} fallback={<Empty>Failed to load your marks.</Empty>}> | |
| 31 | + <Show when={mine()} fallback={<Empty>{t("marksLoadFailed")}</Empty>}> | |
| 29 | 32 | {(report) => <Report report={report()} />} |
| 30 | 33 | </Show> |
| 31 | 34 | </Show> |
| @@ -37,9 +40,10 @@ export default function Marks() { | ||
| 37 | 40 | ); |
| 38 | 41 | } |
| 39 | 42 | |
| 40 | -/** Teacher+ tool: fetch any student's report by id. */ | |
| 43 | +/** Teacher+ tool: look up any student's report. */ | |
| 41 | 44 | function Lookup() { |
| 42 | 45 | const [report, setReport] = createSignal<MarksReport | null>(null); |
| 46 | + const [who, setWho] = createSignal<PersonRef | null>(null); | |
| 43 | 47 | |
| 44 | 48 | const fetch = createAction(async (form: HTMLFormElement) => { |
| 45 | 49 | const data = new FormData(form); |
| @@ -48,17 +52,17 @@ function Lookup() { | ||
| 48 | 52 | |
| 49 | 53 | return ( |
| 50 | 54 | <article class="card stack gap-top"> |
| 51 | - <h2>Student lookup</h2> | |
| 55 | + <h2>{t("studentLookup")}</h2> | |
| 52 | 56 | <form |
| 53 | - class="row" | |
| 57 | + class="row row-end" | |
| 54 | 58 | onSubmit={(e) => { |
| 55 | 59 | e.preventDefault(); |
| 56 | 60 | void fetch.run(e.currentTarget); |
| 57 | 61 | }} |
| 58 | 62 | > |
| 59 | - <input name="user_id" placeholder="Student id" required /> | |
| 63 | + <UserPicker name="user_id" label={t("student")} onPick={setWho} /> | |
| 60 | 64 | <button type="submit" disabled={fetch.pending()}> |
| 61 | - Show marks | |
| 65 | + {t("showMarks")} | |
| 62 | 66 | </button> |
| 63 | 67 | </form> |
| 64 | 68 | <ErrorLine error={fetch.error()} /> |
| @@ -66,9 +70,9 @@ function Lookup() { | ||
| 66 | 70 | <Show when={report()}> |
| 67 | 71 | {(current) => ( |
| 68 | 72 | <> |
| 69 | - <p class="meta"> | |
| 70 | - Report for <span class="mono">{current().user}</span> | |
| 71 | - </p> | |
| 73 | + <Show when={who()}> | |
| 74 | + {(person) => <p class="meta">{t("reportFor")(personLabel(person()))}</p>} | |
| 75 | + </Show> | |
| 72 | 76 | <Report report={current()} /> |
| 73 | 77 | </> |
| 74 | 78 | )} |
| @@ -81,11 +85,11 @@ function Report(props: { report: MarksReport }) { | ||
| 81 | 85 | return ( |
| 82 | 86 | <Show |
| 83 | 87 | when={props.report.courses.length} |
| 84 | - fallback={<Empty>Not enrolled in any course.</Empty>} | |
| 88 | + fallback={<Empty>{t("notEnrolledAny")}</Empty>} | |
| 85 | 89 | > |
| 86 | 90 | <div class="stack"> |
| 87 | - <div class="card row" title="mean of the course averages"> | |
| 88 | - <span class="muted">Overall average</span> | |
| 91 | + <div class="card row" title={t("overallAverageTitle")}> | |
| 92 | + <span class="muted">{t("overallAverage")}</span> | |
| 89 | 93 | <p class="mark push"> |
| 90 | 94 | {props.report.overall_average === null ? ( |
| 91 | 95 | "—" |
| @@ -105,22 +109,22 @@ function Report(props: { report: MarksReport }) { | ||
| 105 | 109 | <h3> |
| 106 | 110 | <A href={`/courses/${block.course.id}`}>{block.course.title}</A> |
| 107 | 111 | </h3> |
| 108 | - <span class="badge" title="weighted course average"> | |
| 112 | + <span class="badge" title={t("courseAverageTitle")}> | |
| 109 | 113 | {block.average === null ? "—" : round(block.average)} |
| 110 | 114 | </span> |
| 111 | 115 | </header> |
| 112 | 116 | <Show |
| 113 | 117 | when={block.results.length} |
| 114 | - fallback={<Empty>Nothing graded yet.</Empty>} | |
| 118 | + fallback={<Empty>{t("nothingGradedYet")}</Empty>} | |
| 115 | 119 | > |
| 116 | 120 | <div class="table-wrap"> |
| 117 | 121 | <table> |
| 118 | 122 | <thead> |
| 119 | 123 | <tr> |
| 120 | - <th>Exam</th> | |
| 121 | - <th>Kind</th> | |
| 122 | - <th>Weight</th> | |
| 123 | - <th>Mark</th> | |
| 124 | + <th>{t("examCol")}</th> | |
| 125 | + <th>{t("kind")}</th> | |
| 126 | + <th>{t("weight")}</th> | |
| 127 | + <th>{t("markCol")}</th> | |
| 124 | 128 | </tr> |
| 125 | 129 | </thead> |
| 126 | 130 | <tbody> |
| @@ -131,9 +135,9 @@ function Report(props: { report: MarksReport }) { | ||
| 131 | 135 | <A href={`/exams/${entry.exam}`}>{entry.title}</A> |
| 132 | 136 | </td> |
| 133 | 137 | <td> |
| 134 | - <span class="badge">{entry.kind}</span> | |
| 138 | + <span class="badge">{t("kindWord")(entry.kind)}</span> | |
| 135 | 139 | </td> |
| 136 | - <td>×{entry.weight}</td> | |
| 140 | + <td>{t("weightBadge")(entry.weight)}</td> | |
| 137 | 141 | <td>{entry.mark}</td> |
| 138 | 142 | </tr> |
| 139 | 143 | )} |
src/pages/NotFound.tsxmodified+3 -2
| @@ -1,12 +1,13 @@ | ||
| 1 | 1 | import { A } from "@solidjs/router"; |
| 2 | +import { t } from "../lib/i18n"; | |
| 2 | 3 | |
| 3 | 4 | export default function NotFound() { |
| 4 | 5 | return ( |
| 5 | 6 | <main class="auth-page"> |
| 6 | 7 | <div class="card stack" style={{ "text-align": "center", padding: "2.5rem 3rem" }}> |
| 7 | 8 | <h1 style={{ "font-size": "2.5rem" }}>404</h1> |
| 8 | - <p class="muted">This page flew away.</p> | |
| 9 | - <A href="/">Back home</A> | |
| 9 | + <p class="muted">{t("pageFlewAway")}</p> | |
| 10 | + <A href="/">{t("backHome")}</A> | |
| 10 | 11 | </div> |
| 11 | 12 | </main> |
| 12 | 13 | ); |
src/pages/Notes.tsxmodified+59 -44
| @@ -2,10 +2,12 @@ | ||
| 2 | 2 | // the resource from the server's response — the UI never waits on a refetch. |
| 3 | 3 | |
| 4 | 4 | import { For, Show, createResource, createSignal } from "solid-js"; |
| 5 | +import { ConfirmButton } from "../components/ConfirmButton"; | |
| 5 | 6 | import { Empty, ErrorLine, Loading } from "../components/Feedback"; |
| 6 | 7 | import { IconEdit, IconPlus, IconTrash } from "../components/Icons"; |
| 7 | 8 | import { createAction } from "../lib/action"; |
| 8 | 9 | import { notes } from "../lib/api"; |
| 10 | +import { t } from "../lib/i18n"; | |
| 9 | 11 | import { LIMITS, type Note } from "../lib/types"; |
| 10 | 12 | |
| 11 | 13 | export default function Notes() { |
| @@ -31,11 +33,11 @@ export default function Notes() { | ||
| 31 | 33 | <section class="page"> |
| 32 | 34 | <header class="page-head"> |
| 33 | 35 | <div> |
| 34 | - <h1>Notes</h1> | |
| 35 | - <p class="sub">Your personal scratchpad — visible only to you.</p> | |
| 36 | + <h1>{t("notesTitle")}</h1> | |
| 37 | + <p class="sub">{t("notesSub")}</p> | |
| 36 | 38 | </div> |
| 37 | 39 | <button onClick={() => setCreating((open) => !open)}> |
| 38 | - <IconPlus /> New note | |
| 40 | + <IconPlus /> {t("newNote")} | |
| 39 | 41 | </button> |
| 40 | 42 | </header> |
| 41 | 43 | |
| @@ -47,26 +49,31 @@ export default function Notes() { | ||
| 47 | 49 | void create.run(e.currentTarget); |
| 48 | 50 | }} |
| 49 | 51 | > |
| 50 | - <input | |
| 51 | - name="title" | |
| 52 | - placeholder="Title" | |
| 53 | - required | |
| 54 | - maxLength={LIMITS.noteTitle} | |
| 55 | - ref={(el) => queueMicrotask(() => el.focus())} | |
| 56 | - /> | |
| 57 | - <textarea | |
| 58 | - name="content" | |
| 59 | - placeholder="Write something…" | |
| 60 | - rows={3} | |
| 61 | - maxLength={LIMITS.noteContent} | |
| 62 | - /> | |
| 52 | + <label> | |
| 53 | + {t("title")} | |
| 54 | + <input | |
| 55 | + name="title" | |
| 56 | + required | |
| 57 | + maxLength={LIMITS.noteTitle} | |
| 58 | + ref={(el) => queueMicrotask(() => el.focus())} | |
| 59 | + /> | |
| 60 | + </label> | |
| 61 | + <label> | |
| 62 | + {t("content")} | |
| 63 | + <textarea | |
| 64 | + name="content" | |
| 65 | + placeholder={t("writeSomething")} | |
| 66 | + rows={3} | |
| 67 | + maxLength={LIMITS.noteContent} | |
| 68 | + /> | |
| 69 | + </label> | |
| 63 | 70 | <ErrorLine error={create.error()} /> |
| 64 | 71 | <span class="row-actions"> |
| 65 | 72 | <button type="submit" disabled={create.pending()}> |
| 66 | - Add note | |
| 73 | + {t("addNote")} | |
| 67 | 74 | </button> |
| 68 | 75 | <button type="button" class="ghost" onClick={() => setCreating(false)}> |
| 69 | - Cancel | |
| 76 | + {t("cancel")} | |
| 70 | 77 | </button> |
| 71 | 78 | </span> |
| 72 | 79 | </form> |
| @@ -75,7 +82,17 @@ export default function Notes() { | ||
| 75 | 82 | <Show when={!list.loading} fallback={<Loading />}> |
| 76 | 83 | <Show |
| 77 | 84 | when={list()?.length} |
| 78 | - fallback={<Empty>No notes yet — write your first one.</Empty>} | |
| 85 | + fallback={ | |
| 86 | + <Empty | |
| 87 | + action={ | |
| 88 | + <button onClick={() => setCreating(true)}> | |
| 89 | + <IconPlus /> {t("newNote")} | |
| 90 | + </button> | |
| 91 | + } | |
| 92 | + > | |
| 93 | + {t("noNotesYet")} | |
| 94 | + </Empty> | |
| 95 | + } | |
| 79 | 96 | > |
| 80 | 97 | <div class="grid"> |
| 81 | 98 | <For each={list()}> |
| @@ -119,28 +136,13 @@ function NoteCard(props: { | ||
| 119 | 136 | <> |
| 120 | 137 | <header class="row"> |
| 121 | 138 | <h3>{props.note.title}</h3> |
| 122 | - <span class="row-actions"> | |
| 123 | - <button | |
| 124 | - class="ghost icon-btn" | |
| 125 | - title="Edit" | |
| 126 | - onClick={() => setEditing(true)} | |
| 127 | - > | |
| 128 | - <IconEdit /> | |
| 129 | - </button> | |
| 130 | - <button | |
| 131 | - class="ghost icon-btn danger" | |
| 132 | - title="Delete" | |
| 133 | - disabled={remove.pending()} | |
| 134 | - onClick={() => void remove.run()} | |
| 135 | - > | |
| 136 | - <IconTrash /> | |
| 137 | - </button> | |
| 138 | - </span> | |
| 139 | + <button class="ghost" onClick={() => setEditing(true)}> | |
| 140 | + <IconEdit /> {t("edit")} | |
| 141 | + </button> | |
| 139 | 142 | </header> |
| 140 | 143 | <Show when={props.note.content}> |
| 141 | 144 | <p class="prewrap">{props.note.content}</p> |
| 142 | 145 | </Show> |
| 143 | - <ErrorLine error={remove.error()} /> | |
| 144 | 146 | </> |
| 145 | 147 | } |
| 146 | 148 | > |
| @@ -151,18 +153,31 @@ function NoteCard(props: { | ||
| 151 | 153 | void save.run(e.currentTarget); |
| 152 | 154 | }} |
| 153 | 155 | > |
| 154 | - <input name="title" value={props.note.title} required maxLength={LIMITS.noteTitle} /> | |
| 155 | - <textarea name="content" rows={4} maxLength={LIMITS.noteContent}> | |
| 156 | - {props.note.content} | |
| 157 | - </textarea> | |
| 158 | - <ErrorLine error={save.error()} /> | |
| 156 | + <label> | |
| 157 | + {t("title")} | |
| 158 | + <input name="title" value={props.note.title} required maxLength={LIMITS.noteTitle} /> | |
| 159 | + </label> | |
| 160 | + <label> | |
| 161 | + {t("content")} | |
| 162 | + <textarea name="content" rows={4} maxLength={LIMITS.noteContent}> | |
| 163 | + {props.note.content} | |
| 164 | + </textarea> | |
| 165 | + </label> | |
| 166 | + <ErrorLine error={save.error() ?? remove.error()} /> | |
| 159 | 167 | <span class="row-actions"> |
| 160 | 168 | <button type="submit" disabled={save.pending()}> |
| 161 | - Save | |
| 169 | + {t("save")} | |
| 162 | 170 | </button> |
| 163 | 171 | <button type="button" class="ghost" onClick={() => setEditing(false)}> |
| 164 | - Cancel | |
| 172 | + {t("cancel")} | |
| 165 | 173 | </button> |
| 174 | + <ConfirmButton | |
| 175 | + class="ghost danger push" | |
| 176 | + disabled={remove.pending()} | |
| 177 | + onConfirm={() => void remove.run()} | |
| 178 | + > | |
| 179 | + <IconTrash /> {t("deleteNote")} | |
| 180 | + </ConfirmButton> | |
| 166 | 181 | </span> |
| 167 | 182 | </form> |
| 168 | 183 | </Show> |
src/pages/Profile.tsxmodified+7 -6
| @@ -8,6 +8,7 @@ import { ProfileFields, profilePatch } from "../components/ProfileFields"; | ||
| 8 | 8 | import { createAction } from "../lib/action"; |
| 9 | 9 | import { users } from "../lib/api"; |
| 10 | 10 | import { useAuth } from "../lib/auth"; |
| 11 | +import { t } from "../lib/i18n"; | |
| 11 | 12 | |
| 12 | 13 | export default function Profile() { |
| 13 | 14 | const { user, update } = useAuth(); |
| @@ -34,8 +35,8 @@ export default function Profile() { | ||
| 34 | 35 | current().username} |
| 35 | 36 | </h1> |
| 36 | 37 | <p class="sub"> |
| 37 | - {current().username} · <span class="badge">{current().role}</span> ·{" "} | |
| 38 | - <span class="mono">{current().id}</span> | |
| 38 | + {current().username} ·{" "} | |
| 39 | + <span class="badge">{t("roleWord")(current().role)}</span> | |
| 39 | 40 | </p> |
| 40 | 41 | </div> |
| 41 | 42 | </div> |
| @@ -48,16 +49,16 @@ export default function Profile() { | ||
| 48 | 49 | void save.run(e.currentTarget); |
| 49 | 50 | }} |
| 50 | 51 | > |
| 51 | - <h2>Personal info</h2> | |
| 52 | - <p class="meta">Leave a field empty to clear it.</p> | |
| 52 | + <h2>{t("personalInfo")}</h2> | |
| 53 | + <p class="meta">{t("leaveEmptyToClear")}</p> | |
| 53 | 54 | <ProfileFields user={current()} /> |
| 54 | 55 | <ErrorLine error={save.error()} /> |
| 55 | 56 | <span class="row-actions"> |
| 56 | 57 | <button type="submit" disabled={save.pending()}> |
| 57 | - Save | |
| 58 | + {t("save")} | |
| 58 | 59 | </button> |
| 59 | 60 | <Show when={saved() && !save.pending()}> |
| 60 | - <span class="meta">Saved.</span> | |
| 61 | + <span class="meta">{t("savedDot")}</span> | |
| 61 | 62 | </Show> |
| 62 | 63 | </span> |
| 63 | 64 | </form> |
src/pages/Users.tsxmodified+61 -28
| @@ -8,6 +8,7 @@ import { ProfileFields, profilePatch } from "../components/ProfileFields"; | ||
| 8 | 8 | import { createAction } from "../lib/action"; |
| 9 | 9 | import { users } from "../lib/api"; |
| 10 | 10 | import { useAuth } from "../lib/auth"; |
| 11 | +import { t } from "../lib/i18n"; | |
| 11 | 12 | import { ROLES, type Role, type User } from "../lib/types"; |
| 12 | 13 | |
| 13 | 14 | export default function Users() { |
| @@ -36,26 +37,26 @@ export default function Users() { | ||
| 36 | 37 | }; |
| 37 | 38 | |
| 38 | 39 | return ( |
| 39 | - <Show when={can("admin")} fallback={<Empty>Admins only.</Empty>}> | |
| 40 | + <Show when={can("admin")} fallback={<Empty>{t("adminsOnly")}</Empty>}> | |
| 40 | 41 | <section class="page"> |
| 41 | 42 | <header class="page-head"> |
| 42 | 43 | <div> |
| 43 | - <h1>Users</h1> | |
| 44 | - <p class="sub">Every account, with roles and personal records.</p> | |
| 44 | + <h1>{t("usersTitle")}</h1> | |
| 45 | + <p class="sub">{t("usersSub")}</p> | |
| 45 | 46 | </div> |
| 46 | 47 | </header> |
| 47 | 48 | <ErrorLine error={setRole.error()} /> |
| 48 | 49 | <Show when={!list.loading} fallback={<Loading />}> |
| 49 | - <Show when={list()?.length} fallback={<Empty>No users.</Empty>}> | |
| 50 | + <Show when={list()?.length} fallback={<Empty>{t("noUsers")}</Empty>}> | |
| 50 | 51 | <div class="table-wrap"> |
| 51 | 52 | <table> |
| 52 | 53 | <thead> |
| 53 | 54 | <tr> |
| 54 | - <th>User</th> | |
| 55 | - <th>Id</th> | |
| 56 | - <th>Contact</th> | |
| 57 | - <th>Born</th> | |
| 58 | - <th>Role</th> | |
| 55 | + <th>{t("userCol")}</th> | |
| 56 | + <th>{t("idCol")}</th> | |
| 57 | + <th>{t("contactCol")}</th> | |
| 58 | + <th>{t("bornCol")}</th> | |
| 59 | + <th>{t("roleCol")}</th> | |
| 59 | 60 | <th /> |
| 60 | 61 | </tr> |
| 61 | 62 | </thead> |
| @@ -81,28 +82,18 @@ export default function Users() { | ||
| 81 | 82 | <td> |
| 82 | 83 | <Show |
| 83 | 84 | when={entry.id !== user()?.id} |
| 84 | - fallback={<em>{entry.role} (you)</em>} | |
| 85 | + fallback={<em>{t("roleWord")(entry.role)}{t("you")}</em>} | |
| 85 | 86 | > |
| 86 | - <select | |
| 87 | - value={entry.role} | |
| 88 | - disabled={setRole.pending()} | |
| 89 | - onChange={(e) => | |
| 90 | - void setRole.run(entry, e.currentTarget.value as Role) | |
| 91 | - } | |
| 92 | - > | |
| 93 | - <For each={ROLES}> | |
| 94 | - {(role) => ( | |
| 95 | - <option value={role} selected={role === entry.role}> | |
| 96 | - {role} | |
| 97 | - </option> | |
| 98 | - )} | |
| 99 | - </For> | |
| 100 | - </select> | |
| 87 | + <RoleCell | |
| 88 | + entry={entry} | |
| 89 | + pending={setRole.pending()} | |
| 90 | + onApply={(role) => setRole.run(entry, role)} | |
| 91 | + /> | |
| 101 | 92 | </Show> |
| 102 | 93 | </td> |
| 103 | 94 | <td> |
| 104 | 95 | <button class="ghost" onClick={() => toggleEdit(entry.id)}> |
| 105 | - {editing() === entry.id ? "Close" : "Edit"} | |
| 96 | + {editing() === entry.id ? t("close") : t("edit")} | |
| 106 | 97 | </button> |
| 107 | 98 | </td> |
| 108 | 99 | </tr> |
| @@ -116,12 +107,12 @@ export default function Users() { | ||
| 116 | 107 | void saveProfile.run(entry, e.currentTarget); |
| 117 | 108 | }} |
| 118 | 109 | > |
| 119 | - <p class="meta">Leave a field empty to clear it.</p> | |
| 110 | + <p class="meta">{t("leaveEmptyToClear")}</p> | |
| 120 | 111 | <ProfileFields user={entry} /> |
| 121 | 112 | <ErrorLine error={saveProfile.error()} /> |
| 122 | 113 | <span class="row-actions"> |
| 123 | 114 | <button type="submit" disabled={saveProfile.pending()}> |
| 124 | - Save profile | |
| 115 | + {t("saveProfile")} | |
| 125 | 116 | </button> |
| 126 | 117 | </span> |
| 127 | 118 | </form> |
| @@ -140,3 +131,45 @@ export default function Users() { | ||
| 140 | 131 | </Show> |
| 141 | 132 | ); |
| 142 | 133 | } |
| 134 | + | |
| 135 | +/** Role dropdown that stages the pick behind Apply/Cancel — a stray scroll | |
| 136 | + * over the select must never fire a role change on its own. */ | |
| 137 | +function RoleCell(props: { | |
| 138 | + entry: User; | |
| 139 | + pending: boolean; | |
| 140 | + onApply: (role: Role) => Promise<boolean>; | |
| 141 | +}) { | |
| 142 | + const [staged, setStaged] = createSignal<Role | null>(null); | |
| 143 | + const dirty = () => staged() !== null && staged() !== props.entry.role; | |
| 144 | + | |
| 145 | + const apply = async () => { | |
| 146 | + const next = staged(); | |
| 147 | + if (next && (await props.onApply(next))) setStaged(null); | |
| 148 | + }; | |
| 149 | + | |
| 150 | + return ( | |
| 151 | + <span class="row-actions"> | |
| 152 | + <select | |
| 153 | + value={staged() ?? props.entry.role} | |
| 154 | + disabled={props.pending} | |
| 155 | + onChange={(e) => setStaged(e.currentTarget.value as Role)} | |
| 156 | + > | |
| 157 | + <For each={ROLES}> | |
| 158 | + {(role) => ( | |
| 159 | + <option value={role} selected={role === (staged() ?? props.entry.role)}> | |
| 160 | + {t("roleWord")(role)} | |
| 161 | + </option> | |
| 162 | + )} | |
| 163 | + </For> | |
| 164 | + </select> | |
| 165 | + <Show when={dirty()}> | |
| 166 | + <button disabled={props.pending} onClick={() => void apply()}> | |
| 167 | + {t("apply")} | |
| 168 | + </button> | |
| 169 | + <button class="ghost" disabled={props.pending} onClick={() => setStaged(null)}> | |
| 170 | + {t("cancel")} | |
| 171 | + </button> | |
| 172 | + </Show> | |
| 173 | + </span> | |
| 174 | + ); | |
| 175 | +} |
src/styles.cssmodified+377 -7
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | --accent-strong: #5468f0; |
| 15 | 15 | --accent-2-strong: #7c5cf0; |
| 16 | 16 | --danger: #f27d7d; |
| 17 | + --danger-strong: #c94747; | |
| 17 | 18 | --ok: #4ecf8a; |
| 18 | 19 | --warn: #e8b44f; |
| 19 | 20 | --radius: 14px; |
| @@ -37,6 +38,7 @@ | ||
| 37 | 38 | --accent-strong: #4a5fe0; |
| 38 | 39 | --accent-2-strong: #7250e0; |
| 39 | 40 | --danger: #d64545; |
| 41 | + --danger-strong: #c23b3b; | |
| 40 | 42 | --ok: #1f9d5f; |
| 41 | 43 | --warn: #a87716; |
| 42 | 44 | --shadow: 0 1px 2px rgb(20 25 40 / 0.06); |
| @@ -53,7 +55,7 @@ body { | ||
| 53 | 55 | background: var(--bg); |
| 54 | 56 | color: var(--text); |
| 55 | 57 | font: |
| 56 | - 15px/1.55 ui-sans-serif, | |
| 58 | + 16px/1.55 ui-sans-serif, | |
| 57 | 59 | system-ui, |
| 58 | 60 | -apple-system, |
| 59 | 61 | "Segoe UI", |
| @@ -180,7 +182,7 @@ a:focus-visible { | ||
| 180 | 182 | display: flex; |
| 181 | 183 | align-items: center; |
| 182 | 184 | gap: 0.65rem; |
| 183 | - padding: 0.5rem 0.65rem; | |
| 185 | + padding: 0.6rem 0.7rem; | |
| 184 | 186 | border-radius: var(--radius-sm); |
| 185 | 187 | color: var(--muted); |
| 186 | 188 | font-weight: 500; |
| @@ -201,10 +203,28 @@ a:focus-visible { | ||
| 201 | 203 | |
| 202 | 204 | .sidebar-end { |
| 203 | 205 | display: flex; |
| 204 | - align-items: center; | |
| 206 | + flex-direction: column; | |
| 207 | + align-items: stretch; | |
| 205 | 208 | gap: 0.25rem; |
| 206 | 209 | } |
| 207 | 210 | |
| 211 | +.sidebar .logout, | |
| 212 | +.sidebar .lang-switch { | |
| 213 | + justify-content: flex-start; | |
| 214 | + padding: 0.6rem 0.7rem; | |
| 215 | + color: var(--muted); | |
| 216 | + border-color: transparent; | |
| 217 | + font-weight: 500; | |
| 218 | +} | |
| 219 | +.sidebar .lang-switch { | |
| 220 | + font-size: 0.82rem; | |
| 221 | +} | |
| 222 | +.sidebar .logout:hover:not(:disabled), | |
| 223 | +.sidebar .lang-switch:hover:not(:disabled) { | |
| 224 | + color: var(--text); | |
| 225 | + background: var(--surface-2); | |
| 226 | +} | |
| 227 | + | |
| 208 | 228 | .user-chip { |
| 209 | 229 | flex: 1; |
| 210 | 230 | min-width: 0; |
| @@ -288,7 +308,7 @@ main { | ||
| 288 | 308 | display: none; |
| 289 | 309 | } |
| 290 | 310 | .sidebar nav a { |
| 291 | - padding: 0.4rem 0.6rem; | |
| 311 | + padding: 0.5rem 0.65rem; | |
| 292 | 312 | } |
| 293 | 313 | .user-meta { |
| 294 | 314 | display: none; |
| @@ -298,6 +318,17 @@ main { | ||
| 298 | 318 | padding: 0.25rem; |
| 299 | 319 | border-radius: 50%; |
| 300 | 320 | } |
| 321 | + .sidebar-end { | |
| 322 | + flex-direction: row; | |
| 323 | + align-items: center; | |
| 324 | + } | |
| 325 | + .sidebar .logout, | |
| 326 | + .sidebar .lang-switch { | |
| 327 | + padding: 0.5rem; | |
| 328 | + } | |
| 329 | + .sidebar .logout span { | |
| 330 | + display: none; | |
| 331 | + } | |
| 301 | 332 | main { |
| 302 | 333 | padding: 1.4rem 1rem 4rem; |
| 303 | 334 | } |
| @@ -354,6 +385,12 @@ main { | ||
| 354 | 385 | flex-wrap: wrap; |
| 355 | 386 | } |
| 356 | 387 | |
| 388 | +/* A row of labeled fields plus a button: align everything to the baseline | |
| 389 | + of the inputs, not the center of the taller labeled column. */ | |
| 390 | +.row-end { | |
| 391 | + align-items: flex-end; | |
| 392 | +} | |
| 393 | + | |
| 357 | 394 | .grid { |
| 358 | 395 | display: grid; |
| 359 | 396 | grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); |
| @@ -461,7 +498,7 @@ select { | ||
| 461 | 498 | background: var(--surface-2); |
| 462 | 499 | border: 1px solid var(--border); |
| 463 | 500 | border-radius: var(--radius-sm); |
| 464 | - padding: 0.5rem 0.75rem; | |
| 501 | + padding: 0.55rem 0.8rem; | |
| 465 | 502 | transition: |
| 466 | 503 | border-color 120ms, |
| 467 | 504 | box-shadow 120ms; |
| @@ -480,6 +517,73 @@ textarea { | ||
| 480 | 517 | color: color-mix(in srgb, var(--muted) 75%, transparent); |
| 481 | 518 | } |
| 482 | 519 | |
| 520 | +/* Input with a trailing button (e.g. the show-password toggle). */ | |
| 521 | +.input-group { | |
| 522 | + display: flex; | |
| 523 | + gap: 0.4rem; | |
| 524 | +} | |
| 525 | +.input-group input { | |
| 526 | + flex: 1; | |
| 527 | + min-width: 0; | |
| 528 | +} | |
| 529 | + | |
| 530 | +/* Plain-language rule stated before the user can get it wrong. */ | |
| 531 | +.hint { | |
| 532 | + font-size: 0.8rem; | |
| 533 | + font-weight: 400; | |
| 534 | + color: var(--muted); | |
| 535 | +} | |
| 536 | + | |
| 537 | +/* --- user picker ------------------------------------------------------------ */ | |
| 538 | + | |
| 539 | +.picker { | |
| 540 | + min-width: 14rem; | |
| 541 | +} | |
| 542 | +.picker-box { | |
| 543 | + position: relative; | |
| 544 | + display: flex; | |
| 545 | + flex-direction: column; | |
| 546 | +} | |
| 547 | +.picker-menu { | |
| 548 | + position: absolute; | |
| 549 | + top: calc(100% + 4px); | |
| 550 | + left: 0; | |
| 551 | + right: 0; | |
| 552 | + z-index: 20; | |
| 553 | + display: flex; | |
| 554 | + flex-direction: column; | |
| 555 | + gap: 2px; | |
| 556 | + max-height: 15rem; | |
| 557 | + overflow-y: auto; | |
| 558 | + padding: 0.3rem; | |
| 559 | + background: var(--surface); | |
| 560 | + border: 1px solid var(--border); | |
| 561 | + border-radius: var(--radius-sm); | |
| 562 | + box-shadow: var(--shadow-lg); | |
| 563 | +} | |
| 564 | +.picker-menu p { | |
| 565 | + padding: 0.4rem 0.6rem; | |
| 566 | +} | |
| 567 | +.picker-menu button { | |
| 568 | + justify-content: flex-start; | |
| 569 | + gap: 0.5rem; | |
| 570 | + padding: 0.45rem 0.6rem; | |
| 571 | + color: var(--text); | |
| 572 | + background: transparent; | |
| 573 | + border-color: transparent; | |
| 574 | + font-weight: 500; | |
| 575 | + text-align: left; | |
| 576 | +} | |
| 577 | +.picker-menu button:hover:not(:disabled) { | |
| 578 | + background: var(--surface-2); | |
| 579 | + filter: none; | |
| 580 | +} | |
| 581 | +.picker-menu button span { | |
| 582 | + color: var(--muted); | |
| 583 | + font-size: 0.82rem; | |
| 584 | + font-weight: 400; | |
| 585 | +} | |
| 586 | + | |
| 483 | 587 | button { |
| 484 | 588 | display: inline-flex; |
| 485 | 589 | align-items: center; |
| @@ -491,7 +595,7 @@ button { | ||
| 491 | 595 | background: linear-gradient(135deg, var(--accent-strong), var(--accent-2-strong)); |
| 492 | 596 | border: 1px solid transparent; |
| 493 | 597 | border-radius: var(--radius-sm); |
| 494 | - padding: 0.5rem 0.95rem; | |
| 598 | + padding: 0.55rem 1rem; | |
| 495 | 599 | cursor: pointer; |
| 496 | 600 | transition: |
| 497 | 601 | filter 100ms, |
| @@ -530,8 +634,17 @@ button.danger:hover:not(:disabled) { | ||
| 530 | 634 | background: color-mix(in srgb, var(--danger) 9%, transparent); |
| 531 | 635 | } |
| 532 | 636 | |
| 637 | +/* An armed ConfirmButton: unmistakably hot until it disarms itself. */ | |
| 638 | +button.confirm-armed, | |
| 639 | +button.confirm-armed:hover:not(:disabled) { | |
| 640 | + color: #fff; | |
| 641 | + background: var(--danger-strong); | |
| 642 | + border-color: transparent; | |
| 643 | + filter: none; | |
| 644 | +} | |
| 645 | + | |
| 533 | 646 | button.icon-btn { |
| 534 | - padding: 0.45rem; | |
| 647 | + padding: 0.65rem; | |
| 535 | 648 | border-radius: var(--radius-sm); |
| 536 | 649 | } |
| 537 | 650 | |
| @@ -658,6 +771,10 @@ td .mono { | ||
| 658 | 771 | } |
| 659 | 772 | |
| 660 | 773 | .empty { |
| 774 | + display: flex; | |
| 775 | + flex-direction: column; | |
| 776 | + align-items: center; | |
| 777 | + gap: 0.9rem; | |
| 661 | 778 | color: var(--muted); |
| 662 | 779 | padding: 2rem 1rem; |
| 663 | 780 | text-align: center; |
| @@ -709,6 +826,259 @@ td .mono { | ||
| 709 | 826 | } |
| 710 | 827 | } |
| 711 | 828 | |
| 829 | +/* --- exams: schedule, room, monitor ----------------------------------------- */ | |
| 830 | + | |
| 831 | +/* The one action a page really wants pressed — bigger than everything else. */ | |
| 832 | +button.cta { | |
| 833 | + font-size: 1.02rem; | |
| 834 | + padding: 0.75rem 1.5rem; | |
| 835 | +} | |
| 836 | + | |
| 837 | +/* An <A> that reads as a button (empty-state actions, back links). */ | |
| 838 | +.button-link { | |
| 839 | + display: inline-flex; | |
| 840 | + align-items: center; | |
| 841 | + gap: 0.45rem; | |
| 842 | + font-weight: 600; | |
| 843 | + color: #fff; | |
| 844 | + background: linear-gradient(135deg, var(--accent-strong), var(--accent-2-strong)); | |
| 845 | + border-radius: var(--radius-sm); | |
| 846 | + padding: 0.55rem 1rem; | |
| 847 | +} | |
| 848 | +.button-link:hover { | |
| 849 | + text-decoration: none; | |
| 850 | + filter: brightness(1.08); | |
| 851 | +} | |
| 852 | + | |
| 853 | +.badge.phase-open { | |
| 854 | + color: var(--ok); | |
| 855 | + background: color-mix(in srgb, var(--ok) 12%, transparent); | |
| 856 | + border-color: color-mix(in srgb, var(--ok) 25%, transparent); | |
| 857 | +} | |
| 858 | +.badge.phase-upcoming { | |
| 859 | + color: var(--warn); | |
| 860 | + background: color-mix(in srgb, var(--warn) 12%, transparent); | |
| 861 | + border-color: color-mix(in srgb, var(--warn) 25%, transparent); | |
| 862 | +} | |
| 863 | +.badge.phase-closed, | |
| 864 | +.badge.status-expired { | |
| 865 | + color: var(--muted); | |
| 866 | + background: color-mix(in srgb, var(--muted) 12%, transparent); | |
| 867 | + border-color: color-mix(in srgb, var(--muted) 25%, transparent); | |
| 868 | +} | |
| 869 | +.badge.status-in_progress { | |
| 870 | + color: var(--ok); | |
| 871 | + background: color-mix(in srgb, var(--ok) 12%, transparent); | |
| 872 | + border-color: color-mix(in srgb, var(--ok) 25%, transparent); | |
| 873 | +} | |
| 874 | +.badge.status-not_started { | |
| 875 | + color: var(--warn); | |
| 876 | + background: color-mix(in srgb, var(--warn) 12%, transparent); | |
| 877 | + border-color: color-mix(in srgb, var(--warn) 25%, transparent); | |
| 878 | +} | |
| 879 | + | |
| 880 | +/* The student's sticky exam header: title, countdown, turn-in. */ | |
| 881 | +.room-head { | |
| 882 | + position: sticky; | |
| 883 | + top: 0.5rem; | |
| 884 | + z-index: 15; | |
| 885 | + display: flex; | |
| 886 | + align-items: center; | |
| 887 | + justify-content: space-between; | |
| 888 | + gap: 1rem; | |
| 889 | + flex-wrap: wrap; | |
| 890 | + background: color-mix(in srgb, var(--surface) 88%, transparent); | |
| 891 | + backdrop-filter: blur(10px); | |
| 892 | +} | |
| 893 | +.room-title { | |
| 894 | + display: flex; | |
| 895 | + flex-direction: column; | |
| 896 | + gap: 0.15rem; | |
| 897 | + min-width: 0; | |
| 898 | +} | |
| 899 | +.room-side { | |
| 900 | + display: flex; | |
| 901 | + align-items: center; | |
| 902 | + gap: 0.9rem; | |
| 903 | +} | |
| 904 | +.room-foot { | |
| 905 | + justify-content: center; | |
| 906 | +} | |
| 907 | + | |
| 908 | +.countdown { | |
| 909 | + font-family: ui-monospace, "JetBrains Mono", monospace; | |
| 910 | + font-size: 1.5rem; | |
| 911 | + font-weight: 650; | |
| 912 | + font-variant-numeric: tabular-nums; | |
| 913 | + letter-spacing: 0.02em; | |
| 914 | +} | |
| 915 | +.countdown.warn { | |
| 916 | + color: var(--warn); | |
| 917 | +} | |
| 918 | +.countdown.danger { | |
| 919 | + color: var(--danger); | |
| 920 | +} | |
| 921 | + | |
| 922 | +/* One tappable row per option — the whole row is the label. */ | |
| 923 | +.choice-pick { | |
| 924 | + gap: 0.5rem; | |
| 925 | +} | |
| 926 | +.choice-row { | |
| 927 | + flex-direction: row; | |
| 928 | + align-items: center; | |
| 929 | + gap: 0.7rem; | |
| 930 | + padding: 0.7rem 0.9rem; | |
| 931 | + font-size: 1rem; | |
| 932 | + font-weight: 500; | |
| 933 | + color: var(--text); | |
| 934 | + background: var(--surface-2); | |
| 935 | + border: 1px solid var(--border); | |
| 936 | + border-radius: var(--radius-sm); | |
| 937 | + cursor: pointer; | |
| 938 | + transition: border-color 120ms, background 120ms; | |
| 939 | +} | |
| 940 | +.choice-row:hover { | |
| 941 | + border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); | |
| 942 | +} | |
| 943 | +.choice-row.picked { | |
| 944 | + border-color: var(--accent); | |
| 945 | + background: color-mix(in srgb, var(--accent) 10%, var(--surface-2)); | |
| 946 | +} | |
| 947 | +.choice-row input { | |
| 948 | + width: 1.15rem; | |
| 949 | + height: 1.15rem; | |
| 950 | + accent-color: var(--accent); | |
| 951 | + flex-shrink: 0; | |
| 952 | +} | |
| 953 | + | |
| 954 | +.save-state { | |
| 955 | + font-size: 0.8rem; | |
| 956 | + color: var(--ok); | |
| 957 | +} | |
| 958 | +.save-state.error { | |
| 959 | + color: var(--danger); | |
| 960 | + font-weight: 600; | |
| 961 | +} | |
| 962 | + | |
| 963 | +.notice-ok { | |
| 964 | + border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); | |
| 965 | + color: var(--ok); | |
| 966 | + font-weight: 500; | |
| 967 | +} | |
| 968 | +.notice-warn { | |
| 969 | + border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); | |
| 970 | + color: var(--warn); | |
| 971 | + font-weight: 500; | |
| 972 | +} | |
| 973 | + | |
| 974 | +/* Question authoring: one row per option, radio marks the right one. */ | |
| 975 | +.option-row { | |
| 976 | + display: flex; | |
| 977 | + align-items: center; | |
| 978 | + gap: 0.6rem; | |
| 979 | +} | |
| 980 | +.option-row input[type="radio"] { | |
| 981 | + width: 1.15rem; | |
| 982 | + height: 1.15rem; | |
| 983 | + accent-color: var(--ok); | |
| 984 | + flex-shrink: 0; | |
| 985 | +} | |
| 986 | +.option-row input:not([type="radio"]) { | |
| 987 | + flex: 1; | |
| 988 | + min-width: 0; | |
| 989 | +} | |
| 990 | + | |
| 991 | +ol.choices { | |
| 992 | + margin: 0; | |
| 993 | + padding-left: 1.4rem; | |
| 994 | + display: flex; | |
| 995 | + flex-direction: column; | |
| 996 | + gap: 0.25rem; | |
| 997 | +} | |
| 998 | +ol.choices li.correct { | |
| 999 | + color: var(--ok); | |
| 1000 | + font-weight: 600; | |
| 1001 | +} | |
| 1002 | + | |
| 1003 | +.live-counts { | |
| 1004 | + display: flex; | |
| 1005 | + gap: 0.5rem; | |
| 1006 | + flex-wrap: wrap; | |
| 1007 | +} | |
| 1008 | + | |
| 1009 | +.sheet-row { | |
| 1010 | + padding: 0.6rem 0; | |
| 1011 | + border-bottom: 1px solid var(--border); | |
| 1012 | +} | |
| 1013 | +.sheet-row:last-child { | |
| 1014 | + border-bottom: none; | |
| 1015 | +} | |
| 1016 | +.sheet-row .qtext .badge { | |
| 1017 | + margin-left: 0.5rem; | |
| 1018 | +} | |
| 1019 | +.answer-ok { | |
| 1020 | + color: var(--ok); | |
| 1021 | + font-weight: 500; | |
| 1022 | +} | |
| 1023 | +.answer-bad { | |
| 1024 | + color: var(--danger); | |
| 1025 | + font-weight: 500; | |
| 1026 | +} | |
| 1027 | + | |
| 1028 | +/* --- bottom tab bar (small screens) ------------------------------------------ */ | |
| 1029 | + | |
| 1030 | +.tabbar { | |
| 1031 | + display: none; | |
| 1032 | +} | |
| 1033 | + | |
| 1034 | +@media (max-width: 860px) { | |
| 1035 | + .sidebar nav { | |
| 1036 | + display: none; | |
| 1037 | + } | |
| 1038 | + .tabbar { | |
| 1039 | + position: fixed; | |
| 1040 | + inset: auto 0 0 0; | |
| 1041 | + z-index: 30; | |
| 1042 | + display: grid; | |
| 1043 | + grid-auto-flow: column; | |
| 1044 | + grid-auto-columns: 1fr; | |
| 1045 | + padding: 0.3rem 0.4rem calc(0.3rem + env(safe-area-inset-bottom)); | |
| 1046 | + background: color-mix(in srgb, var(--surface) 88%, transparent); | |
| 1047 | + backdrop-filter: blur(14px); | |
| 1048 | + border-top: 1px solid var(--border); | |
| 1049 | + } | |
| 1050 | + .tabbar a { | |
| 1051 | + display: flex; | |
| 1052 | + flex-direction: column; | |
| 1053 | + align-items: center; | |
| 1054 | + justify-content: center; | |
| 1055 | + gap: 0.15rem; | |
| 1056 | + min-height: 52px; | |
| 1057 | + border-radius: var(--radius-sm); | |
| 1058 | + color: var(--muted); | |
| 1059 | + font-size: 0.66rem; | |
| 1060 | + font-weight: 600; | |
| 1061 | + letter-spacing: 0.01em; | |
| 1062 | + } | |
| 1063 | + .tabbar a:hover { | |
| 1064 | + text-decoration: none; | |
| 1065 | + } | |
| 1066 | + .tabbar a.active { | |
| 1067 | + color: var(--accent); | |
| 1068 | + background: color-mix(in srgb, var(--accent) 11%, transparent); | |
| 1069 | + } | |
| 1070 | + .tabbar .icon { | |
| 1071 | + width: 1.35em; | |
| 1072 | + height: 1.35em; | |
| 1073 | + } | |
| 1074 | + main { | |
| 1075 | + padding-bottom: 6rem; | |
| 1076 | + } | |
| 1077 | + .room-head { | |
| 1078 | + top: 0; | |
| 1079 | + } | |
| 1080 | +} | |
| 1081 | + | |
| 712 | 1082 | /* --- auth page ----------------------------------------------------------------- */ |
| 713 | 1083 | |
| 714 | 1084 | .auth-page { |
vite.config.tsmodified+2 -0
| @@ -11,6 +11,8 @@ export default defineConfig({ | ||
| 11 | 11 | "/api": { |
| 12 | 12 | target: "http://127.0.0.1:8080", |
| 13 | 13 | changeOrigin: true, |
| 14 | + // The exam room is a WebSocket under the same prefix. | |
| 15 | + ws: true, | |
| 14 | 16 | rewrite: (path) => path.replace(/^\/api/, ""), |
| 15 | 17 | }, |
| 16 | 18 | }, |