mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
refactoring quiz data fetching to simplify
This commit is contained in:
@@ -6,7 +6,6 @@ import {
|
||||
} from "@/hooks/localCourse/lectureHooks";
|
||||
import { useLocalCourseSettingsQuery } from "@/hooks/localCourse/localCoursesHooks";
|
||||
import { useUpdatePageMutation } from "@/hooks/localCourse/pageHooks";
|
||||
import { useUpdateQuizMutation } from "@/hooks/localCourse/quizHooks";
|
||||
import { LocalAssignment } from "@/models/local/assignment/localAssignment";
|
||||
import { Lecture } from "@/models/local/lecture";
|
||||
import { getLectureForDay } from "@/models/local/lectureUtils";
|
||||
@@ -20,6 +19,7 @@ import {
|
||||
import { Dispatch, SetStateAction, useCallback, DragEvent } from "react";
|
||||
import { DraggableItem } from "./draggingContext";
|
||||
import { getNewLockDate } from "./getNewLockDate";
|
||||
import { useUpdateItemMutation } from "@/hooks/localCourse/courseItemHooks";
|
||||
|
||||
export function useItemDropOnDay({
|
||||
setIsDragging,
|
||||
@@ -36,7 +36,7 @@ export function useItemDropOnDay({
|
||||
}) {
|
||||
const { data: settings } = useLocalCourseSettingsQuery();
|
||||
const { data: weeks } = useLecturesByWeekQuery();
|
||||
const updateQuizMutation = useUpdateQuizMutation();
|
||||
const updateQuizMutation = useUpdateItemMutation("Quiz");
|
||||
const updateLectureMutation = useLectureUpdateMutation();
|
||||
const updateAssignmentMutation = useUpdateAssignmentMutation();
|
||||
const updatePageMutation = useUpdatePageMutation();
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
"use client";
|
||||
import { useUpdateAssignmentMutation } from "@/hooks/localCourse/assignmentHooks";
|
||||
import { useUpdatePageMutation } from "@/hooks/localCourse/pageHooks";
|
||||
import { useUpdateQuizMutation } from "@/hooks/localCourse/quizHooks";
|
||||
import { LocalAssignment } from "@/models/local/assignment/localAssignment";
|
||||
import { LocalCoursePage } from "@/models/local/page/localCoursePage";
|
||||
import { LocalQuiz } from "@/models/local/quiz/localQuiz";
|
||||
import { Dispatch, SetStateAction, useCallback, DragEvent } from "react";
|
||||
import { DraggableItem } from "./draggingContext";
|
||||
import { useUpdateItemMutation } from "@/hooks/localCourse/courseItemHooks";
|
||||
|
||||
export function useItemDropOnModule({
|
||||
setIsDragging,
|
||||
}: {
|
||||
setIsDragging: Dispatch<SetStateAction<boolean>>;
|
||||
}) {
|
||||
const updateQuizMutation = useUpdateQuizMutation();
|
||||
const updateQuizMutation = useUpdateItemMutation("Quiz");
|
||||
const updateAssignmentMutation = useUpdateAssignmentMutation();
|
||||
const updatePageMutation = useUpdatePageMutation();
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ export default function LecturePreview({ lecture }: { lecture: Lecture }) {
|
||||
</section>
|
||||
<section>
|
||||
<div
|
||||
className="markdownPreview"
|
||||
className="markdownPreview text-xl"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: markdownToHTMLSafe(lecture.content),
|
||||
}}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useLecturesByWeekQuery } from "@/hooks/localCourse/lectureHooks";
|
||||
import LecturePreview from "../LecturePreview";
|
||||
import { getLectureUrl } from "@/services/urlUtils";
|
||||
import { getCourseUrl, getLectureUrl } from "@/services/urlUtils";
|
||||
import { useCourseContext } from "../../../context/courseContext";
|
||||
import Link from "next/link";
|
||||
|
||||
@@ -22,18 +22,29 @@ export default function LecturePreviewPage({
|
||||
}
|
||||
return (
|
||||
<div className="flex h-full xl:flex-row flex-col ">
|
||||
<div className="flex-shrink flex-1 pb-1 ms-3 xl:ms-0">
|
||||
<Link className="btn" href={getLectureUrl(courseName, lectureDay)}>
|
||||
Edit Page
|
||||
</Link>
|
||||
<div className="flex-shrink flex-1 pb-1 ms-3 xl:ms-0 flex flex-row flex-wrap gap-3 content-start ">
|
||||
<div className="">
|
||||
<Link
|
||||
className="btn"
|
||||
href={getLectureUrl(courseName, lectureDay)}
|
||||
shallow={true}
|
||||
>
|
||||
Edit Page
|
||||
</Link>
|
||||
</div>
|
||||
<div className="">
|
||||
<Link className="btn" href={getCourseUrl(courseName)} shallow={true}>
|
||||
Course Calendar
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-center min-h-0 px-2">
|
||||
<div
|
||||
className="
|
||||
w-full max-w-screen-lg
|
||||
border-slate-700 border-4 rounded-md
|
||||
p-3 overflow-auto
|
||||
"
|
||||
w-full max-w-screen-lg
|
||||
border-slate-700 border-4 rounded-md
|
||||
p-3 overflow-auto
|
||||
"
|
||||
>
|
||||
<LecturePreview lecture={lecture} />
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
import { useAssignmentsQueries } from "@/hooks/localCourse/assignmentHooks";
|
||||
import { usePagesQueries } from "@/hooks/localCourse/pageHooks";
|
||||
import { useQuizzesQueries } from "@/hooks/localCourse/quizHooks";
|
||||
import { IModuleItem } from "@/models/local/IModuleItem";
|
||||
import {
|
||||
getDateFromString,
|
||||
@@ -20,6 +19,7 @@ import { getModuleItemUrl } from "@/services/urlUtils";
|
||||
import { useCourseContext } from "../context/courseContext";
|
||||
import { Expandable } from "../../../../components/Expandable";
|
||||
import { useDragStyleContext } from "../context/drag/dragStyleContext";
|
||||
import { useItemsQueries } from "@/hooks/localCourse/courseItemHooks";
|
||||
|
||||
export default function ExpandableModule({
|
||||
moduleName,
|
||||
@@ -29,7 +29,7 @@ export default function ExpandableModule({
|
||||
const { itemDropOnModule } = useDraggingContext();
|
||||
|
||||
const { data: assignments } = useAssignmentsQueries(moduleName);
|
||||
const { data: quizzes } = useQuizzesQueries(moduleName);
|
||||
const { data: quizzes } = useItemsQueries(moduleName, "Quiz");
|
||||
const { data: pages } = usePagesQueries(moduleName);
|
||||
const modal = useModal();
|
||||
|
||||
|
||||
@@ -4,11 +4,10 @@ import SelectInput from "@/components/form/SelectInput";
|
||||
import TextInput from "@/components/form/TextInput";
|
||||
import { Spinner } from "@/components/Spinner";
|
||||
import { useCreateAssignmentMutation } from "@/hooks/localCourse/assignmentHooks";
|
||||
import { useCreateItemMutation } from "@/hooks/localCourse/courseItemHooks";
|
||||
import { useModuleNamesQuery } from "@/hooks/localCourse/localCourseModuleHooks";
|
||||
import { useLocalCourseSettingsQuery } from "@/hooks/localCourse/localCoursesHooks";
|
||||
import { useCreatePageMutation } from "@/hooks/localCourse/pageHooks";
|
||||
import { useCreateQuizMutation } from "@/hooks/localCourse/quizHooks";
|
||||
import { AssignmentSubmissionType } from "@/models/local/assignment/assignmentSubmissionType";
|
||||
import { LocalAssignmentGroup } from "@/models/local/assignment/localAssignmentGroup";
|
||||
import {
|
||||
dateToMarkdownString,
|
||||
@@ -53,7 +52,7 @@ export default function NewItemForm({
|
||||
|
||||
const createAssignment = useCreateAssignmentMutation();
|
||||
const createPage = useCreatePageMutation();
|
||||
const createQuiz = useCreateQuizMutation();
|
||||
const createQuiz = useCreateItemMutation("Quiz");
|
||||
|
||||
const isPending =
|
||||
createAssignment.isPending || createPage.isPending || createQuiz.isPending;
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
"use client";
|
||||
import { MonacoEditor } from "@/components/editor/MonacoEditor";
|
||||
import {
|
||||
useQuizQuery,
|
||||
useUpdateQuizMutation,
|
||||
} from "@/hooks/localCourse/quizHooks";
|
||||
import { quizMarkdownUtils } from "@/models/local/quiz/utils/quizMarkdownUtils";
|
||||
import { useEffect, useState } from "react";
|
||||
import QuizPreview from "./QuizPreview";
|
||||
@@ -13,6 +9,7 @@ import { SuspenseAndErrorHandling } from "@/components/SuspenseAndErrorHandling"
|
||||
import { useRouter } from "next/navigation";
|
||||
import { getModuleItemUrl } from "@/services/urlUtils";
|
||||
import { useCourseContext } from "@/app/course/[courseName]/context/courseContext";
|
||||
import { useItemQuery, useUpdateItemMutation } from "@/hooks/localCourse/courseItemHooks";
|
||||
|
||||
const helpString = `QUESTION REFERENCE
|
||||
---
|
||||
@@ -64,8 +61,8 @@ export default function EditQuiz({
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const { courseName } = useCourseContext();
|
||||
const { data: quiz } = useQuizQuery(moduleName, quizName);
|
||||
const updateQuizMutation = useUpdateQuizMutation();
|
||||
const { data: quiz } = useItemQuery(moduleName, quizName, "Quiz");
|
||||
const updateQuizMutation = useUpdateItemMutation("Quiz");
|
||||
const [quizText, setQuizText] = useState(quizMarkdownUtils.toMarkdown(quiz));
|
||||
const [error, setError] = useState("");
|
||||
const [showHelp, setShowHelp] = useState(false);
|
||||
@@ -111,7 +108,15 @@ export default function EditQuiz({
|
||||
return () => {
|
||||
clearTimeout(handler);
|
||||
};
|
||||
}, [courseName, moduleName, quiz, quizName, quizText, router, updateQuizMutation]);
|
||||
}, [
|
||||
courseName,
|
||||
moduleName,
|
||||
quiz,
|
||||
quizName,
|
||||
quizText,
|
||||
router,
|
||||
updateQuizMutation,
|
||||
]);
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-col align-middle px-1">
|
||||
|
||||
@@ -6,11 +6,8 @@ import {
|
||||
useAddQuizToCanvasMutation,
|
||||
useDeleteQuizFromCanvasMutation,
|
||||
} from "@/hooks/canvas/canvasQuizHooks";
|
||||
import { useDeleteItemMutation, useItemQuery } from "@/hooks/localCourse/courseItemHooks";
|
||||
import { useLocalCourseSettingsQuery } from "@/hooks/localCourse/localCoursesHooks";
|
||||
import {
|
||||
useDeleteQuizMutation,
|
||||
useQuizQuery,
|
||||
} from "@/hooks/localCourse/quizHooks";
|
||||
import { baseCanvasUrl } from "@/services/canvas/canvasServiceUtils";
|
||||
import { getCourseUrl } from "@/services/urlUtils";
|
||||
import Link from "next/link";
|
||||
@@ -29,10 +26,10 @@ export function QuizButtons({
|
||||
const { courseName } = useCourseContext();
|
||||
const { data: settings } = useLocalCourseSettingsQuery();
|
||||
const { data: canvasQuizzes } = useCanvasQuizzesQuery();
|
||||
const { data: quiz } = useQuizQuery(moduleName, quizName);
|
||||
const { data: quiz } = useItemQuery(moduleName, quizName, "Quiz");
|
||||
const addToCanvas = useAddQuizToCanvasMutation();
|
||||
const deleteFromCanvas = useDeleteQuizFromCanvasMutation();
|
||||
const deleteLocal = useDeleteQuizMutation();
|
||||
const deleteLocal = useDeleteItemMutation("Quiz");
|
||||
const modal = useModal();
|
||||
|
||||
const quizInCanvas = canvasQuizzes.find((c) => c.title === quizName);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import CheckIcon from "@/components/icons/CheckIcon";
|
||||
import { useQuizQuery } from "@/hooks/localCourse/quizHooks";
|
||||
import { LocalQuiz } from "@/models/local/quiz/localQuiz";
|
||||
import { useItemQuery } from "@/hooks/localCourse/courseItemHooks";
|
||||
import {
|
||||
LocalQuizQuestion,
|
||||
QuestionType,
|
||||
} from "@/models/local/quiz/localQuizQuestion";
|
||||
import { quizQuestionMarkdownUtils } from "@/models/local/quiz/utils/quizQuestionMarkdownUtils";
|
||||
import { markdownToHTMLSafe } from "@/services/htmlMarkdownUtils";
|
||||
|
||||
export default function QuizPreview({
|
||||
@@ -15,7 +13,7 @@ export default function QuizPreview({
|
||||
quizName: string;
|
||||
moduleName: string;
|
||||
}) {
|
||||
const { data: quiz } = useQuizQuery(moduleName, quizName);
|
||||
const { data: quiz } = useItemQuery(moduleName, quizName, "Quiz");
|
||||
return (
|
||||
<div style={{ overflow: "scroll", height: "100%" }}>
|
||||
<div className="columns-2">
|
||||
|
||||
Reference in New Issue
Block a user