mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
adding storage for lectures
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||
import {
|
||||
useMutation,
|
||||
useQueryClient,
|
||||
useSuspenseQuery,
|
||||
} from "@tanstack/react-query";
|
||||
import { lectureKeys } from "./lectureKeys";
|
||||
import { useCourseContext } from "@/app/course/[courseName]/context/courseContext";
|
||||
import { getLectures } from "@/services/fileStorage/lectureFileStorageService";
|
||||
import {
|
||||
getLectures,
|
||||
updateLecture,
|
||||
} from "@/services/fileStorage/lectureFileStorageService";
|
||||
import { Lecture } from "@/models/local/lecture";
|
||||
import { useLocalCourseSettingsQuery } from "./localCoursesHooks";
|
||||
|
||||
export const getLecturesQueryConfig = (courseName: string) =>
|
||||
({
|
||||
@@ -9,7 +18,23 @@ export const getLecturesQueryConfig = (courseName: string) =>
|
||||
queryFn: async () => await getLectures(courseName),
|
||||
} as const);
|
||||
|
||||
export const useLecturesQuery = () => {
|
||||
export const useLecturesByWeekQuery = () => {
|
||||
const { courseName } = useCourseContext();
|
||||
return useSuspenseQuery(getLecturesQueryConfig(courseName));
|
||||
};
|
||||
|
||||
export const useLectureUpdateMutation = () => {
|
||||
const { courseName } = useCourseContext();
|
||||
const { data: settings } = useLocalCourseSettingsQuery();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (lecture: Lecture) => {
|
||||
await updateLecture(courseName, settings, lecture);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: lectureKeys.allLectures(courseName),
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user