This commit is contained in:
2024-08-28 14:22:56 -06:00
parent 1051c4fb6e
commit 10afc745a9
5 changed files with 60 additions and 48 deletions

View File

@@ -22,50 +22,53 @@ export default function CourseContextProvider({
DraggableItem | undefined
>();
const updateQuiz = (day: Date) => {
if (!itemBeingDragged) return;
const updatedQuiz: LocalQuiz = {
...(itemBeingDragged.item as LocalQuiz),
dueAt: dateToMarkdownString(day),
};
const localModule = course.modules.find((m) =>
m.quizzes.map((q) => q.name).includes(updatedQuiz.name)
);
if (!localModule)
console.log("could not find module for quiz ", updatedQuiz);
const updatedCourse: LocalCourse = {
...course,
modules: course.modules.map((m) =>
m.name !== localModule?.name
? m
: {
...m,
quizzes: m.quizzes.map((q) =>
q.name === updatedQuiz.name ? updatedQuiz : q
),
}
),
};
updateCourseMutation.mutate({
updatedCourse,
previousCourse: course,
});
};
return (
<CourseContext.Provider
value={{
localCourse: course,
startItemDrag: (d) => {
console.log("starting drag");
setItemBeingDragged(d);
},
endItemDrag: () => {
console.log("stopping drag");
setItemBeingDragged(undefined);
},
itemDrop: (day) => {
console.log("dropping");
if (itemBeingDragged && day) {
if (itemBeingDragged.type === "quiz") {
const updatedQuiz: LocalQuiz = {
...(itemBeingDragged.item as LocalQuiz),
dueAt: dateToMarkdownString(day),
};
const localModule = course.modules.find((m) =>
m.quizzes.map((q) => q.name).includes(updatedQuiz.name)
);
if (!localModule)
console.log("could not find module for quiz ", updatedQuiz);
const updatedCourse: LocalCourse = {
...course,
modules: course.modules.map((m) =>
m.name !== localModule?.name
? m
: {
...m,
quizzes: m.quizzes.map((q) =>
q.name === updatedQuiz.name ? updatedQuiz : q
),
}
),
};
updateCourseMutation.mutate({
updatedCourse,
previousCourse: course,
});
updateQuiz(day);
}
}
setItemBeingDragged(undefined);