mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
doing more trpc, still working on preloading
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { QueryClient } from "@tanstack/react-query";
|
||||
import { localCourseKeys } from "./localCourse/localCourseKeys";
|
||||
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||
import { LocalCourseSettings } from "@/models/local/localCourse";
|
||||
import { LocalCourseSettings } from "@/models/local/localCourseSettings";
|
||||
import { canvasAssignmentService } from "@/services/canvas/canvasAssignmentService";
|
||||
import { canvasAssignmentKeys } from "./canvas/canvasAssignmentHooks";
|
||||
import { LocalAssignment } from "@/models/local/assignment/localAssignment";
|
||||
@@ -32,7 +32,6 @@ export const hydrateCourse = async (
|
||||
queryClient: QueryClient,
|
||||
courseSettings: LocalCourseSettings
|
||||
) => {
|
||||
|
||||
const courseName = courseSettings.name;
|
||||
const moduleNames = await fileStorageService.modules.getModuleNames(
|
||||
courseName
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
getModuleNamesFromServer,
|
||||
} from "./localCourseModuleServerActions";
|
||||
import { trpc } from "@/services/trpc/utils";
|
||||
import { LocalAssignment } from "@/models/local/assignment/localAssignment";
|
||||
|
||||
export const useModuleNamesQuery = () => {
|
||||
const { courseName } = useCourseContext();
|
||||
@@ -38,7 +39,14 @@ export const useCreateModuleMutation = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useAllCourseDataQuery = () => {
|
||||
export const useAllCourseDataQuery = (): {
|
||||
assignmentsAndModules: {
|
||||
moduleName: string;
|
||||
assignment: LocalAssignment;
|
||||
}[];
|
||||
quizzesAndModules: any[];
|
||||
pagesAndModules: any[];
|
||||
} => {
|
||||
const { courseName } = useCourseContext();
|
||||
const { data: moduleNames } = useModuleNamesQuery();
|
||||
|
||||
|
||||
@@ -1,101 +1,34 @@
|
||||
"use client";
|
||||
import { LocalCourse, LocalCourseSettings } from "@/models/local/localCourse";
|
||||
import {
|
||||
useMutation,
|
||||
useQueryClient,
|
||||
useSuspenseQuery,
|
||||
} from "@tanstack/react-query";
|
||||
import { localCourseKeys } from "./localCourseKeys";
|
||||
import { useCourseContext } from "@/app/course/[courseName]/context/courseContext";
|
||||
import {
|
||||
createCourseOnServer,
|
||||
updateCourseSettingsOnServer,
|
||||
} from "./localCoursesServerActions";
|
||||
import { trpc } from "@/services/trpc/utils";
|
||||
|
||||
export const useLocalCoursesSettingsQuery = () =>
|
||||
trpc.settings.allCoursesSettings.useSuspenseQuery();
|
||||
// useSuspenseQuery({
|
||||
// queryKey: localCourseKeys.allCoursesSettings,
|
||||
// queryFn: async () => {
|
||||
// return await getAllCoursesSettingsFromServer();
|
||||
// },
|
||||
// });
|
||||
|
||||
|
||||
export const useLocalCourseSettingsQuery = () => {
|
||||
const { courseName } = useCourseContext();
|
||||
// const { data: settingsList } = useLocalCoursesSettingsQuery();
|
||||
return trpc.settings.courseSettings.useSuspenseQuery({ courseName });
|
||||
// return useSuspenseQuery({
|
||||
// queryKey: localCourseKeys.settings(courseName),
|
||||
// queryFn: async () => {
|
||||
// const settingsList = await getAllCoursesSettingsFromServer();
|
||||
// const s = settingsList.find((s) => s.name === courseName);
|
||||
// if (!s) {
|
||||
// console.log(courseName, settingsList);
|
||||
// throw Error("Could not find settings for course " + courseName);
|
||||
// }
|
||||
// return s;
|
||||
// },
|
||||
// });
|
||||
|
||||
};
|
||||
|
||||
export const useCreateLocalCourseMutation = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (newCourse: LocalCourse) => {
|
||||
await createCourseOnServer({ course: newCourse });
|
||||
},
|
||||
const utils = trpc.useUtils();
|
||||
return trpc.settings.createCourse.useMutation({
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: localCourseKeys.allCoursesSettings,
|
||||
});
|
||||
utils.settings.allCoursesSettings.invalidate();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateLocalCourseSettingsMutation = () => {
|
||||
const { courseName } = useCourseContext();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (updatedSettings: LocalCourseSettings) => {
|
||||
// queryClient.setQueryData(
|
||||
// localCourseKeys.settings(courseName),
|
||||
// updatedSettings
|
||||
// );
|
||||
await updateCourseSettingsOnServer({
|
||||
courseName,
|
||||
settings: updatedSettings,
|
||||
});
|
||||
},
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: localCourseKeys.allCoursesSettings,
|
||||
});
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: localCourseKeys.settings(courseName),
|
||||
});
|
||||
const utils = trpc.useUtils();
|
||||
|
||||
return trpc.settings.createCourse.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.settings.allCoursesSettings.invalidate();
|
||||
utils.settings.courseSettings.invalidate({ courseName });
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// export const useUpdateCourseMutation = (courseName: string) => {
|
||||
// const queryClient = useQueryClient();
|
||||
// return useMutation({
|
||||
// mutationFn: async (body: {
|
||||
// updatedCourse: LocalCourse;
|
||||
// previousCourse: LocalCourse;
|
||||
// }) => {
|
||||
// const url = `/api/courses/${courseName}`;
|
||||
// await axiosClient.put(url, body);
|
||||
// },
|
||||
// onSuccess: () => {
|
||||
// queryClient.invalidateQueries({
|
||||
// queryKey: localCourseKeys.settings(courseName),
|
||||
// });
|
||||
// },
|
||||
// scope: {
|
||||
// id: "all courses",
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use server";
|
||||
import { LocalCourse, LocalCourseSettings } from "@/models/local/localCourse";
|
||||
import {
|
||||
LocalCourseSettings,
|
||||
} from "@/models/local/localCourseSettings";
|
||||
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||
|
||||
export async function getCourseSettingsFromServer({
|
||||
@@ -13,23 +15,23 @@ export async function getAllCoursesSettingsFromServer() {
|
||||
return await fileStorageService.settings.getAllCoursesSettings();
|
||||
}
|
||||
|
||||
export async function createCourseOnServer({
|
||||
course,
|
||||
}: {
|
||||
course: LocalCourse;
|
||||
}) {
|
||||
await fileStorageService.settings.updateCourseSettings(
|
||||
course.settings.name,
|
||||
course.settings
|
||||
);
|
||||
}
|
||||
// export async function createCourseOnServer({
|
||||
// course,
|
||||
// }: {
|
||||
// course: LocalCourse;
|
||||
// }) {
|
||||
// await fileStorageService.settings.updateCourseSettings(
|
||||
// course.settings.name,
|
||||
// course.settings
|
||||
// );
|
||||
// }
|
||||
|
||||
export async function updateCourseSettingsOnServer({
|
||||
courseName,
|
||||
settings,
|
||||
}: {
|
||||
courseName: string;
|
||||
settings: LocalCourseSettings;
|
||||
}) {
|
||||
await fileStorageService.settings.updateCourseSettings(courseName, settings);
|
||||
}
|
||||
// export async function updateCourseSettingsOnServer({
|
||||
// courseName,
|
||||
// settings,
|
||||
// }: {
|
||||
// courseName: string;
|
||||
// settings: LocalCourseSettings;
|
||||
// }) {
|
||||
// await fileStorageService.settings.updateCourseSettings(courseName, settings);
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user