mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
117 lines
3.1 KiB
TypeScript
117 lines
3.1 KiB
TypeScript
import type { Metadata } from "next";
|
|
import "./globals.css";
|
|
import Providers from "./providers";
|
|
import { Suspense } from "react";
|
|
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
|
|
import { MyToaster } from "./MyToaster";
|
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
|
import { trpcAppRouter } from "@/services/serverFunctions/router/app";
|
|
import { createTrpcContext } from "@/services/serverFunctions/context";
|
|
import superjson from "superjson";
|
|
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
|
import { ClientCacheInvalidation } from "../components/realtime/ClientCacheInvalidation";
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export const metadata: Metadata = {
|
|
title: "Canvas Manager 2.0",
|
|
};
|
|
|
|
export default async function RootLayout({
|
|
children,
|
|
}: Readonly<{
|
|
children: React.ReactNode;
|
|
}>) {
|
|
return (
|
|
<html lang="en">
|
|
<head></head>
|
|
<body className="flex justify-center">
|
|
<div className="bg-slate-900 h-screen text-slate-300 w-full sm:p-1">
|
|
<MyToaster />
|
|
<Suspense>
|
|
<Providers>
|
|
<DataHydration>
|
|
<ClientCacheInvalidation></ClientCacheInvalidation>
|
|
{children}
|
|
</DataHydration>
|
|
</Providers>
|
|
</Suspense>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
);
|
|
}
|
|
|
|
async function DataHydration({
|
|
children,
|
|
}: Readonly<{
|
|
children: React.ReactNode;
|
|
}>) {
|
|
console.log("starting hydration");
|
|
const trpcHelper = createServerSideHelpers({
|
|
router: trpcAppRouter,
|
|
ctx: createTrpcContext(),
|
|
transformer: superjson,
|
|
queryClientConfig: {
|
|
defaultOptions: {
|
|
queries: {
|
|
staleTime: Infinity,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
const allSettings = await fileStorageService.settings.getAllCoursesSettings();
|
|
|
|
await Promise.all(
|
|
allSettings.map(async (settings) => {
|
|
const courseName = settings.name;
|
|
const moduleNames = await trpcHelper.module.getModuleNames.fetch({
|
|
courseName,
|
|
});
|
|
await Promise.all([
|
|
// assignments
|
|
...moduleNames.map(
|
|
async (moduleName) =>
|
|
await trpcHelper.assignment.getAllAssignments.prefetch({
|
|
courseName,
|
|
moduleName,
|
|
})
|
|
),
|
|
// quizzes
|
|
...moduleNames.map(
|
|
async (moduleName) =>
|
|
await trpcHelper.quiz.getAllQuizzes.prefetch({
|
|
courseName,
|
|
moduleName,
|
|
})
|
|
),
|
|
// pages
|
|
...moduleNames.map(
|
|
async (moduleName) =>
|
|
await trpcHelper.page.getAllPages.prefetch({
|
|
courseName,
|
|
moduleName,
|
|
})
|
|
),
|
|
]);
|
|
})
|
|
);
|
|
|
|
// lectures
|
|
await Promise.all(
|
|
allSettings.map(
|
|
async (settings) =>
|
|
await trpcHelper.lectures.getLectures.fetch({
|
|
courseName: settings.name,
|
|
})
|
|
)
|
|
);
|
|
|
|
const dehydratedState = dehydrate(trpcHelper.queryClient);
|
|
console.log("ran hydration");
|
|
|
|
return (
|
|
<HydrationBoundary state={dehydratedState}>{children}</HydrationBoundary>
|
|
);
|
|
}
|