forge
Explore
Log in

Don't you dare go Hollow

🐛 refresh exam detail when route id changes

Browse files at this commit

7122c92c94a9ef21e56f247e08dd73615e72099fBurak BoduroğluParent: d9ee743
  • fix
    • 🐛 refresh exam detail when route id changes
Show full message
fix: 🐛 refresh exam detail when route id changes
- derive exam detail id from the reactive pathname
- derive exam room id from the reactive pathname
- prevent stale exam data from rendering after navigating between exams
src/pages/exam-detail-page.tsxmodified+2 -6
@@ -1,4 +1,4 @@
1-import { Link, useLocation, useNavigate, useParams } from "@tanstack/solid-router";
1+import { Link, useLocation, useNavigate } from "@tanstack/solid-router";
22 import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js";
33 import { deleteExamById } from "@/api/deleteExamById";
44 import { deleteExamResultByUserId } from "@/api/deleteExamResultByUserId";
@@ -57,16 +57,12 @@ export default function ExamDetailPage() {
5757
5858 function ExamDetailContent() {
5959 const location = useLocation();
60- const params = useParams({ from: "/exams/$id" });
6160 const auth = useAuth();
6261 const navigate = useNavigate();
6362 const t = useT();
6463 const { locale } = usePreferences();
6564 const now = createNow();
66- const id = createMemo(() => {
67- location();
68- return params().id;
69- });
65+ const id = createMemo(() => decodeURIComponent(location().pathname.split("/").pop() ?? ""));
7066
7167 const [exam, { refetch: refetchExam }] = createResource(id, (examId) => getExamById(examId));
7268 const [settings] = createResource(() => getSettings());
src/pages/exam-room-page.tsxmodified+2 -6
@@ -1,4 +1,4 @@
1-import { Link, useLocation, useParams } from "@tanstack/solid-router";
1+import { Link, useLocation } from "@tanstack/solid-router";
22 import { Show, Suspense, createMemo, createResource } from "solid-js";
33 import { getExamById } from "@/api/getExamById";
44 import { getMyCourses } from "@/api/getMyCourses";
@@ -23,13 +23,9 @@ export default function ExamRoomPage() {
2323
2424 function ExamRoomContent() {
2525 const location = useLocation();
26- const params = useParams({ from: "/exam-room/$id" });
2726 const auth = useAuth();
2827 const t = useT();
29- const id = createMemo(() => {
30- location();
31- return params().id;
32- });
28+ const id = createMemo(() => decodeURIComponent(location().pathname.split("/").pop() ?? ""));
3329 const [exam] = createResource(id, (examId) => getExamById(examId));
3430 const [mine] = createResource(
3531 () => (auth.user()?.role === "student" ? true : null),