From 7024736eb0c0a0ef58377ff1f2aebd121d301944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 12 Jul 2026 06:57:35 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20live=20exams,=20Turkish=20i?= =?UTF-8?q?18n,=20and=20mobile=20tab=20bar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - mirror the backend exam contract: schedule fields, attempts, questions/answers, live monitor, /time clock sync, ws proxy - exam scheduling UI in plain words with client-side window validation - teacher question authoring: choice/written, points, correct pick - student exam room: server-judged countdown, WebSocket autosave with REST fallback, two-step turn-in, review after submit or expiry - teacher live monitor over SSE with answer sheets, auto-score suggestion, and inline grading - full English/Turkish dictionaries, persisted toggle, localized dates, document lang so Turkish casing renders İ correctly - weight badges speak plain words ("counts ×2" / "×2 sayılır") - bottom tab bar within thumb reach on small screens --- src/app.tsx | 2 + src/components/ConfirmButton.tsx | 49 +++ src/components/ExamMonitor.tsx | 219 +++++++++++ src/components/ExamQuestions.tsx | 274 ++++++++++++++ src/components/Feedback.tsx | 9 +- src/components/Icons.tsx | 16 + src/components/Layout.tsx | 61 ++- src/components/ProfileFields.tsx | 13 +- src/components/ScheduleFields.tsx | 105 ++++++ src/components/UserPicker.tsx | 101 +++++ src/lib/action.ts | 5 +- src/lib/api.ts | 93 ++++- src/lib/clock.ts | 42 +++ src/lib/format.ts | 36 +- src/lib/i18n.ts | 606 ++++++++++++++++++++++++++++++ src/lib/types.ts | 155 +++++++- src/pages/CourseDetail.tsx | 157 +++++--- src/pages/Courses.tsx | 56 ++- src/pages/EventDetail.tsx | 111 +++--- src/pages/Events.tsx | 58 +-- src/pages/ExamDetail.tsx | 302 ++++++++++++--- src/pages/ExamRoom.tsx | 370 ++++++++++++++++++ src/pages/Exams.tsx | 15 +- src/pages/Home.tsx | 35 +- src/pages/Login.tsx | 54 ++- src/pages/Marks.tsx | 50 +-- src/pages/NotFound.tsx | 5 +- src/pages/Notes.tsx | 103 ++--- src/pages/Profile.tsx | 13 +- src/pages/Users.tsx | 89 +++-- src/styles.css | 384 ++++++++++++++++++- vite.config.ts | 2 + 32 files changed, 3184 insertions(+), 406 deletions(-) create mode 100644 src/components/ConfirmButton.tsx create mode 100644 src/components/ExamMonitor.tsx create mode 100644 src/components/ExamQuestions.tsx create mode 100644 src/components/ScheduleFields.tsx create mode 100644 src/components/UserPicker.tsx create mode 100644 src/lib/clock.ts create mode 100644 src/lib/i18n.ts create mode 100644 src/pages/ExamRoom.tsx diff --git a/src/app.tsx b/src/app.tsx index ccacca2..0a07acd 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -16,6 +16,7 @@ const Courses = lazy(() => import("./pages/Courses")); const CourseDetail = lazy(() => import("./pages/CourseDetail")); const Exams = lazy(() => import("./pages/Exams")); const ExamDetail = lazy(() => import("./pages/ExamDetail")); +const ExamRoom = lazy(() => import("./pages/ExamRoom")); const Marks = lazy(() => import("./pages/Marks")); const Profile = lazy(() => import("./pages/Profile")); const Users = lazy(() => import("./pages/Users")); @@ -46,6 +47,7 @@ export function App() { + diff --git a/src/components/ConfirmButton.tsx b/src/components/ConfirmButton.tsx new file mode 100644 index 0000000..31556a7 --- /dev/null +++ b/src/components/ConfirmButton.tsx @@ -0,0 +1,49 @@ +// Two-step destructive button: the first press arms it ("Really delete?"), +// the second fires. It disarms by itself after a moment or when focus leaves, +// so a stray tap never destroys anything. + +import { Show, createSignal, onCleanup, type JSX } from "solid-js"; +import { t } from "../lib/i18n"; + +export function ConfirmButton(props: { + children: JSX.Element; + onConfirm: () => void; + /** Armed label; defaults to the localized "Really delete?". */ + confirmText?: string; + /** Resting classes; defaults to "ghost danger". */ + class?: string; + disabled?: boolean; +}) { + const [armed, setArmed] = createSignal(false); + let timer: ReturnType | undefined; + onCleanup(() => clearTimeout(timer)); + + const disarm = () => { + clearTimeout(timer); + setArmed(false); + }; + + const press = () => { + if (armed()) { + disarm(); + props.onConfirm(); + } else { + setArmed(true); + timer = setTimeout(disarm, 4000); + } + }; + + return ( + + ); +} diff --git a/src/components/ExamMonitor.tsx b/src/components/ExamMonitor.tsx new file mode 100644 index 0000000..ce2a072 --- /dev/null +++ b/src/components/ExamMonitor.tsx @@ -0,0 +1,219 @@ +// The teacher's live view of a scheduled exam: who's in, who's still writing, +// time each student has left, marks as they land. Fed by the backend's SSE +// stream (a fresh snapshot every couple of seconds); the browser's +// EventSource reconnects by itself. Each row opens the student's answer +// sheet with the machine's auto-score suggestion and an inline grade box. + +import { For, Show, createResource, createSignal, onCleanup } from "solid-js"; +import { createAction } from "../lib/action"; +import { exams } from "../lib/api"; +import { formatCountdown, personLabel } from "../lib/format"; +import { t } from "../lib/i18n"; +import type { Exam, ExamLive, LiveStudent, PersonRef } from "../lib/types"; +import { LIMITS } from "../lib/types"; +import { Empty, ErrorLine, Loading } from "./Feedback"; + +export function ExamMonitor(props: { exam: Exam }) { + const [snapshot, setSnapshot] = createSignal(null); + const [reviewing, setReviewing] = createSignal(null); + + const source = new EventSource(exams.liveStreamUrl(props.exam.id), { + withCredentials: true, + }); + source.addEventListener("snapshot", (event) => { + setSnapshot(JSON.parse((event as MessageEvent).data) as ExamLive); + }); + onCleanup(() => source.close()); + + const seconds = (student: LiveStudent) => + student.remaining_ms === null ? "—" : formatCountdown(student.remaining_ms); + + const activity = (student: LiveStudent, now: number) => { + if (student.last_activity === null) return "—"; + const secondsAgo = Math.max(0, Math.round((now - student.last_activity) / 1000)); + return secondsAgo < 120 + ? t("agoSeconds")(secondsAgo) + : t("agoMinutes")(Math.round(secondsAgo / 60)); + }; + + return ( +
+

{t("liveMonitor")}

+ }> + {(live) => ( + <> +
+ {t("countEnrolled")(live().counts.enrolled)} + {t("countWriting")(live().counts.in_progress)} + {t("countTurnedIn")(live().counts.submitted)} + {t("countNotStarted")(live().counts.not_started)} + 0}> + {t("countTimeUp")(live().counts.expired)} + + {t("countGraded")(live().counts.graded)} +
+ + {t("nobodyEnrolledCourse")}} + > +
+ + + + + + + + + + + + + + {(student) => ( + + + + + + + + + + )} + + +
{t("student")}{t("status")}{t("answeredCol")}{t("timeLeftCol")}{t("lastSaveCol")}{t("markCol")} +
{personLabel(student.user)} + + {t("liveStatusWord")(student.status)} + + + {student.answered} / {live().question_count} + {seconds(student)}{activity(student, live().now)}{student.mark ?? "—"} + + + +
+
+
+ + + {(student) => } + + + )} +
+
+ ); +} + +/** One student's judged answers plus the auto-score suggestion and a grade box. */ +function AnswerSheet(props: { examId: string; student: PersonRef }) { + const [sheet] = createResource( + () => [props.examId, props.student.id] as const, + ([examId, userId]) => exams.attemptAnswers(examId, userId), + ); + // The authored questions (with text/choices/correct) to render rows against. + const [questions] = createResource(() => props.examId, exams.questions); + + const grade = createAction(async (form: HTMLFormElement) => { + const data = new FormData(form); + await exams.grade(props.examId, props.student.id, Number(data.get("mark"))); + }); + + const suggestion = () => { + const auto = sheet()?.auto_score; + return auto && auto.possible > 0 + ? Math.round((auto.earned / auto.possible) * 100) + : undefined; + }; + + return ( +
+

{t("sheetTitle")(personLabel(props.student))}

+ }> + {t("noQuestionsSheet")}} + > +
+ + {(question, index) => { + const answer = () => + sheet()!.answers.find((a) => a.question === question.id); + return ( +
+

+ Q{index() + 1}. {question.text} + {t("pts")(question.points)} +

+ {t("noAnswer")}

}> + {(current) => ( +

+ {current().text || "—"}} + > + {question.choices?.[current().selected ?? -1] ?? "—"} + ✓ + + {t("rightAnswerIs")(question.choices?.[question.correct ?? -1] ?? "—")} + + +

+ )} +
+
+ ); + }} +
+
+ +

+ {t("autoScoreLine")(sheet()!.auto_score.earned, sheet()!.auto_score.possible)} +

+
+ +
{ + e.preventDefault(); + void grade.run(e.currentTarget); + }} + > + + +
+ +
+
+ ); +} diff --git a/src/components/ExamQuestions.tsx b/src/components/ExamQuestions.tsx new file mode 100644 index 0000000..16a0375 --- /dev/null +++ b/src/components/ExamQuestions.tsx @@ -0,0 +1,274 @@ +// Question authoring for whoever manages the exam's course. Choice questions +// carry 2–10 options with the right one picked by radio; text questions are +// free-form and graded by a human. The backend freezes the list the moment +// anyone starts an attempt — that lands here as an error line, not a crash. + +import { For, Show, createResource, createSignal } from "solid-js"; +import { createAction } from "../lib/action"; +import { exams } from "../lib/api"; +import { t } from "../lib/i18n"; +import { LIMITS, type ExamQuestion, type QuestionKind } from "../lib/types"; +import { ConfirmButton } from "./ConfirmButton"; +import { Empty, ErrorLine, Loading } from "./Feedback"; +import { IconPlus } from "./Icons"; + +interface QuestionDraft { + text: string; + kind: string; + points: number; + choices: string[] | null; + correct: number | null; +} + +export function ExamQuestions(props: { examId: string }) { + const [list, { mutate }] = createResource(() => props.examId, exams.questions); + const [adding, setAdding] = createSignal(false); + const [editing, setEditing] = createSignal(null); + + const create = createAction(async (draft: QuestionDraft) => { + const created = await exams.createQuestion(props.examId, draft); + mutate((current) => [...(current ?? []), created]); + setAdding(false); + }); + + const save = createAction(async (qid: string, draft: QuestionDraft) => { + const updated = await exams.updateQuestion(props.examId, qid, draft); + mutate((current) => current?.map((q) => (q.id === qid ? updated : q))); + setEditing(null); + }); + + const remove = createAction(async (qid: string) => { + await exams.removeQuestion(props.examId, qid); + mutate((current) => current?.filter((q) => q.id !== qid)); + }); + + const totalPoints = () => (list() ?? []).reduce((sum, q) => sum + q.points, 0); + + return ( +
+
+

{t("questionsTitle")}

+ + {t("totalPoints")(totalPoints())} + + +
+ + + setAdding(false)} + onSubmit={(draft) => void create.run(draft)} + /> + + + + + + }> + setAdding(true)}> + {t("addQuestion")} + + } + > + {t("noQuestionsYet")} + + } + > +
+ + {(question, index) => ( +
+ setEditing(null)} + onSubmit={(draft) => void save.run(question.id, draft)} + /> + } + > +
+ Q{index() + 1} + {t("pts")(question.points)} + {t("questionKindWord")(question.kind)} + + + void remove.run(question.id)} + > + {t("deleteNote")} + + +
+

{question.text}

+ +
    + + {(choice, choiceIndex) => ( +
  1. + {choice} + ✓ +
  2. + )} +
    +
+
+
+
+ )} +
+
+
+
+
+ ); +} + +/** Create/edit form; choice options are dynamic rows with a "right answer" radio. */ +function QuestionForm(props: { + initial?: ExamQuestion; + pending: boolean; + onSubmit: (draft: QuestionDraft) => void; + onCancel: () => void; +}) { + const [kind, setKind] = createSignal(props.initial?.kind ?? "choice"); + const [options, setOptions] = createSignal( + props.initial?.choices ?? ["", ""], + ); + const [correct, setCorrect] = createSignal(props.initial?.correct ?? 0); + + const removeOption = (index: number) => { + setOptions((current) => current.filter((_, i) => i !== index)); + if (correct() === index) setCorrect(0); + else if (correct() > index) setCorrect(correct() - 1); + }; + + const submit = (form: HTMLFormElement) => { + const data = new FormData(form); + props.onSubmit({ + text: String(data.get("text")), + kind: kind(), + points: Number(data.get("points")), + choices: kind() === "choice" ? options() : null, + correct: kind() === "choice" ? correct() : null, + }); + }; + + return ( +
{ + e.preventDefault(); + submit(e.currentTarget); + }} + > + +
+ + +
+ + +
+ {t("tickRightAnswer")} + + {(option, index) => ( +
+ setCorrect(index())} + aria-label={t("optionIsRight")(index() + 1)} + /> + { + const value = e.currentTarget.value; + setOptions((current) => + current.map((v, i) => (i === index() ? value : v)), + ); + }} + /> + +
+ )} +
+ + + +
+
+ + + + + +
+ ); +} diff --git a/src/components/Feedback.tsx b/src/components/Feedback.tsx index b92268b..b7bfcba 100644 --- a/src/components/Feedback.tsx +++ b/src/components/Feedback.tsx @@ -20,6 +20,11 @@ export function Loading() { ); } -export function Empty(props: { children: JSX.Element }) { - return

{props.children}

; +export function Empty(props: { children: JSX.Element; action?: JSX.Element }) { + return ( +
+

{props.children}

+ {props.action} +
+ ); } diff --git a/src/components/Icons.tsx b/src/components/Icons.tsx index e80b807..2486848 100644 --- a/src/components/Icons.tsx +++ b/src/components/Icons.tsx @@ -114,3 +114,19 @@ export const IconArrow = () => ( ); + +export const IconEye = () => ( + + + + +); + +export const IconEyeOff = () => ( + + + + + + +); diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index fa323a4..b457e1e 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -1,9 +1,11 @@ // App shell: sidebar with navigation, user chip, and logout. Collapses into a -// top bar on narrow screens (pure CSS). Rendered only for authenticated routes. +// top bar on narrow screens (pure CSS), where the nav moves into a fixed +// bottom tab bar within thumb reach. Rendered only for authenticated routes. import { A, useNavigate } from "@solidjs/router"; import { Show, type ParentProps } from "solid-js"; import { useAuth } from "../lib/auth"; +import { lang, setLang, t } from "../lib/i18n"; import { IconBook, IconCalendar, @@ -36,49 +38,84 @@ export function Layout(props: ParentProps) {
{props.children}
+ + {/* Thumb-reach duplicate of the nav on small screens (CSS-hidden on + desktop); the sidebar collapses into a top bar with just the brand, + profile chip, and logout. */} + ); } diff --git a/src/components/ProfileFields.tsx b/src/components/ProfileFields.tsx index a81681f..3b61b39 100644 --- a/src/components/ProfileFields.tsx +++ b/src/components/ProfileFields.tsx @@ -5,6 +5,7 @@ import type { ProfilePatch } from "../lib/api"; import { today } from "../lib/format"; +import { t } from "../lib/i18n"; import { LIMITS, type User } from "../lib/types"; /** Matches the backend rule: optional leading +, separators, 7–15 digits. */ @@ -26,16 +27,16 @@ export function ProfileFields(props: { user: User }) { <>