forked from ravi2krishna/lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.tsx
71 lines (69 loc) · 1.94 KB
/
routes.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { MakeGenerics, Navigate, Route } from "@tanstack/react-location";
import { getAllCourses } from "./hooks/useGetAllCourses";
import { getCourse } from "./hooks/useGetCourse";
import { getCourses } from "./hooks/useGetCourses";
import { queryClient } from "./lib/react-query";
import Admin from "./pages/admin";
import CreateCourse from "./pages/create-course";
import Dashboard from "./pages/dashboard";
import ManageCourse from "./pages/ManageCourse";
import ManageCourses from "./pages/ManageCourses";
export type LocationGenerics = MakeGenerics<{
LoaderData: {
// ordersForStudent: ICourse[];
// courseProgress: ICourseProgress;
};
Params: {
courseId: string;
};
}>;
export const routes: Route<LocationGenerics>[] = [
{
path: "/",
element: <Dashboard />,
loader: async () => {
return (
queryClient.getQueryData(["getCourses"]) ??
(await queryClient.fetchQuery(["getCourses"], () => getCourses()))
);
},
},
{
path: "admin",
element: <Admin />,
children: [
{
path: "/",
element: <Navigate to={"courses"} />,
},
{
path: "courses",
element: <ManageCourses />,
loader: async () => {
return (
queryClient.getQueryData(["getAllCourses"]) ??
(await queryClient.fetchQuery(["getAllCourses"], () =>
getAllCourses()
))
);
},
children: [
{ path: "add", element: <CreateCourse /> },
{
path: ":courseId",
element: <ManageCourse />,
loader: async ({ params }) => {
return (
queryClient.getQueryData(["getCourse", params.courseId]) ??
(await queryClient.fetchQuery(
["getCourse", params.courseId],
() => getCourse(params.courseId)
))
);
},
},
],
},
],
},
];