mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
starting to gut
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
import { createContext } from "@/services/trpc/context";
|
import { createTrpcContext } from "@/services/trpc/context";
|
||||||
import { appRouter } from "@/services/trpc/router/app";
|
import { trpcAppRouter } from "@/services/trpc/router/app";
|
||||||
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
||||||
|
|
||||||
const handler = (request: Request) => {
|
const handler = (request: Request) => {
|
||||||
return fetchRequestHandler({
|
return fetchRequestHandler({
|
||||||
endpoint: "/api/trpc",
|
endpoint: "/api/trpc",
|
||||||
req: request,
|
req: request,
|
||||||
router: appRouter,
|
router: trpcAppRouter,
|
||||||
createContext: createContext,
|
createContext: createTrpcContext,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ import { Suspense } from "react";
|
|||||||
import { getQueryClient } from "@/app/providersQueryClientUtils";
|
import { getQueryClient } from "@/app/providersQueryClientUtils";
|
||||||
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
|
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
|
||||||
import { hydrateCanvasCourse } from "@/hooks/hookHydration";
|
import { hydrateCanvasCourse } from "@/hooks/hookHydration";
|
||||||
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
|
import { trpcAppRouter } from "@/services/trpc/router/app";
|
||||||
|
import { createTrpcContext } from "@/services/trpc/context";
|
||||||
|
import superjson from "superjson";
|
||||||
|
|
||||||
export default async function CourseLayout({
|
export default async function CourseLayout({
|
||||||
children,
|
children,
|
||||||
@@ -23,12 +27,49 @@ export default async function CourseLayout({
|
|||||||
const queryClient = getQueryClient();
|
const queryClient = getQueryClient();
|
||||||
await hydrateCanvasCourse(settings.canvasId, queryClient);
|
await hydrateCanvasCourse(settings.canvasId, queryClient);
|
||||||
const dehydratedState = dehydrate(queryClient);
|
const dehydratedState = dehydrate(queryClient);
|
||||||
|
const trpcHelper = createServerSideHelpers({
|
||||||
|
router: trpcAppRouter,
|
||||||
|
ctx: createTrpcContext(),
|
||||||
|
transformer: superjson,
|
||||||
|
});
|
||||||
|
|
||||||
|
const allSettings = await fileStorageService.settings.getAllCoursesSettings();
|
||||||
|
await Promise.all(
|
||||||
|
allSettings.map(async (settings) => {
|
||||||
|
const courseName = settings.name;
|
||||||
|
const moduleNames = await fileStorageService.modules.getModuleNames(
|
||||||
|
courseName
|
||||||
|
);
|
||||||
|
await Promise.all(
|
||||||
|
moduleNames.map(async (moduleName) => {
|
||||||
|
await trpcHelper.assignment.getAllAssignments.prefetch({
|
||||||
|
courseName,
|
||||||
|
moduleName,
|
||||||
|
});
|
||||||
|
|
||||||
|
// await Promise.all(
|
||||||
|
// assignments.map(
|
||||||
|
// async (a) =>
|
||||||
|
// await trpcHelper.assignment.getAssignment.fetch({
|
||||||
|
// courseName,
|
||||||
|
// moduleName,
|
||||||
|
// assignmentName: a.name,
|
||||||
|
// })
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
})
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const dehydratedTrpc = trpcHelper.dehydrate();
|
||||||
return (
|
return (
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<HydrationBoundary state={dehydratedState}>
|
<HydrationBoundary state={dehydratedState}>
|
||||||
<CourseContextProvider localCourseName={decodedCourseName}>
|
<HydrationBoundary state={dehydratedTrpc}>
|
||||||
{children}
|
<CourseContextProvider localCourseName={decodedCourseName}>
|
||||||
</CourseContextProvider>
|
{children}
|
||||||
|
</CourseContextProvider>
|
||||||
|
</HydrationBoundary>
|
||||||
</HydrationBoundary>
|
</HydrationBoundary>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,7 +7,13 @@ import { hydrateCourses } from "@/hooks/hookHydration";
|
|||||||
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
|
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
|
||||||
import { MyToaster } from "./MyToaster";
|
import { MyToaster } from "./MyToaster";
|
||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
export const dynamic = 'force-dynamic'
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
|
import { trpcAppRouter } from "@/services/trpc/router/app";
|
||||||
|
import { createTrpcContext } from "@/services/trpc/context";
|
||||||
|
import superjson from "superjson";
|
||||||
|
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||||
|
import ClientOnly from "@/components/ClientOnly";
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Canvas Manager 2.0",
|
title: "Canvas Manager 2.0",
|
||||||
@@ -21,21 +27,59 @@ export default async function RootLayout({
|
|||||||
const queryClient = getQueryClient();
|
const queryClient = getQueryClient();
|
||||||
await hydrateCourses(queryClient);
|
await hydrateCourses(queryClient);
|
||||||
const dehydratedState = dehydrate(queryClient);
|
const dehydratedState = dehydrate(queryClient);
|
||||||
cookies() // disables static page generation at build time
|
cookies(); // disables static page generation at build time
|
||||||
|
|
||||||
|
const trpcHelper = createServerSideHelpers({
|
||||||
|
router: trpcAppRouter,
|
||||||
|
ctx: createTrpcContext(),
|
||||||
|
transformer: superjson,
|
||||||
|
});
|
||||||
|
|
||||||
|
const allSettings = await fileStorageService.settings.getAllCoursesSettings();
|
||||||
|
await Promise.all(
|
||||||
|
allSettings.map(async (settings) => {
|
||||||
|
const courseName = settings.name;
|
||||||
|
const moduleNames = await fileStorageService.modules.getModuleNames(
|
||||||
|
courseName
|
||||||
|
);
|
||||||
|
await Promise.all(
|
||||||
|
moduleNames.map(async (moduleName) => {
|
||||||
|
await trpcHelper.assignment.getAllAssignments.prefetch({
|
||||||
|
courseName,
|
||||||
|
moduleName,
|
||||||
|
});
|
||||||
|
|
||||||
|
// await Promise.all(
|
||||||
|
// assignments.map(
|
||||||
|
// async (a) =>
|
||||||
|
// await trpcHelper.assignment.getAssignment.fetch({
|
||||||
|
// courseName,
|
||||||
|
// moduleName,
|
||||||
|
// assignmentName: a.name,
|
||||||
|
// })
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
})
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const dehydratedTrpc = trpcHelper.dehydrate();
|
||||||
return (
|
return (
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head></head>
|
<head></head>
|
||||||
<body className="flex justify-center">
|
<body className="flex justify-center">
|
||||||
<div className="bg-slate-900 h-screen text-slate-300 w-full sm:p-1">
|
<div className="bg-slate-900 h-screen text-slate-300 w-full sm:p-1">
|
||||||
<MyToaster />
|
<MyToaster />
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<Providers>
|
<Providers>
|
||||||
|
<HydrationBoundary state={dehydratedTrpc}>
|
||||||
<HydrationBoundary state={dehydratedState}>
|
<HydrationBoundary state={dehydratedState}>
|
||||||
{children}
|
{children}
|
||||||
</HydrationBoundary>
|
</HydrationBoundary>
|
||||||
</Providers>
|
</HydrationBoundary>
|
||||||
</Suspense>
|
</Providers>
|
||||||
|
</Suspense>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ import { canvasPageService } from "@/services/canvas/canvasPageService";
|
|||||||
import { canvasQuizKeys } from "./canvas/canvasQuizHooks";
|
import { canvasQuizKeys } from "./canvas/canvasQuizHooks";
|
||||||
import { canvasPageKeys } from "./canvas/canvasPageHooks";
|
import { canvasPageKeys } from "./canvas/canvasPageHooks";
|
||||||
import { getLecturesQueryConfig } from "./localCourse/lectureHooks";
|
import { getLecturesQueryConfig } from "./localCourse/lectureHooks";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
|
||||||
import { appRouter } from "@/services/trpc/router/app";
|
|
||||||
import superjson from "superjson";
|
|
||||||
import { createContext } from "@/services/trpc/context";
|
|
||||||
|
|
||||||
// https://tanstack.com/query/latest/docs/framework/react/guides/ssr
|
// https://tanstack.com/query/latest/docs/framework/react/guides/ssr
|
||||||
export const hydrateCourses = async (queryClient: QueryClient) => {
|
export const hydrateCourses = async (queryClient: QueryClient) => {
|
||||||
@@ -36,26 +32,30 @@ export const hydrateCourse = async (
|
|||||||
queryClient: QueryClient,
|
queryClient: QueryClient,
|
||||||
courseSettings: LocalCourseSettings
|
courseSettings: LocalCourseSettings
|
||||||
) => {
|
) => {
|
||||||
const trpcHelpers = createServerSideHelpers({
|
|
||||||
router: appRouter,
|
|
||||||
ctx: createContext(),
|
|
||||||
transformer: superjson,
|
|
||||||
});
|
|
||||||
|
|
||||||
const courseName = courseSettings.name;
|
const courseName = courseSettings.name;
|
||||||
const moduleNames = await fileStorageService.modules.getModuleNames(
|
const moduleNames = await fileStorageService.modules.getModuleNames(
|
||||||
courseName
|
courseName
|
||||||
);
|
);
|
||||||
|
|
||||||
await Promise.all(
|
// await Promise.all(
|
||||||
moduleNames.map(
|
// moduleNames.map(async (moduleName) => {
|
||||||
async (moduleName) =>
|
// const assignments = await trpcHelpers.assignment.getAllAssignments.fetch({
|
||||||
await trpcHelpers.assignment.getAllAssignments.fetch({
|
// courseName,
|
||||||
courseName,
|
// moduleName,
|
||||||
moduleName,
|
// });
|
||||||
})
|
// await Promise.all(
|
||||||
)
|
// assignments.map(
|
||||||
);
|
// async (a) =>
|
||||||
|
// await trpcHelpers.assignment.getAssignment.fetch({
|
||||||
|
// courseName,
|
||||||
|
// moduleName,
|
||||||
|
// assignmentName: a.name,
|
||||||
|
// })
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
// })
|
||||||
|
// );
|
||||||
|
|
||||||
const modulesData = await Promise.all(
|
const modulesData = await Promise.all(
|
||||||
moduleNames.map((moduleName) => loadAllModuleData(courseName, moduleName))
|
moduleNames.map((moduleName) => loadAllModuleData(courseName, moduleName))
|
||||||
@@ -136,26 +136,26 @@ const loadAllModuleData = async (courseName: string, moduleName: string) => {
|
|||||||
const hydrateModuleData = async (
|
const hydrateModuleData = async (
|
||||||
{
|
{
|
||||||
moduleName,
|
moduleName,
|
||||||
assignments,
|
// assignments,
|
||||||
quizzes,
|
quizzes,
|
||||||
pages,
|
pages,
|
||||||
}: {
|
}: {
|
||||||
moduleName: string;
|
moduleName: string;
|
||||||
assignments: LocalAssignment[];
|
// assignments: LocalAssignment[];
|
||||||
quizzes: LocalQuiz[];
|
quizzes: LocalQuiz[];
|
||||||
pages: LocalCoursePage[];
|
pages: LocalCoursePage[];
|
||||||
},
|
},
|
||||||
courseName: string,
|
courseName: string,
|
||||||
queryClient: QueryClient
|
queryClient: QueryClient
|
||||||
) => {
|
) => {
|
||||||
await queryClient.prefetchQuery({
|
// await queryClient.prefetchQuery({
|
||||||
queryKey: localCourseKeys.allItemsOfType(
|
// queryKey: localCourseKeys.allItemsOfType(
|
||||||
courseName,
|
// courseName,
|
||||||
moduleName,
|
// moduleName,
|
||||||
"Assignment"
|
// "Assignment"
|
||||||
),
|
// ),
|
||||||
queryFn: () => assignments,
|
// queryFn: () => assignments,
|
||||||
});
|
// });
|
||||||
await queryClient.prefetchQuery({
|
await queryClient.prefetchQuery({
|
||||||
queryKey: localCourseKeys.allItemsOfType(courseName, moduleName, "Quiz"),
|
queryKey: localCourseKeys.allItemsOfType(courseName, moduleName, "Quiz"),
|
||||||
queryFn: () => quizzes,
|
queryFn: () => quizzes,
|
||||||
@@ -164,20 +164,20 @@ const hydrateModuleData = async (
|
|||||||
queryKey: localCourseKeys.allItemsOfType(courseName, moduleName, "Page"),
|
queryKey: localCourseKeys.allItemsOfType(courseName, moduleName, "Page"),
|
||||||
queryFn: () => pages,
|
queryFn: () => pages,
|
||||||
});
|
});
|
||||||
await Promise.all(
|
// await Promise.all(
|
||||||
assignments.map(
|
// assignments.map(
|
||||||
async (assignment) =>
|
// async (assignment) =>
|
||||||
await queryClient.prefetchQuery({
|
// await queryClient.prefetchQuery({
|
||||||
queryKey: localCourseKeys.itemOfType(
|
// queryKey: localCourseKeys.itemOfType(
|
||||||
courseName,
|
// courseName,
|
||||||
moduleName,
|
// moduleName,
|
||||||
assignment.name,
|
// assignment.name,
|
||||||
"Assignment"
|
// "Assignment"
|
||||||
),
|
// ),
|
||||||
queryFn: () => assignment,
|
// queryFn: () => assignment,
|
||||||
})
|
// })
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
quizzes.map(
|
quizzes.map(
|
||||||
async (quiz) =>
|
async (quiz) =>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export const useAssignmentQuery = (
|
|||||||
|
|
||||||
export const useAssignmentsQuery = (moduleName: string) => {
|
export const useAssignmentsQuery = (moduleName: string) => {
|
||||||
const { courseName } = useCourseContext();
|
const { courseName } = useCourseContext();
|
||||||
return trpc.assignment.getAllAssignments.useSuspenseQuery({
|
return trpc.assignment.getAllAssignments.useQuery({
|
||||||
moduleName,
|
moduleName,
|
||||||
courseName,
|
courseName,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import type { CreateNextContextOptions } from '@trpc/server/adapters/next';
|
|
||||||
|
|
||||||
export const createContext = async () => {
|
export const createTrpcContext = async () => {
|
||||||
|
return {};
|
||||||
return {
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Context = typeof createContext;
|
export type TrpcContext = typeof createTrpcContext;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createContext } from "../context";
|
import { createTrpcContext } from "../context";
|
||||||
import publicProcedure from "../procedures/public";
|
import publicProcedure from "../procedures/public";
|
||||||
import { createCallerFactory, mergeRouters, router } from "../trpc";
|
import { createCallerFactory, router } from "../trpc";
|
||||||
import { assignmentRouter } from "./assignmentRouter";
|
import { assignmentRouter } from "./assignmentRouter";
|
||||||
|
|
||||||
export const helloRouter = router({
|
export const helloRouter = router({
|
||||||
@@ -11,16 +11,16 @@ export const helloRouter = router({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const appRouter = router({
|
export const trpcAppRouter = router({
|
||||||
hello: helloRouter,
|
hello: helloRouter,
|
||||||
assignment: assignmentRouter,
|
assignment: assignmentRouter,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const createCaller = createCallerFactory(appRouter);
|
export const createCaller = createCallerFactory(trpcAppRouter);
|
||||||
|
|
||||||
export const createAsyncCaller = async () => {
|
export const createAsyncCaller = async () => {
|
||||||
const context = await createContext();
|
const context = await createTrpcContext();
|
||||||
return createCaller(context);
|
return createCaller(context);
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AppRouter = typeof appRouter;
|
export type AppRouter = typeof trpcAppRouter;
|
||||||
|
|||||||
Reference in New Issue
Block a user