better matching

This commit is contained in:
2024-08-26 12:52:55 -06:00
parent 884e465df6
commit cafe04faf6
15 changed files with 232 additions and 33 deletions

View 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(),
});
};

View 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;
},
});