mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
updates
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user