mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
am updateing course
This commit is contained in:
@@ -4,12 +4,17 @@ import { getDateFromStringOrThrow } from "@/models/local/timeUtils";
|
||||
import { useCourseContext } from "../context/courseContext";
|
||||
|
||||
export default function Day({ day, month }: { day: Date; month: number }) {
|
||||
const context = useCourseContext();
|
||||
const {
|
||||
localCourse: { modules },
|
||||
startItemDrag,
|
||||
endItemDrag,
|
||||
itemDrop,
|
||||
} = useCourseContext();
|
||||
|
||||
const isInSameMonth = day.getMonth() + 1 != month;
|
||||
const backgroundClass = isInSameMonth ? "" : "bg-slate-900";
|
||||
|
||||
const todaysAssignments = context.localCourse.modules
|
||||
const todaysAssignments = modules
|
||||
.flatMap((m) => m.assignments)
|
||||
.filter((a) => {
|
||||
const dueDate = getDateFromStringOrThrow(
|
||||
@@ -22,7 +27,7 @@ export default function Day({ day, month }: { day: Date; month: number }) {
|
||||
dueDate.getDate() === day.getDate()
|
||||
);
|
||||
});
|
||||
const todaysQuizzes = context.localCourse.modules
|
||||
const todaysQuizzes = modules
|
||||
.flatMap((m) => m.quizzes)
|
||||
.filter((q) => {
|
||||
const dueDate = getDateFromStringOrThrow(
|
||||
@@ -35,7 +40,7 @@ export default function Day({ day, month }: { day: Date; month: number }) {
|
||||
dueDate.getDate() === day.getDate()
|
||||
);
|
||||
});
|
||||
const todaysPages = context.localCourse.modules
|
||||
const todaysPages = modules
|
||||
.flatMap((m) => m.pages)
|
||||
.filter((p) => {
|
||||
const dueDate = getDateFromStringOrThrow(
|
||||
@@ -53,17 +58,34 @@ export default function Day({ day, month }: { day: Date; month: number }) {
|
||||
className={
|
||||
"border border-slate-600 rounded-lg p-2 pb-4 m-1 " + backgroundClass
|
||||
}
|
||||
onDrop={() => itemDrop(day)}
|
||||
onDragOver={(e) => e.preventDefault()}
|
||||
>
|
||||
{day.getDate()}
|
||||
<ul className="list-disc ms-4">
|
||||
{todaysAssignments.map((a) => (
|
||||
<li key={a.name} >{a.name}</li>
|
||||
<li key={a.name}>{a.name}</li>
|
||||
))}
|
||||
{todaysQuizzes.map((q) => (
|
||||
<li key={q.name}>{q.name}</li>
|
||||
<li
|
||||
key={q.name}
|
||||
role="button"
|
||||
draggable="true"
|
||||
onDragStart={() => startItemDrag({ type: "quiz", item: q })}
|
||||
onDragEnd={endItemDrag}
|
||||
>
|
||||
{q.name}
|
||||
</li>
|
||||
))}
|
||||
{todaysPages.map((p) => (
|
||||
<li key={p.name}>{p.name}</li>
|
||||
<li
|
||||
key={p.name}
|
||||
role="button"
|
||||
draggable="true"
|
||||
// onDragStart={() => startItemDrag({ type: "page", item: p })}
|
||||
>
|
||||
{p.name}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
"use client";
|
||||
import { ReactNode, useState } from "react";
|
||||
import { CourseContext, DraggableItem } from "./courseContext";
|
||||
import { useLocalCourseDetailsQuery } from "@/hooks/localCoursesHooks";
|
||||
import {
|
||||
useLocalCourseDetailsQuery,
|
||||
useUpdateCourseMutation,
|
||||
} from "@/hooks/localCoursesHooks";
|
||||
import { LocalQuiz } from "@/models/local/quiz/localQuiz";
|
||||
import { LocalCourse } from "@/models/local/localCourse";
|
||||
import { dateToMarkdownString } from "@/models/local/timeUtils";
|
||||
|
||||
export default function CourseContextProvider({
|
||||
localCourseName,
|
||||
@@ -11,15 +17,59 @@ export default function CourseContextProvider({
|
||||
localCourseName: string;
|
||||
}) {
|
||||
const { data: course } = useLocalCourseDetailsQuery(localCourseName);
|
||||
const updateCourseMutation = useUpdateCourseMutation(course.settings.name);
|
||||
const [itemBeingDragged, setItemBeingDragged] = useState<
|
||||
DraggableItem | undefined
|
||||
>();
|
||||
|
||||
return (
|
||||
<CourseContext.Provider
|
||||
value={{
|
||||
localCourse: course,
|
||||
startModuleDrag: (d) => setItemBeingDragged(d),
|
||||
stopModuleDrag: (day) => setItemBeingDragged(undefined),
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
setItemBeingDragged(undefined);
|
||||
},
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -10,8 +10,9 @@ export interface DraggableItem {
|
||||
|
||||
export interface CourseContextInterface {
|
||||
localCourse: LocalCourse;
|
||||
startModuleDrag: (dragging: DraggableItem) => void;
|
||||
stopModuleDrag: (droppedOnDay?: Date) => void;
|
||||
startItemDrag: (dragging: DraggableItem) => void;
|
||||
endItemDrag: () => void;
|
||||
itemDrop: (droppedOnDay?: Date) => void;
|
||||
}
|
||||
|
||||
const defaultValue: CourseContextInterface = {
|
||||
@@ -29,10 +30,9 @@ const defaultValue: CourseContextInterface = {
|
||||
},
|
||||
},
|
||||
},
|
||||
startModuleDrag: () => { },
|
||||
stopModuleDrag: function (droppedOnDay?: Date): void {
|
||||
throw new Error("Function not implemented.");
|
||||
}
|
||||
startItemDrag: () => {},
|
||||
endItemDrag: () => {},
|
||||
itemDrop: () => {},
|
||||
};
|
||||
|
||||
export const CourseContext =
|
||||
|
||||
Reference in New Issue
Block a user