🔄 Force resource refetch on same-route param navigation
Browse files at this commitdf3fa001a985695c6f5f500beb8933b10da89d23Parent: 163d4c5- fix
- 🔄 Force resource refetch on same-route param navigation
5 changed files +34 -14
- src/pages/course-detail-page.tsx +6 -2
- src/pages/event-detail-page.tsx +8 -4
- src/pages/exam-detail-page.tsx +6 -2
- src/pages/exam-room-page.tsx +7 -3
- src/pages/live-monitor-page.tsx +7 -3
src/pages/course-detail-page.tsxmodified+6 -2
| @@ -1,5 +1,5 @@ | |||
| 1 | import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; | 1 | import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; |
| 2 | -import { Link, useNavigate, useParams } from "@tanstack/solid-router"; | 2 | +import { Link, useLocation, useNavigate, useParams } from "@tanstack/solid-router"; |
| 3 | import { deleteCourseById } from "@/api/deleteCourseById"; | 3 | import { deleteCourseById } from "@/api/deleteCourseById"; |
| 4 | import { deleteCourseEnrollmentByUserId } from "@/api/deleteCourseEnrollmentByUserId"; | 4 | import { deleteCourseEnrollmentByUserId } from "@/api/deleteCourseEnrollmentByUserId"; |
| 5 | import { getCourseById } from "@/api/getCourseById"; | 5 | import { getCourseById } from "@/api/getCourseById"; |
| @@ -53,11 +53,15 @@ export default function CourseDetailPage() { | |||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | function CourseDetailContent() { | 55 | function CourseDetailContent() { |
| 56 | + const location = useLocation(); | ||
| 56 | const params = useParams({ from: "/courses/$id" }); | 57 | const params = useParams({ from: "/courses/$id" }); |
| 57 | const auth = useAuth(); | 58 | const auth = useAuth(); |
| 58 | const navigate = useNavigate(); | 59 | const navigate = useNavigate(); |
| 59 | const t = useT(); | 60 | const t = useT(); |
| 60 | - const id = () => params().id; | 61 | + const id = createMemo(() => { |
| 62 | + location(); | ||
| 63 | + return params().id; | ||
| 64 | + }); | ||
| 61 | 65 | ||
| 62 | const [course, { refetch: refetchCourse }] = createResource(id, (courseId) => getCourseById(courseId)); | 66 | const [course, { refetch: refetchCourse }] = createResource(id, (courseId) => getCourseById(courseId)); |
| 63 | const [terms] = createResource(() => getTerms()); | 67 | const [terms] = createResource(() => getTerms()); |
src/pages/event-detail-page.tsxmodified+8 -4
| @@ -1,5 +1,5 @@ | |||
| 1 | -import { Link, useNavigate, useParams } from "@tanstack/solid-router"; | 1 | +import { Link, useLocation, useNavigate, useParams } from "@tanstack/solid-router"; |
| 2 | -import { Show, Suspense, createResource, createSignal } from "solid-js"; | 2 | +import { Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; |
| 3 | import { deleteEventAttendanceByUserId } from "@/api/deleteEventAttendanceByUserId"; | 3 | import { deleteEventAttendanceByUserId } from "@/api/deleteEventAttendanceByUserId"; |
| 4 | import { deleteEventById } from "@/api/deleteEventById"; | 4 | import { deleteEventById } from "@/api/deleteEventById"; |
| 5 | import { getEventAttendance } from "@/api/getEventAttendance"; | 5 | import { getEventAttendance } from "@/api/getEventAttendance"; |
| @@ -34,12 +34,16 @@ export default function EventDetailPage() { | |||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | function EventDetailContent() { | 36 | function EventDetailContent() { |
| 37 | + const location = useLocation(); | ||
| 37 | const params = useParams({ from: "/events/$id" }); | 38 | const params = useParams({ from: "/events/$id" }); |
| 38 | const auth = useAuth(); | 39 | const auth = useAuth(); |
| 39 | const navigate = useNavigate(); | 40 | const navigate = useNavigate(); |
| 40 | - const t = useT(); | ||
| 41 | const { locale } = usePreferences(); | 41 | const { locale } = usePreferences(); |
| 42 | - const id = () => params().id; | 42 | + const t = useT(); |
| 43 | + const id = createMemo(() => { | ||
| 44 | + location(); | ||
| 45 | + return params().id; | ||
| 46 | + }); | ||
| 43 | 47 | ||
| 44 | const [event, { refetch: refetchEvent }] = createResource(id, (eventId) => getEventById(eventId)); | 48 | const [event, { refetch: refetchEvent }] = createResource(id, (eventId) => getEventById(eventId)); |
| 45 | const [attendance, { refetch: refetchAttendance }] = createResource(id, (eventId) => | 49 | const [attendance, { refetch: refetchAttendance }] = createResource(id, (eventId) => |
src/pages/exam-detail-page.tsxmodified+6 -2
| @@ -1,4 +1,4 @@ | |||
| 1 | -import { Link, useNavigate, useParams } from "@tanstack/solid-router"; | 1 | +import { Link, useLocation, useNavigate, useParams } from "@tanstack/solid-router"; |
| 2 | import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; | 2 | import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; |
| 3 | import { deleteExamById } from "@/api/deleteExamById"; | 3 | import { deleteExamById } from "@/api/deleteExamById"; |
| 4 | import { deleteExamResultByUserId } from "@/api/deleteExamResultByUserId"; | 4 | import { deleteExamResultByUserId } from "@/api/deleteExamResultByUserId"; |
| @@ -54,13 +54,17 @@ export default function ExamDetailPage() { | |||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | function ExamDetailContent() { | 56 | function ExamDetailContent() { |
| 57 | + const location = useLocation(); | ||
| 57 | const params = useParams({ from: "/exams/$id" }); | 58 | const params = useParams({ from: "/exams/$id" }); |
| 58 | const auth = useAuth(); | 59 | const auth = useAuth(); |
| 59 | const navigate = useNavigate(); | 60 | const navigate = useNavigate(); |
| 60 | const t = useT(); | 61 | const t = useT(); |
| 61 | const { locale } = usePreferences(); | 62 | const { locale } = usePreferences(); |
| 62 | const now = createNow(); | 63 | const now = createNow(); |
| 63 | - const id = () => params().id; | 64 | + const id = createMemo(() => { |
| 65 | + location(); | ||
| 66 | + return params().id; | ||
| 67 | + }); | ||
| 64 | 68 | ||
| 65 | const [exam, { refetch: refetchExam }] = createResource(id, (examId) => getExamById(examId)); | 69 | const [exam, { refetch: refetchExam }] = createResource(id, (examId) => getExamById(examId)); |
| 66 | const isTeacherPlus = createMemo(() => hasMinRole(auth.user()?.role, "teacher")); | 70 | const isTeacherPlus = createMemo(() => hasMinRole(auth.user()?.role, "teacher")); |
src/pages/exam-room-page.tsxmodified+7 -3
| @@ -1,5 +1,5 @@ | |||
| 1 | -import { Link, useParams } from "@tanstack/solid-router"; | 1 | +import { Link, useLocation, useParams } from "@tanstack/solid-router"; |
| 2 | -import { Show, Suspense, createResource } from "solid-js"; | 2 | +import { Show, Suspense, createMemo, createResource } from "solid-js"; |
| 3 | import { getExamById } from "@/api/getExamById"; | 3 | import { getExamById } from "@/api/getExamById"; |
| 4 | import { getMyCourses } from "@/api/getMyCourses"; | 4 | import { getMyCourses } from "@/api/getMyCourses"; |
| 5 | import { formatApiError } from "@/api/client"; | 5 | import { formatApiError } from "@/api/client"; |
| @@ -22,10 +22,14 @@ export default function ExamRoomPage() { | |||
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | function ExamRoomContent() { | 24 | function ExamRoomContent() { |
| 25 | + const location = useLocation(); | ||
| 25 | const params = useParams({ from: "/exam-room/$id" }); | 26 | const params = useParams({ from: "/exam-room/$id" }); |
| 26 | const auth = useAuth(); | 27 | const auth = useAuth(); |
| 27 | const t = useT(); | 28 | const t = useT(); |
| 28 | - const id = () => params().id; | 29 | + const id = createMemo(() => { |
| 30 | + location(); | ||
| 31 | + return params().id; | ||
| 32 | + }); | ||
| 29 | const [exam] = createResource(id, (examId) => getExamById(examId)); | 33 | const [exam] = createResource(id, (examId) => getExamById(examId)); |
| 30 | const [mine] = createResource( | 34 | const [mine] = createResource( |
| 31 | () => (auth.user()?.role === "student" ? true : null), | 35 | () => (auth.user()?.role === "student" ? true : null), |
src/pages/live-monitor-page.tsxmodified+7 -3
| @@ -1,5 +1,5 @@ | |||
| 1 | -import { For, Show, Suspense, createEffect, createResource, createSignal, onCleanup, untrack } from "solid-js"; | 1 | +import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal, onCleanup, untrack } from "solid-js"; |
| 2 | -import { Link, useParams } from "@tanstack/solid-router"; | 2 | +import { Link, useLocation, useParams } from "@tanstack/solid-router"; |
| 3 | import { getExamLive } from "@/api/getExamLive"; | 3 | import { getExamLive } from "@/api/getExamLive"; |
| 4 | import { getExamLiveStreamUrl } from "@/api/getExamLiveStreamUrl"; | 4 | import { getExamLiveStreamUrl } from "@/api/getExamLiveStreamUrl"; |
| 5 | import { getExamById } from "@/api/getExamById"; | 5 | import { getExamById } from "@/api/getExamById"; |
| @@ -95,11 +95,15 @@ function attemptLabel(entry: LiveRosterEntry): string { | |||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | function LiveMonitorContent() { | 97 | function LiveMonitorContent() { |
| 98 | + const location = useLocation(); | ||
| 98 | const params = useParams({ from: "/exams/$id/live" }); | 99 | const params = useParams({ from: "/exams/$id/live" }); |
| 99 | const t = useT(); | 100 | const t = useT(); |
| 100 | const { locale } = usePreferences(); | 101 | const { locale } = usePreferences(); |
| 101 | const now = createNow(); | 102 | const now = createNow(); |
| 102 | - const id = () => params().id; | 103 | + const id = createMemo(() => { |
| 104 | + location(); | ||
| 105 | + return params().id; | ||
| 106 | + }); | ||
| 103 | 107 | ||
| 104 | const [exam] = createResource(id, (eid) => getExamById(eid)); | 108 | const [exam] = createResource(id, (eid) => getExamById(eid)); |
| 105 | const [snapshot, setSnapshot] = createSignal<LiveMonitor | null>(null); | 109 | const [snapshot, setSnapshot] = createSignal<LiveMonitor | null>(null); |