can update quiz

This commit is contained in:
2024-08-30 13:15:10 -06:00
parent 51069a856a
commit 09b387c328
12 changed files with 227 additions and 94 deletions

View File

@@ -6,10 +6,26 @@ export async function GET(
params: { courseName, moduleName, quizName },
}: { params: { courseName: string; moduleName: string; quizName: string } }
) {
const settings = await fileStorageService.getQuiz(
const quiz = await fileStorageService.getQuiz(
courseName,
moduleName,
quizName
);
return Response.json(settings);
return Response.json(quiz);
}
export async function PUT(
request: Request,
{
params: { courseName, moduleName, quizName },
}: { params: { courseName: string; moduleName: string; quizName: string } }
) {
const quiz = await request.json()
await fileStorageService.updateQuiz(
courseName,
moduleName,
quizName,
quiz
);
return Response.json({});
}

View File

@@ -30,7 +30,6 @@ export default function CourseCalendar() {
bg-slate-950
"
>
Month Goes Here
{months.map((month) => (
<CalendarMonth key={month.month + "" + month.year} month={month} />
))}

View File

@@ -54,7 +54,13 @@ export default function DayItemsInModule({
key={q.name}
role="button"
draggable="true"
onDragStart={() => startItemDrag({ type: "quiz", item: q })}
onDragStart={() =>
startItemDrag({
type: "quiz",
item: q,
sourceModuleName: moduleName,
})
}
onDragEnd={endItemDrag}
>
{q.name}
@@ -65,7 +71,13 @@ export default function DayItemsInModule({
key={p.name}
role="button"
draggable="true"
onDragStart={() => startItemDrag({ type: "page", item: p })}
onDragStart={() =>
startItemDrag({
type: "page",
item: p,
sourceModuleName: moduleName,
})
}
>
{p.name}
</li>

View File

@@ -3,6 +3,7 @@ import { ReactNode, useState } from "react";
import { CourseContext, DraggableItem } from "./courseContext";
import { LocalQuiz } from "@/models/local/quiz/localQuiz";
import { dateToMarkdownString } from "@/models/local/timeUtils";
import { useUpdateQuizMutation } from "@/hooks/localCourse/quizHooks";
export default function CourseContextProvider({
localCourseName,
@@ -11,6 +12,7 @@ export default function CourseContextProvider({
children: ReactNode;
localCourseName: string;
}) {
const updateQuizMutation = useUpdateQuizMutation(localCourseName);
const [itemBeingDragged, setItemBeingDragged] = useState<
DraggableItem | undefined
>();
@@ -58,10 +60,17 @@ export default function CourseContextProvider({
setItemBeingDragged(undefined);
},
itemDrop: (day) => {
console.log("dropping");
if (itemBeingDragged && day) {
if (itemBeingDragged.type === "quiz") {
updateQuiz(day);
const quiz: LocalQuiz = {
...(itemBeingDragged.item as LocalQuiz),
dueAt: dateToMarkdownString(day),
};
updateQuizMutation.mutate({
quiz: quiz,
quizName: quiz.name,
moduleName: itemBeingDragged.sourceModuleName,
});
}
}
setItemBeingDragged(undefined);

View File

@@ -4,6 +4,7 @@ import { createContext, useContext } from "react";
export interface DraggableItem {
item: IModuleItem;
sourceModuleName: string;
type: "quiz" | "assignment" | "page";
}

View File

@@ -5,6 +5,7 @@ import {
QueryClientProvider,
} from "@tanstack/react-query";
import { ReactNode } from "react";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
function makeQueryClient() {
return new QueryClient({
@@ -39,10 +40,13 @@ export default function Providers({ children }: { children: ReactNode }) {
// have a suspense boundary between this and the code that may
// suspend because React will throw away the client on the initial
// render if it suspends and there is no boundary
const queryClient = getQueryClient();
return (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
<QueryClientProvider client={queryClient}>
<ReactQueryDevtools initialIsOpen={false} />
{children}
</QueryClientProvider>
);
}