mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
better matching
This commit is contained in:
10
nextjs/src/hooks/hookHydration.ts
Normal file
10
nextjs/src/hooks/hookHydration.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { QueryClient } from "@tanstack/react-query";
|
||||
import { localCourseKeys } from "./localCoursesHooks";
|
||||
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||
|
||||
export const hydrateCourses = async (queryClient: QueryClient) => {
|
||||
await queryClient.prefetchQuery({
|
||||
queryKey: localCourseKeys.allCourses,
|
||||
queryFn: async () => await fileStorageService.loadSavedCourses(),
|
||||
});
|
||||
};
|
||||
17
nextjs/src/hooks/localCoursesHooks.ts
Normal file
17
nextjs/src/hooks/localCoursesHooks.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { LocalCourse } from "@/models/local/localCourse";
|
||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||
import axios from "axios";
|
||||
|
||||
export const localCourseKeys = {
|
||||
allCourses: ["all courses"] as const,
|
||||
};
|
||||
|
||||
export const useLocalCoursesQuery = () =>
|
||||
useSuspenseQuery({
|
||||
queryKey: localCourseKeys.allCourses,
|
||||
queryFn: async (): Promise<LocalCourse[]> => {
|
||||
const url = `/api/courses`;
|
||||
const response = await axios.get(url);
|
||||
return response.data;
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user