From fcfa59d46a5d722ba7c05d1390b10e66174afd9e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?=
<80620802+burakboduroglu@users.noreply.github.com>
Date: Mon, 20 Jul 2026 09:22:42 +0300
Subject: [PATCH] =?UTF-8?q?fix:=20=E2=99=BB=EF=B8=8F=20exam=20answer=20she?=
=?UTF-8?q?et=20in=20SidePanel,=20course=20names,=20correct/wrong=20icons?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- remove standalone exam-answer-sheet page and route
- answer sheet opens in SidePanel (not inline top-of-page) with collapsible
mark update card
- handle 404 from getStudentAnswers → show "Başlamadı" badge instead of
error, list all questions with null answers
- correct answer: green IconCheck badge, wrong: red IconX badge, same
22×22px layout replacing "Doğru Seç" / "✗" text
- exams-page: wait for courses() before fetching list, lazy-fetch missing
course titles via getCourseById so course column always shows name
---
src/components/exams/answer-sheet-view.tsx | 56 ++++++--
src/components/layout/app-shell.tsx | 2 +-
src/pages/exam-answer-sheet-page.tsx | 151 ---------------------
src/pages/exam-detail-page.tsx | 111 ++++++++++++++-
src/pages/exams-page.tsx | 23 +++-
src/routes/router.tsx | 8 --
6 files changed, 175 insertions(+), 176 deletions(-)
delete mode 100644 src/pages/exam-answer-sheet-page.tsx
diff --git a/src/components/exams/answer-sheet-view.tsx b/src/components/exams/answer-sheet-view.tsx
index a786a56..0af01df 100644
--- a/src/components/exams/answer-sheet-view.tsx
+++ b/src/components/exams/answer-sheet-view.tsx
@@ -1,8 +1,12 @@
import { For, Show, Suspense, createResource } from "solid-js";
+import { ApiError } from "@/api/client";
import { getExamQuestions } from "@/api/getExamQuestions";
import { getStudentAnswers } from "@/api/getStudentAnswers";
+import type { StudentAnswerSheet } from "@/api/types";
import { Badge } from "@/components/ui/badge";
+import { IconCheck, IconX } from "@/components/ui/icons";
import { PageSpinner } from "@/components/ui/page-spinner";
+import { cn } from "@/lib/cn";
import { joinAnswerSheet } from "@/lib/answer-sheet";
import { personLabelWithId } from "@/lib/person";
import { useT } from "@/stores/preferences-context";
@@ -12,7 +16,22 @@ export function AnswerSheetView(props: { examId: string; userId: string }) {
const [data] = createResource(
() => [props.examId, props.userId] as const,
async ([examId, userId]) => {
- const [questions, sheet] = await Promise.all([getExamQuestions(examId), getStudentAnswers(examId, userId)]);
+ const questions = await getExamQuestions(examId);
+ let sheet: StudentAnswerSheet;
+ try {
+ sheet = await getStudentAnswers(examId, userId);
+ } catch (err) {
+ if (err instanceof ApiError && err.status === 404) {
+ sheet = {
+ exam: examId,
+ user: { id: userId, username: userId, display_name: null },
+ answers: [],
+ auto_score: { earned: 0, possible: 0 },
+ };
+ } else {
+ throw err;
+ }
+ }
return { sheet, rows: joinAnswerSheet(questions.items, sheet.answers) };
},
);
@@ -24,9 +43,11 @@ export function AnswerSheetView(props: { examId: string; userId: string }) {
{personLabelWithId(d().sheet.user)}
-
- {t("exams.autoScore")}: {d().sheet.auto_score.earned}/{d().sheet.auto_score.possible}
-
+
0} fallback={{t("exams.notStarted")}}>
+
+ {t("exams.autoScore")}: {d().sheet.auto_score.earned}/{d().sheet.auto_score.possible}
+
+
@@ -35,11 +56,22 @@ export function AnswerSheetView(props: { examId: string; userId: string }) {
#{idx() + 1}
{row.question.points} {t("questions.points")}
-
- {row.answer?.is_correct === true ? t("exams.isCorrect") :
- row.answer?.is_correct === false ? "✗" :
- row.question.kind === "text" ? t("questions.kind.text") : "—"}
-
+
+
+ }>
+
+
+
+
+
+ {t("questions.kind.text")}
+
+
+ —
+
{row.question.text}
@@ -73,7 +105,11 @@ export function AnswerSheetView(props: { examId: string; userId: string }) {
✗
- {ci() === row.question.correct && {t("questions.correct")}}
+ {ci() === row.question.correct && (
+
+
+
+ )}
)}
diff --git a/src/components/layout/app-shell.tsx b/src/components/layout/app-shell.tsx
index b0db42b..998256d 100644
--- a/src/components/layout/app-shell.tsx
+++ b/src/components/layout/app-shell.tsx
@@ -25,7 +25,7 @@ export function AppShell(props: ParentProps) {
const [celebiOpen, setCelebiOpen] = createSignal(false);
const collapsed = () => prefs.sidebarCollapsed();
const location = useLocation();
- const wide = () => location().pathname.startsWith("/exam-room/") || location().pathname.startsWith("/exam-answers/") || location().pathname === "/messages";
+ const wide = () => location().pathname.startsWith("/exam-room/") || location().searchStr.includes("answerUser=") || location().pathname === "/messages";
const routeLabel = createMemo(() => {
const path = location().pathname;
if (path === "/") return t("nav.home");
diff --git a/src/pages/exam-answer-sheet-page.tsx b/src/pages/exam-answer-sheet-page.tsx
deleted file mode 100644
index 1cbac5b..0000000
--- a/src/pages/exam-answer-sheet-page.tsx
+++ /dev/null
@@ -1,151 +0,0 @@
-import { Link, useLocation } from "@tanstack/solid-router";
-import { Show, Suspense, createMemo, createResource, createSignal } from "solid-js";
-import { getExamById } from "@/api/getExamById";
-import { getExamResults } from "@/api/getExamResults";
-import { postExamResult } from "@/api/postExamResult";
-import { formatApiError } from "@/api/client";
-import { AnswerSheetView } from "@/components/exams/answer-sheet-view";
-import { PageHeader } from "@/components/layout/page-header";
-import { RouteGuard } from "@/components/layout/route-guard";
-import { Alert } from "@/components/ui/alert";
-import { Button } from "@/components/ui/button";
-import { IconChevronLeft } from "@/components/ui/icons";
-import { Input } from "@/components/ui/input";
-import { Label } from "@/components/ui/label";
-import { PageSpinner } from "@/components/ui/page-spinner";
-import { createFlash } from "@/lib/flash";
-import { personId } from "@/lib/person";
-import { hasMinRole } from "@/lib/roles";
-import { useAuth } from "@/stores/auth-context";
-import { useT } from "@/stores/preferences-context";
-
-export default function ExamAnswerSheetPage() {
- return (
-
-
-
- );
-}
-
-function ExamAnswerSheetContent() {
- const auth = useAuth();
- const location = useLocation();
- const t = useT();
- const [mark, setMark] = createSignal("0");
- const [error, setError] = createSignal("");
- const [pending, setPending] = createSignal(false);
- const [flash, setFlash] = createFlash();
- const params = createMemo((prev: { examId: string; userId: string }) => {
- const match = /^\/exam-answers\/([^/]+)\/([^/]+)$/.exec(location().pathname);
- return match ? { examId: decodeURIComponent(match[1]), userId: decodeURIComponent(match[2]) } : prev;
- }, { examId: "", userId: "" });
- const [exam] = createResource(() => params().examId, (examId) => getExamById(examId));
- const [result, { refetch: refetchResult }] = createResource(
- () => params(),
- async ({ examId, userId }) => {
- if (!examId || !userId) return null;
- const page = await getExamResults(examId, { limit: 500, offset: 0 });
- const row = page.items.find((item) => personId(item.user) === userId) ?? null;
- setMark(row ? String(row.mark) : "0");
- return row;
- },
- );
- const canView = () => {
- const e = exam();
- const u = auth.user();
- if (!e || !u) return false;
- return e.creator === u.id || hasMinRole(u.role, "manager");
- };
- const setClampedMark = (value: string) => {
- if (value === "") {
- setMark(value);
- return;
- }
- const next = Math.max(0, Math.min(100, Number(value)));
- setMark(Number.isNaN(next) ? "" : String(Math.trunc(next)));
- };
- const submitMark = async (event: SubmitEvent) => {
- event.preventDefault();
- const next = Number(mark());
- if (!Number.isInteger(next) || next < 0 || next > 100) {
- setError(t("form.markRange"));
- return;
- }
- setError("");
- setPending(true);
- try {
- await postExamResult(params().examId, { user_id: params().userId, mark: next });
- await refetchResult();
- setFlash(t("common.saved"));
- } catch (err) {
- setError(formatApiError(err));
- } finally {
- setPending(false);
- }
- };
-
- return (
- }>
- }>
- {formatApiError(exam.error)}
-
- }
- >
- {(ex) => (
- {t("common.accessDenied")}}>
-
-
-
-
- }
- />
-
-
-
-
- )}
-
-
- );
-}
diff --git a/src/pages/exam-detail-page.tsx b/src/pages/exam-detail-page.tsx
index c131035..14571a6 100644
--- a/src/pages/exam-detail-page.tsx
+++ b/src/pages/exam-detail-page.tsx
@@ -16,6 +16,7 @@ import { ApiError, formatApiError } from "@/api/client";
import type { ExamResult } from "@/api/types";
import { ExamForm } from "@/components/exams/exam-form";
import { ExamQuestionsPanel } from "@/components/exams/exam-questions-panel";
+import { AnswerSheetView } from "@/components/exams/answer-sheet-view";
import { ExamResultBadge } from "@/components/exams/exam-result-badge";
import { GradeForm } from "@/components/exams/grade-form";
import { RouteGuard } from "@/components/layout/route-guard";
@@ -25,7 +26,8 @@ import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { ConfirmDialog } from "@/components/ui/confirm-dialog";
import { DataTable } from "@/components/ui/data-table";
-import { IconChevronLeft, IconEdit, IconExam, IconEye, IconPlus, IconTrash } from "@/components/ui/icons";
+import { IconChevronDown, IconChevronLeft, IconEdit, IconExam, IconEye, IconPlus, IconTrash } from "@/components/ui/icons";
+import { Input } from "@/components/ui/input";
import { PaginationControls } from "@/components/ui/pagination-controls";
import { PageSpinner } from "@/components/ui/page-spinner";
import { SectionDisclosure } from "@/components/ui/section-disclosure";
@@ -84,6 +86,11 @@ function ExamDetailContent() {
const [removeUserId, setRemoveUserId] = createSignal(null);
const [gradeOpen, setGradeOpen] = createSignal(false);
const [resultPage, setResultPage] = createSignal(0);
+ const [answerSheetUserId, setAnswerSheetUserId] = createSignal(null);
+ const answerSheetOpen = () => answerSheetUserId() != null;
+ const [answerMark, setAnswerMark] = createSignal("0");
+ const [answerError, setAnswerError] = createSignal("");
+ const [answerPending, setAnswerPending] = createSignal(false);
const [questionCreateOpen, setQuestionCreateOpen] = createSignal(false);
const [openSections, setOpenSections] = createSignal({
schedule: false,
@@ -135,6 +142,17 @@ function ExamDetailContent() {
() => (hasCourseManagementRights() && gradeOpen() ? id() : null),
async (examId) => examId ? getExamResults(examId, { limit: 500, offset: 0 }) : null,
);
+ const [answerResult, { refetch: refetchAnswerResult }] = createResource(
+ () => (hasCourseManagementRights() && answerSheetOpen() ? [id(), answerSheetUserId()!] as const : null),
+ async (source) => {
+ if (!source) return null;
+ const [examId, userId] = source;
+ const page = await getExamResults(examId, { limit: 500, offset: 0 });
+ const row = page.items.find((item) => personId(item.user) === userId) ?? null;
+ setAnswerMark(row ? String(row.mark) : "0");
+ return row;
+ },
+ );
const [stats] = createResource(
() => (hasCourseManagementRights() && openSections().statistics ? id() : null),
async (examId) => {
@@ -205,6 +223,36 @@ function ExamDetailContent() {
const isDraft = () => exam()?.draft === true;
const resultTotal = () => results()?.total ?? 0;
const resultTotalPages = () => Math.max(1, Math.ceil(resultTotal() / RESULT_PAGE_SIZE));
+ const setClampedAnswerMark = (value: string) => {
+ if (value === "") {
+ setAnswerMark(value);
+ return;
+ }
+ const next = Math.max(0, Math.min(100, Number(value)));
+ setAnswerMark(Number.isNaN(next) ? "" : String(Math.trunc(next)));
+ };
+ const submitAnswerMark = async (event: SubmitEvent) => {
+ event.preventDefault();
+ const userId = answerSheetUserId();
+ if (!userId) return;
+ const mark = Number(answerMark());
+ if (!Number.isInteger(mark) || mark < 0 || mark > 100) {
+ setAnswerError(t("form.markRange"));
+ return;
+ }
+ setAnswerError("");
+ setAnswerPending(true);
+ try {
+ await postExamResult(id(), { user_id: userId, mark });
+ await refetchAnswerResult();
+ await refetchResults();
+ setFlash(t("common.saved"));
+ } catch (err) {
+ setAnswerError(formatApiError(err));
+ } finally {
+ setAnswerPending(false);
+ }
+ };
createEffect(() => {
if (resultPage() >= resultTotalPages()) setResultPage(resultTotalPages() - 1);
});
@@ -249,12 +297,12 @@ function ExamDetailContent() {
{
label: t("exams.answerSheet"),
icon: ,
- onSelect: () => void navigate({ to: "/exam-answers/$examId/$userId", params: { examId: id(), userId: personId(cell.row.original.user) } }),
+ onSelect: () => setAnswerSheetUserId(personId(cell.row.original.user)),
},
{
label: t("common.update"),
icon: ,
- onSelect: () => void navigate({ to: "/exam-answers/$examId/$userId", params: { examId: id(), userId: personId(cell.row.original.user) } }),
+ onSelect: () => setAnswerSheetUserId(personId(cell.row.original.user)),
},
...(!isFinished()
? [{
@@ -386,6 +434,63 @@ function ExamDetailContent() {
+ { if (!open) setAnswerSheetUserId(null); }}
+ title={t("exams.answerSheet")}
+ size="wide"
+ >
+
+ {(userId) => {
+ const [markOpen, setMarkOpen] = createSignal(false);
+ return (
+
+
+
+
+
+
+
+ );
+ }}
+
+
+
course.creator.id === auth.user()?.id || hasMinRole(auth.user()?.role, "manager")),
);
const canCreate = () => hasMinRole(auth.user()?.role, "teacher") && manageableCourses().length > 0;
- const courseById = createMemo(() => new Map(visibleCourses().map((course) => [course.id, course])));
- const courseTitle = (courseId: string) => courseById().get(courseId)?.title ?? courseId;
+ const [courseMap, setCourseMap] = createSignal>({});
+ const courseTitle = (courseId: string) => {
+ const cached = visibleCourses().find((c) => c.id === courseId);
+ if (cached) return cached.title;
+ return courseMap()[courseId] ?? courseId;
+ };
const examStatus = (exam: Exam) => examDisplayStatus(exam, now(), attemptStatuses()[exam.id]);
@@ -99,9 +104,21 @@ function ExamsContent() {
() => {
// Do not track now() here — it ticks every second and would re-fetch forever.
if (isStudent() && mine() === undefined) return null;
+ if (!isStudent() && courses() === undefined) return null;
return [isStudent() ? "s" : "t", (mine() ?? []).map((c) => c.id).join(",")].join("|");
},
- async () => (await getExams()).items,
+ async () => {
+ const items = (await getExams()).items;
+ const known = new Map(visibleCourses().map((c) => [c.id, c.title]));
+ const missing = [...new Set(items.map((e) => e.course))].filter((id) => !known.has(id));
+ if (missing.length > 0) {
+ await Promise.all(missing.map((id) =>
+ getCourseById(id).then((c) => known.set(id, c.title)).catch(() => {}),
+ ));
+ }
+ setCourseMap(Object.fromEntries(known));
+ return items;
+ },
);
createEffect(() => {
diff --git a/src/routes/router.tsx b/src/routes/router.tsx
index 570e3f6..5cca4dc 100644
--- a/src/routes/router.tsx
+++ b/src/routes/router.tsx
@@ -29,7 +29,6 @@ const EventsPage = lazyRoute(() => import("@/pages/events-page"));
const EventDetailPage = lazyRoute(() => import("@/pages/event-detail-page"));
const ExamsPage = lazyRoute(() => import("@/pages/exams-page"));
const ExamDetailPage = lazyRoute(() => import("@/pages/exam-detail-page"));
-const ExamAnswerSheetPage = lazyRoute(() => import("@/pages/exam-answer-sheet-page"));
const ExamRoomPage = lazyRoute(() => import("@/pages/exam-room-page"));
const CoursesPage = lazyRoute(() => import("@/pages/courses-page"));
const CourseDetailPage = lazyRoute(() => import("@/pages/course-detail-page"));
@@ -120,12 +119,6 @@ const examDetailRoute = createRoute({
component: ExamDetailPage,
});
-const examAnswerSheetRoute = createRoute({
- getParentRoute: () => rootRoute,
- path: "/exam-answers/$examId/$userId",
- component: ExamAnswerSheetPage,
-});
-
const examRoomRoute = createRoute({
getParentRoute: () => rootRoute,
path: "/exam-room/$id",
@@ -247,7 +240,6 @@ const routeTree = rootRoute.addChildren([
notesRoute,
eventsRoute,
eventDetailRoute,
- examAnswerSheetRoute,
examDetailRoute,
examRoomRoute,
liveMonitorRoute,