starting to move over settings

This commit is contained in:
2024-11-08 16:01:41 -07:00
parent 6fd5053ac5
commit 026ca3846f
35 changed files with 188 additions and 155 deletions

View File

@@ -33,7 +33,7 @@ export default async function RootLayout({
<MyToaster />
<Suspense>
<Providers>
{children}
<DataHydration>{children}</DataHydration>
</Providers>
</Suspense>
</div>
@@ -41,3 +41,52 @@ export default async function RootLayout({
</html>
);
}
async function DataHydration({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
console.log("starting hydration");
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(
allSettings.map(
async (settings) =>
await trpcHelper.lectures.getLectures.prefetch({
courseName: settings.name,
})
)
);
await hydrateCourses(trpcHelper.queryClient);
const dehydratedState = dehydrate(trpcHelper.queryClient);
console.log("ran hydration");
return (
<HydrationBoundary state={dehydratedState}>{children}</HydrationBoundary>
);
}