Merge fix/progress-bar into feat/232-assignments-pagina-ui-ux
This commit is contained in:
commit
368130c431
149 changed files with 4429 additions and 1120 deletions
|
@ -15,6 +15,7 @@ import { invalidateAllGroupKeys } from "./groups";
|
|||
import { invalidateAllSubmissionKeys } from "./submissions";
|
||||
import type { TeachersResponse } from "@/controllers/teachers";
|
||||
import type { TeacherInvitationsResponse } from "@/controllers/teacher-invitations";
|
||||
import { studentClassesQueryKey } from "@/queries/students.ts";
|
||||
|
||||
const classController = new ClassController();
|
||||
|
||||
|
@ -171,6 +172,8 @@ export function useClassDeleteStudentMutation(): UseMutationReturnType<
|
|||
await queryClient.invalidateQueries({ queryKey: classQueryKey(data.class.id) });
|
||||
await queryClient.invalidateQueries({ queryKey: classStudentsKey(data.class.id, true) });
|
||||
await queryClient.invalidateQueries({ queryKey: classStudentsKey(data.class.id, false) });
|
||||
await queryClient.invalidateQueries({ queryKey: studentClassesQueryKey(data.class.id, false) });
|
||||
await queryClient.invalidateQueries({ queryKey: studentClassesQueryKey(data.class.id, true) });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
import { type MaybeRefOrGetter, toValue } from "vue";
|
||||
import type { Language } from "@/data-objects/language.ts";
|
||||
import { useQuery, type UseQueryReturnType } from "@tanstack/vue-query";
|
||||
import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
type UseMutationReturnType,
|
||||
type UseQueryReturnType,
|
||||
} from "@tanstack/vue-query";
|
||||
import { getLearningObjectController } from "@/controllers/controllers.ts";
|
||||
import type { LearningObject } from "@/data-objects/learning-objects/learning-object.ts";
|
||||
import type { LearningPath } from "@/data-objects/learning-paths/learning-path.ts";
|
||||
import type { AxiosError } from "axios";
|
||||
|
||||
export const LEARNING_OBJECT_KEY = "learningObject";
|
||||
const learningObjectController = getLearningObjectController();
|
||||
|
@ -24,15 +31,15 @@ export function useLearningObjectMetadataQuery(
|
|||
}
|
||||
|
||||
export function useLearningObjectHTMLQuery(
|
||||
hruid: MaybeRefOrGetter<string>,
|
||||
language: MaybeRefOrGetter<Language>,
|
||||
version: MaybeRefOrGetter<number>,
|
||||
hruid: MaybeRefOrGetter<string | undefined>,
|
||||
language: MaybeRefOrGetter<Language | undefined>,
|
||||
version: MaybeRefOrGetter<number | undefined>,
|
||||
): UseQueryReturnType<Document, Error> {
|
||||
return useQuery({
|
||||
queryKey: [LEARNING_OBJECT_KEY, "html", hruid, language, version],
|
||||
queryFn: async () => {
|
||||
const [hruidVal, languageVal, versionVal] = [toValue(hruid), toValue(language), toValue(version)];
|
||||
return learningObjectController.getHTML(hruidVal, languageVal, versionVal);
|
||||
return learningObjectController.getHTML(hruidVal!, languageVal!, versionVal!);
|
||||
},
|
||||
enabled: () => Boolean(toValue(hruid)) && Boolean(toValue(language)) && Boolean(toValue(version)),
|
||||
});
|
||||
|
@ -55,3 +62,49 @@ export function useLearningObjectListForPathQuery(
|
|||
enabled: () => Boolean(toValue(learningPath)),
|
||||
});
|
||||
}
|
||||
|
||||
export function useLearningObjectListForAdminQuery(
|
||||
admin: MaybeRefOrGetter<string | undefined>,
|
||||
): UseQueryReturnType<LearningObject[], Error> {
|
||||
return useQuery({
|
||||
queryKey: [LEARNING_OBJECT_KEY, "forAdmin", admin],
|
||||
queryFn: async () => {
|
||||
const adminVal = toValue(admin);
|
||||
return await learningObjectController.getAllAdministratedBy(adminVal!);
|
||||
},
|
||||
enabled: () => toValue(admin) !== undefined,
|
||||
});
|
||||
}
|
||||
|
||||
export function useUploadLearningObjectMutation(): UseMutationReturnType<
|
||||
LearningObject,
|
||||
AxiosError,
|
||||
{ learningObjectZip: File },
|
||||
unknown
|
||||
> {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ learningObjectZip }) => await learningObjectController.upload(learningObjectZip),
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({ queryKey: [LEARNING_OBJECT_KEY, "forAdmin"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteLearningObjectMutation(): UseMutationReturnType<
|
||||
LearningObject,
|
||||
AxiosError,
|
||||
{ hruid: string; language: Language; version: number },
|
||||
unknown
|
||||
> {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ hruid, language, version }) =>
|
||||
await learningObjectController.deleteLearningObject(hruid, language, version),
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({ queryKey: [LEARNING_OBJECT_KEY, "forAdmin"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,8 +1,16 @@
|
|||
import { type MaybeRefOrGetter, toValue } from "vue";
|
||||
import type { Language } from "@/data-objects/language.ts";
|
||||
import { useQuery, type UseQueryReturnType } from "@tanstack/vue-query";
|
||||
import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
type UseMutationReturnType,
|
||||
type UseQueryReturnType,
|
||||
} from "@tanstack/vue-query";
|
||||
import { getLearningPathController } from "@/controllers/controllers";
|
||||
import type { LearningPath } from "@/data-objects/learning-paths/learning-path.ts";
|
||||
import type { AxiosError } from "axios";
|
||||
import type { LearningPath as LearningPathDTO } from "@dwengo-1/common/interfaces/learning-content";
|
||||
import type { LearningPath } from "@/data-objects/learning-paths/learning-path";
|
||||
|
||||
export const LEARNING_PATH_KEY = "learningPath";
|
||||
const learningPathController = getLearningPathController();
|
||||
|
@ -22,16 +30,69 @@ export function useGetLearningPathQuery(
|
|||
});
|
||||
}
|
||||
|
||||
export function useGetAllLearningPathsByThemeQuery(
|
||||
export function useGetAllLearningPathsByThemeAndLanguageQuery(
|
||||
theme: MaybeRefOrGetter<string>,
|
||||
language: MaybeRefOrGetter<Language>,
|
||||
): UseQueryReturnType<LearningPath[], Error> {
|
||||
return useQuery({
|
||||
queryKey: [LEARNING_PATH_KEY, "getAllByTheme", theme],
|
||||
queryFn: async () => learningPathController.getAllByTheme(toValue(theme)),
|
||||
queryKey: [LEARNING_PATH_KEY, "getAllByTheme", theme, language],
|
||||
queryFn: async () => learningPathController.getAllByThemeAndLanguage(toValue(theme), toValue(language)),
|
||||
enabled: () => Boolean(toValue(theme)),
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetAllLearningPathsByAdminQuery(
|
||||
admin: MaybeRefOrGetter<string | undefined>,
|
||||
): UseQueryReturnType<LearningPathDTO[], AxiosError> {
|
||||
return useQuery({
|
||||
queryKey: [LEARNING_PATH_KEY, "getAllByAdmin", admin],
|
||||
queryFn: async () => learningPathController.getAllByAdminRaw(toValue(admin)!),
|
||||
enabled: () => Boolean(toValue(admin)),
|
||||
});
|
||||
}
|
||||
|
||||
export function usePostLearningPathMutation(): UseMutationReturnType<
|
||||
LearningPathDTO,
|
||||
AxiosError,
|
||||
{ learningPath: Partial<LearningPathDTO> },
|
||||
unknown
|
||||
> {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ learningPath }) => learningPathController.postLearningPath(learningPath),
|
||||
onSuccess: async () => queryClient.invalidateQueries({ queryKey: [LEARNING_PATH_KEY] }),
|
||||
});
|
||||
}
|
||||
|
||||
export function usePutLearningPathMutation(): UseMutationReturnType<
|
||||
LearningPathDTO,
|
||||
AxiosError,
|
||||
{ learningPath: Partial<LearningPathDTO> },
|
||||
unknown
|
||||
> {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ learningPath }) => learningPathController.putLearningPath(learningPath),
|
||||
onSuccess: async () => queryClient.invalidateQueries({ queryKey: [LEARNING_PATH_KEY] }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteLearningPathMutation(): UseMutationReturnType<
|
||||
LearningPathDTO,
|
||||
AxiosError,
|
||||
{ hruid: string; language: Language },
|
||||
unknown
|
||||
> {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ hruid, language }) => learningPathController.deleteLearningPath(hruid, language),
|
||||
onSuccess: async () => queryClient.invalidateQueries({ queryKey: [LEARNING_PATH_KEY] }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useSearchLearningPathQuery(
|
||||
query: MaybeRefOrGetter<string | undefined>,
|
||||
language: MaybeRefOrGetter<string | undefined>,
|
||||
|
|
|
@ -33,7 +33,7 @@ function studentsQueryKey(full: boolean): [string, boolean] {
|
|||
function studentQueryKey(username: string): [string, string] {
|
||||
return ["student", username];
|
||||
}
|
||||
function studentClassesQueryKey(username: string, full: boolean): [string, string, boolean] {
|
||||
export function studentClassesQueryKey(username: string, full: boolean): [string, string, boolean] {
|
||||
return ["student-classes", username, full];
|
||||
}
|
||||
function studentAssignmentsQueryKey(username: string, full: boolean): [string, string, boolean] {
|
||||
|
|
|
@ -10,7 +10,6 @@ import {
|
|||
import { TeacherController, type TeacherResponse, type TeachersResponse } from "@/controllers/teachers.ts";
|
||||
import type { ClassesResponse } from "@/controllers/classes.ts";
|
||||
import type { JoinRequestResponse, JoinRequestsResponse, StudentsResponse } from "@/controllers/students.ts";
|
||||
import type { QuestionsResponse } from "@/controllers/questions.ts";
|
||||
import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher";
|
||||
import { studentJoinRequestQueryKey, studentJoinRequestsQueryKey } from "@/queries/students.ts";
|
||||
import type { AssignmentResponse, AssignmentsResponse } from "@/controllers/assignments";
|
||||
|
@ -38,10 +37,6 @@ function teacherStudentsQueryKey(username: string, full: boolean): [string, stri
|
|||
return ["teacher-students", username, full];
|
||||
}
|
||||
|
||||
function teacherQuestionsQueryKey(username: string, full: boolean): [string, string, boolean] {
|
||||
return ["teacher-questions", username, full];
|
||||
}
|
||||
|
||||
export function teacherClassJoinRequests(classId: string): [string, string] {
|
||||
return ["teacher-class-join-requests", classId];
|
||||
}
|
||||
|
@ -96,17 +91,6 @@ export function useTeacherStudentsQuery(
|
|||
});
|
||||
}
|
||||
|
||||
export function useTeacherQuestionsQuery(
|
||||
username: MaybeRefOrGetter<string | undefined>,
|
||||
full: MaybeRefOrGetter<boolean> = false,
|
||||
): UseQueryReturnType<QuestionsResponse, Error> {
|
||||
return useQuery({
|
||||
queryKey: computed(() => teacherQuestionsQueryKey(toValue(username)!, toValue(full))),
|
||||
queryFn: async () => teacherController.getQuestions(toValue(username)!, toValue(full)),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
});
|
||||
}
|
||||
|
||||
export function useTeacherJoinRequestsQuery(
|
||||
username: MaybeRefOrGetter<string | undefined>,
|
||||
classId: MaybeRefOrGetter<string | undefined>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue