mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
running smooth again
This commit is contained in:
@@ -2,26 +2,32 @@
|
|||||||
import { useModuleNamesQuery } from "@/hooks/localCourse/localCoursesHooks";
|
import { useModuleNamesQuery } from "@/hooks/localCourse/localCoursesHooks";
|
||||||
import DayItemsInModule from "./DayItemsInModule";
|
import DayItemsInModule from "./DayItemsInModule";
|
||||||
import { getDateFromStringOrThrow } from "@/models/local/timeUtils";
|
import { getDateFromStringOrThrow } from "@/models/local/timeUtils";
|
||||||
import { useDraggingContext } from "../context/DraggingContext";
|
import { useDraggingContext } from "../context/draggingContext";
|
||||||
|
|
||||||
export default function Day({ day, month }: { day: string; month: number }) {
|
export default function Day({ day, month }: { day: string; month: number }) {
|
||||||
const { data: moduleNames } = useModuleNamesQuery();
|
const { data: moduleNames } = useModuleNamesQuery();
|
||||||
|
|
||||||
const dayAsDate = getDateFromStringOrThrow(day, "calculating same month in day")
|
const dayAsDate = getDateFromStringOrThrow(
|
||||||
const isInSameMonth =
|
day,
|
||||||
dayAsDate.getMonth() + 1 !=
|
"calculating same month in day"
|
||||||
month;
|
);
|
||||||
|
const isInSameMonth = dayAsDate.getMonth() + 1 != month;
|
||||||
const backgroundClass = isInSameMonth ? "" : "bg-slate-900";
|
const backgroundClass = isInSameMonth ? "" : "bg-slate-900";
|
||||||
|
const { itemDrop } = useDraggingContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={
|
className={
|
||||||
"border border-slate-600 rounded-lg p-2 pb-4 m-1 " + backgroundClass
|
"border border-slate-600 rounded-lg p-2 pb-4 m-1 " + backgroundClass
|
||||||
}
|
}
|
||||||
|
onDrop={(e) => {
|
||||||
|
itemDrop(e, day);
|
||||||
|
}}
|
||||||
|
onDragOver={(e) => e.preventDefault()}
|
||||||
>
|
>
|
||||||
{dayAsDate.getDate()}
|
{dayAsDate.getDate()}
|
||||||
{moduleNames.map((moduleName) => (
|
{moduleNames.map((moduleName) => (
|
||||||
<ModuleInDay
|
<DayItemsInModule
|
||||||
key={"" + day + month + moduleName}
|
key={"" + day + month + moduleName}
|
||||||
moduleName={moduleName}
|
moduleName={moduleName}
|
||||||
day={day}
|
day={day}
|
||||||
@@ -30,12 +36,3 @@ export default function Day({ day, month }: { day: string; month: number }) {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ModuleInDay({ moduleName, day }: { moduleName: string; day: string }) {
|
|
||||||
const { itemDrop } = useDraggingContext();
|
|
||||||
return (
|
|
||||||
<div onDrop={() => itemDrop(day)} onDragOver={(e) => e.preventDefault()}>
|
|
||||||
<DayItemsInModule day={day} moduleName={moduleName} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import React, { useCallback, useMemo } from "react";
|
import React, { useMemo } from "react";
|
||||||
import { useCourseContext } from "../context/courseContext";
|
import { useCourseContext } from "../context/courseContext";
|
||||||
import { useModuleDataQuery } from "@/hooks/localCourse/localCoursesHooks";
|
import { useModuleDataQuery } from "@/hooks/localCourse/localCoursesHooks";
|
||||||
import { getDateFromStringOrThrow } from "@/models/local/timeUtils";
|
import { getDateFromStringOrThrow } from "@/models/local/timeUtils";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { LocalAssignment } from "@/models/local/assignmnet/localAssignment";
|
import { usePageNamesQuery, usePagesQueries } from "@/hooks/localCourse/pageHooks";
|
||||||
import { LocalQuiz } from "@/models/local/quiz/localQuiz";
|
import { useQuizNamesQuery, useQuizzesQueries } from "@/hooks/localCourse/quizHooks";
|
||||||
import { LocalCoursePage } from "@/models/local/page/localCoursePage";
|
import { useAssignmentNamesQuery, useAssignmentsQueries } from "@/hooks/localCourse/assignmentHooks";
|
||||||
import { useDraggingContext } from "../context/DraggingContext";
|
|
||||||
|
|
||||||
export default function DayItemsInModule({
|
export default function DayItemsInModule({
|
||||||
day,
|
day,
|
||||||
@@ -16,10 +15,121 @@ export default function DayItemsInModule({
|
|||||||
day: string;
|
day: string;
|
||||||
moduleName: string;
|
moduleName: string;
|
||||||
}) {
|
}) {
|
||||||
|
return (
|
||||||
|
<ul className="list-disc ms-4">
|
||||||
|
<Assignments moduleName={moduleName} day={day} />
|
||||||
|
<Quizzes moduleName={moduleName} day={day} />
|
||||||
|
<Pages moduleName={moduleName} day={day} />
|
||||||
|
</ul>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Pages({ moduleName, day }: { moduleName: string; day: string }) {
|
||||||
|
const { data: pageNames } = usePageNamesQuery(moduleName);
|
||||||
|
const { data: pages } = usePagesQueries(moduleName, pageNames);
|
||||||
|
const todaysPages = useMemo(
|
||||||
|
() =>
|
||||||
|
pages.filter((p) => {
|
||||||
|
const dueDate = getDateFromStringOrThrow(
|
||||||
|
p.dueAt,
|
||||||
|
"due at for page in day"
|
||||||
|
);
|
||||||
|
const dayAsDate = getDateFromStringOrThrow(
|
||||||
|
day,
|
||||||
|
"in pages in DayItemsInModule"
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
dueDate.getFullYear() === dayAsDate.getFullYear() &&
|
||||||
|
dueDate.getMonth() === dayAsDate.getMonth() &&
|
||||||
|
dueDate.getDate() === dayAsDate.getDate()
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
[day, pages]
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{todaysPages.map((p) => (
|
||||||
|
<li
|
||||||
|
key={p.name}
|
||||||
|
role="button"
|
||||||
|
draggable="true"
|
||||||
|
onDragStart={(e) => {
|
||||||
|
e.dataTransfer.setData(
|
||||||
|
"draggableItem",
|
||||||
|
JSON.stringify({
|
||||||
|
type: "page",
|
||||||
|
item: p,
|
||||||
|
sourceModuleName: moduleName,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{p.name}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Quizzes({ moduleName, day }: { moduleName: string; day: string }) {
|
||||||
|
const { data: quizNames } = useQuizNamesQuery(moduleName);
|
||||||
|
const { data: quizzes } = useQuizzesQueries(moduleName, quizNames);
|
||||||
|
|
||||||
const { courseName } = useCourseContext();
|
const { courseName } = useCourseContext();
|
||||||
const { endItemDrag, startItemDrag } = useDraggingContext();
|
const todaysQuizzes = useMemo(
|
||||||
const { assignments, quizzes, pages } = useModuleDataQuery(
|
() =>
|
||||||
moduleName
|
quizzes.filter((q) => {
|
||||||
|
const dueDate = getDateFromStringOrThrow(
|
||||||
|
q.dueAt,
|
||||||
|
"due at for quiz in day"
|
||||||
|
);
|
||||||
|
const dayAsDate = getDateFromStringOrThrow(
|
||||||
|
day,
|
||||||
|
"in quizzes in DayItemsInModule"
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
dueDate.getFullYear() === dayAsDate.getFullYear() &&
|
||||||
|
dueDate.getMonth() === dayAsDate.getMonth() &&
|
||||||
|
dueDate.getDate() === dayAsDate.getDate()
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
[day, quizzes]
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{todaysQuizzes.map((q) => (
|
||||||
|
<li
|
||||||
|
key={q.name}
|
||||||
|
role="button"
|
||||||
|
draggable="true"
|
||||||
|
onDragStart={(e) => {
|
||||||
|
e.dataTransfer.setData(
|
||||||
|
"draggableItem",
|
||||||
|
JSON.stringify({
|
||||||
|
type: "quiz",
|
||||||
|
item: q,
|
||||||
|
sourceModuleName: moduleName,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
onDragEnd={(e) => e.preventDefault()}
|
||||||
|
>
|
||||||
|
<Link
|
||||||
|
href={`/course/${courseName}/modules/${moduleName}/quiz/${q.name}`}
|
||||||
|
>
|
||||||
|
{q.name}
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Assignments({ moduleName, day }: { moduleName: string; day: string }) {
|
||||||
|
const { data: assignmentNames } = useAssignmentNamesQuery(moduleName);
|
||||||
|
const { data: assignments } = useAssignmentsQueries(
|
||||||
|
moduleName,
|
||||||
|
assignmentNames
|
||||||
);
|
);
|
||||||
const todaysAssignments = useMemo(
|
const todaysAssignments = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -40,112 +150,27 @@ export default function DayItemsInModule({
|
|||||||
}),
|
}),
|
||||||
[assignments, day]
|
[assignments, day]
|
||||||
);
|
);
|
||||||
const todaysQuizzes = useMemo(
|
|
||||||
() =>
|
|
||||||
quizzes.filter((q) => {
|
|
||||||
const dueDate = getDateFromStringOrThrow(
|
|
||||||
q.dueAt,
|
|
||||||
"due at for quiz in day"
|
|
||||||
);
|
|
||||||
const dayAsDate = getDateFromStringOrThrow(
|
|
||||||
day,
|
|
||||||
"in quizzes in DayItemsInModule"
|
|
||||||
);
|
|
||||||
return (
|
|
||||||
dueDate.getFullYear() === dayAsDate.getFullYear() &&
|
|
||||||
dueDate.getMonth() === dayAsDate.getMonth() &&
|
|
||||||
dueDate.getDate() === dayAsDate.getDate()
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
[day, quizzes]
|
|
||||||
);
|
|
||||||
const todaysPages = useMemo(
|
|
||||||
() =>
|
|
||||||
pages.filter((p) => {
|
|
||||||
const dueDate = getDateFromStringOrThrow(
|
|
||||||
p.dueAt,
|
|
||||||
"due at for page in day"
|
|
||||||
);
|
|
||||||
const dayAsDate = getDateFromStringOrThrow(
|
|
||||||
day,
|
|
||||||
"in pages in DayItemsInModule"
|
|
||||||
);
|
|
||||||
return (
|
|
||||||
dueDate.getFullYear() === dayAsDate.getFullYear() &&
|
|
||||||
dueDate.getMonth() === dayAsDate.getMonth() &&
|
|
||||||
dueDate.getDate() === dayAsDate.getDate()
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
[day, pages]
|
|
||||||
);
|
|
||||||
const startAssignmentDrag = useCallback(
|
|
||||||
(a: LocalAssignment) => () =>
|
|
||||||
startItemDrag({
|
|
||||||
type: "assignment",
|
|
||||||
item: a,
|
|
||||||
sourceModuleName: moduleName,
|
|
||||||
}),
|
|
||||||
[moduleName, startItemDrag]
|
|
||||||
);
|
|
||||||
const startQuizDrag = useCallback(
|
|
||||||
(q: LocalQuiz) => () =>
|
|
||||||
startItemDrag({
|
|
||||||
type: "quiz",
|
|
||||||
item: q,
|
|
||||||
sourceModuleName: moduleName,
|
|
||||||
}),
|
|
||||||
[moduleName, startItemDrag]
|
|
||||||
);
|
|
||||||
const starPageDrag = useCallback(
|
|
||||||
(p: LocalCoursePage) => () =>
|
|
||||||
startItemDrag({
|
|
||||||
type: "page",
|
|
||||||
item: p,
|
|
||||||
sourceModuleName: moduleName,
|
|
||||||
}),
|
|
||||||
[moduleName, startItemDrag]
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ul className="list-disc ms-4">
|
|
||||||
{todaysAssignments.map((a) => (
|
{todaysAssignments.map((a) => (
|
||||||
<li
|
<li
|
||||||
key={a.name}
|
key={a.name}
|
||||||
role="button"
|
role="button"
|
||||||
draggable="true"
|
draggable="true"
|
||||||
onDragStart={startAssignmentDrag(a)}
|
onDragStart={(e) => {
|
||||||
onDragEnd={endItemDrag}
|
e.dataTransfer.setData(
|
||||||
|
"draggableItem",
|
||||||
|
JSON.stringify({
|
||||||
|
type: "assignment",
|
||||||
|
item: a,
|
||||||
|
sourceModuleName: moduleName,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{a.name}
|
{a.name}
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
{todaysQuizzes.map((q) => (
|
|
||||||
<li
|
|
||||||
key={q.name}
|
|
||||||
role="button"
|
|
||||||
draggable="true"
|
|
||||||
onDragStart={startQuizDrag(q)}
|
|
||||||
onDragEnd={endItemDrag}
|
|
||||||
>
|
|
||||||
<Link
|
|
||||||
href={`/course/${courseName}/modules/${moduleName}/quiz/${q.name}`}
|
|
||||||
>
|
|
||||||
{q.name}
|
|
||||||
</Link>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
{todaysPages.map((p) => (
|
|
||||||
<li
|
|
||||||
key={p.name}
|
|
||||||
role="button"
|
|
||||||
draggable="true"
|
|
||||||
onDragStart={starPageDrag(p)}
|
|
||||||
onDragEnd={endItemDrag}
|
|
||||||
>
|
|
||||||
{p.name}
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,14 +34,14 @@ function createCalendarMonth(year: number, month: number): CalendarMonthModel {
|
|||||||
Array.from({ length: 7 }).map((_, dayIndex) => {
|
Array.from({ length: 7 }).map((_, dayIndex) => {
|
||||||
if (weekIndex === 0 && dayIndex < firstDayOfMonth) {
|
if (weekIndex === 0 && dayIndex < firstDayOfMonth) {
|
||||||
return dateToMarkdownString(
|
return dateToMarkdownString(
|
||||||
new Date(year, month - 1, dayIndex - firstDayOfMonth + 1)
|
new Date(year, month - 1, dayIndex - firstDayOfMonth + 1, 12, 0, 0)
|
||||||
);
|
);
|
||||||
} else if (currentDay <= daysInMonth) {
|
} else if (currentDay <= daysInMonth) {
|
||||||
return dateToMarkdownString(new Date(year, month - 1, currentDay++));
|
return dateToMarkdownString(new Date(year, month - 1, currentDay++, 12, 0, 0));
|
||||||
} else {
|
} else {
|
||||||
currentDay++;
|
currentDay++;
|
||||||
return dateToMarkdownString(
|
return dateToMarkdownString(
|
||||||
new Date(year, month, currentDay - daysInMonth - 1)
|
new Date(year, month, currentDay - daysInMonth - 1, 12, 0, 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,14 +1,6 @@
|
|||||||
"use client";
|
"use client"
|
||||||
import { ReactNode, useCallback, useState } from "react";
|
import { ReactNode } from "react";
|
||||||
import { CourseContext } from "./courseContext";
|
import { CourseContext } from "./courseContext";
|
||||||
import { DraggableItem } from "./DraggingContext";
|
|
||||||
import { LocalQuiz } from "@/models/local/quiz/localQuiz";
|
|
||||||
import {
|
|
||||||
dateToMarkdownString,
|
|
||||||
getDateFromStringOrThrow,
|
|
||||||
} from "@/models/local/timeUtils";
|
|
||||||
import { useUpdateQuizMutation } from "@/hooks/localCourse/quizHooks";
|
|
||||||
import { useLocalCourseSettingsQuery } from "@/hooks/localCourse/localCoursesHooks";
|
|
||||||
|
|
||||||
export default function CourseContextProvider({
|
export default function CourseContextProvider({
|
||||||
localCourseName,
|
localCourseName,
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { ReactNode, useCallback, useState } from "react";
|
import { ReactNode, useCallback, DragEvent } from "react";
|
||||||
import { DraggableItem, DraggingContext } from "./DraggingContext";
|
import { DraggingContext } from "./draggingContext";
|
||||||
import { LocalQuiz } from "@/models/local/quiz/localQuiz";
|
|
||||||
import {
|
|
||||||
dateToMarkdownString,
|
|
||||||
getDateFromStringOrThrow,
|
|
||||||
} from "@/models/local/timeUtils";
|
|
||||||
import { useUpdateQuizMutation } from "@/hooks/localCourse/quizHooks";
|
import { useUpdateQuizMutation } from "@/hooks/localCourse/quizHooks";
|
||||||
import { useLocalCourseSettingsQuery } from "@/hooks/localCourse/localCoursesHooks";
|
import { useLocalCourseSettingsQuery } from "@/hooks/localCourse/localCoursesHooks";
|
||||||
|
|
||||||
@@ -17,62 +12,56 @@ export default function DraggingContextProvider({
|
|||||||
}) {
|
}) {
|
||||||
const updateQuizMutation = useUpdateQuizMutation();
|
const updateQuizMutation = useUpdateQuizMutation();
|
||||||
const { data: settings } = useLocalCourseSettingsQuery();
|
const { data: settings } = useLocalCourseSettingsQuery();
|
||||||
const [itemBeingDragged, setItemBeingDragged] = useState<
|
|
||||||
DraggableItem | undefined
|
|
||||||
>();
|
|
||||||
|
|
||||||
const itemDrop = useCallback(
|
const itemDrop = useCallback(
|
||||||
(day: string | undefined) => {
|
(e: DragEvent<HTMLDivElement>, day: string | undefined) => {
|
||||||
if (itemBeingDragged && day) {
|
// const itemBeingDragged = JSON.parse(
|
||||||
const dayAsDate = getDateFromStringOrThrow(day, "in drop callback");
|
// e.dataTransfer.getData("draggableItem")
|
||||||
dayAsDate.setHours(settings.defaultDueTime.hour);
|
// );
|
||||||
dayAsDate.setHours(settings.defaultDueTime.minute);
|
|
||||||
if (itemBeingDragged.type === "quiz") {
|
|
||||||
console.log("dropping quiz");
|
|
||||||
const previousQuiz = itemBeingDragged.item as LocalQuiz;
|
|
||||||
|
|
||||||
const quiz: LocalQuiz = {
|
// if (itemBeingDragged && day) {
|
||||||
...previousQuiz,
|
// const dayAsDate = getDateFromStringOrThrow(day, "in drop callback");
|
||||||
dueAt: dateToMarkdownString(dayAsDate),
|
// dayAsDate.setHours(settings.defaultDueTime.hour);
|
||||||
lockAt:
|
// dayAsDate.setMinutes(settings.defaultDueTime.minute);
|
||||||
previousQuiz.lockAt &&
|
// dayAsDate.setSeconds(0);
|
||||||
(getDateFromStringOrThrow(previousQuiz.lockAt, "lockAt date") >
|
|
||||||
dayAsDate
|
// console.log("dropped on day", dayAsDate, day);
|
||||||
? previousQuiz.lockAt
|
// if (itemBeingDragged.type === "quiz") {
|
||||||
: dateToMarkdownString(dayAsDate)),
|
// console.log("dropping quiz");
|
||||||
};
|
// const previousQuiz = itemBeingDragged.item as LocalQuiz;
|
||||||
updateQuizMutation.mutate({
|
|
||||||
quiz: quiz,
|
// const quiz: LocalQuiz = {
|
||||||
quizName: quiz.name,
|
// ...previousQuiz,
|
||||||
moduleName: itemBeingDragged.sourceModuleName,
|
// dueAt: dateToMarkdownString(dayAsDate),
|
||||||
});
|
// lockAt:
|
||||||
} else if (itemBeingDragged.type === "assignment") {
|
// previousQuiz.lockAt &&
|
||||||
console.log("dropped assignment");
|
// (getDateFromStringOrThrow(previousQuiz.lockAt, "lockAt date") >
|
||||||
} else if (itemBeingDragged.type === "page") {
|
// dayAsDate
|
||||||
console.log("dropped page");
|
// ? previousQuiz.lockAt
|
||||||
}
|
// : dateToMarkdownString(dayAsDate)),
|
||||||
}
|
// };
|
||||||
setItemBeingDragged(undefined);
|
// updateQuizMutation.mutate({
|
||||||
|
// quiz: quiz,
|
||||||
|
// quizName: quiz.name,
|
||||||
|
// moduleName: itemBeingDragged.sourceModuleName,
|
||||||
|
// });
|
||||||
|
// } else if (itemBeingDragged.type === "assignment") {
|
||||||
|
// console.log("dropped assignment");
|
||||||
|
// } else if (itemBeingDragged.type === "page") {
|
||||||
|
// console.log("dropped page");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
itemBeingDragged,
|
// settings.defaultDueTime.hour,
|
||||||
settings.defaultDueTime.hour,
|
// settings.defaultDueTime.minute,
|
||||||
settings.defaultDueTime.minute,
|
// updateQuizMutation,
|
||||||
updateQuizMutation,
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
const startItemDrag = useCallback((d: DraggableItem) => {
|
|
||||||
setItemBeingDragged(d);
|
|
||||||
}, []);
|
|
||||||
const endItemDrag = useCallback(() => {
|
|
||||||
setItemBeingDragged(undefined);
|
|
||||||
}, []);
|
|
||||||
return (
|
return (
|
||||||
<DraggingContext.Provider
|
<DraggingContext.Provider
|
||||||
value={{
|
value={{
|
||||||
startItemDrag: startItemDrag,
|
|
||||||
endItemDrag: endItemDrag,
|
|
||||||
itemDrop,
|
itemDrop,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { IModuleItem } from "@/models/local/IModuleItem";
|
import { IModuleItem } from "@/models/local/IModuleItem";
|
||||||
import { createContext, useContext } from "react";
|
import { createContext, useContext, DragEvent } from "react";
|
||||||
|
|
||||||
export interface DraggableItem {
|
export interface DraggableItem {
|
||||||
item: IModuleItem;
|
item: IModuleItem;
|
||||||
@@ -9,13 +9,9 @@ export interface DraggableItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DraggingContextInterface {
|
export interface DraggingContextInterface {
|
||||||
startItemDrag: (dragging: DraggableItem) => void;
|
itemDrop: (e: DragEvent<HTMLDivElement>,droppedOnDay?: string) => void;
|
||||||
endItemDrag: () => void;
|
|
||||||
itemDrop: (droppedOnDay?: string) => void;
|
|
||||||
}
|
}
|
||||||
const defaultDraggingValue: DraggingContextInterface = {
|
const defaultDraggingValue: DraggingContextInterface = {
|
||||||
startItemDrag: () => { },
|
|
||||||
endItemDrag: () => { },
|
|
||||||
itemDrop: () => { },
|
itemDrop: () => { },
|
||||||
};
|
};
|
||||||
export const DraggingContext = createContext<DraggingContextInterface>(defaultDraggingValue);
|
export const DraggingContext = createContext<DraggingContextInterface>(defaultDraggingValue);
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
dehydrate,
|
dehydrate,
|
||||||
HydrationBoundary,
|
HydrationBoundary,
|
||||||
QueryClient,
|
|
||||||
} from "@tanstack/react-query";
|
} from "@tanstack/react-query";
|
||||||
import { hydrateCourse } from "@/hooks/hookHydration";
|
|
||||||
import { getQueryClient } from "@/app/providersQueryClientUtils";
|
import { getQueryClient } from "@/app/providersQueryClientUtils";
|
||||||
|
import { hydrateCourse } from "@/hooks/hookHydration";
|
||||||
|
|
||||||
export default async function CourseLayout({
|
export default async function CourseLayout({
|
||||||
children,
|
children,
|
||||||
|
|||||||
@@ -1,17 +1,25 @@
|
|||||||
|
import { useAssignmentNamesQuery, useAssignmentsQueries } from "@/hooks/localCourse/assignmentHooks";
|
||||||
|
import { usePageNamesQuery, usePagesQueries } from "@/hooks/localCourse/pageHooks";
|
||||||
|
import { useQuizNamesQuery, useQuizzesQueries } from "@/hooks/localCourse/quizHooks";
|
||||||
import { IModuleItem } from "@/models/local/IModuleItem";
|
import { IModuleItem } from "@/models/local/IModuleItem";
|
||||||
import { getDateFromStringOrThrow } from "@/models/local/timeUtils";
|
import { getDateFromStringOrThrow } from "@/models/local/timeUtils";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useCourseContext } from "../context/courseContext";
|
|
||||||
import { useModuleDataQuery } from "@/hooks/localCourse/localCoursesHooks";
|
|
||||||
|
|
||||||
export default function ExpandableModule({
|
export default function ExpandableModule({
|
||||||
moduleName,
|
moduleName,
|
||||||
}: {
|
}: {
|
||||||
moduleName: string;
|
moduleName: string;
|
||||||
}) {
|
}) {
|
||||||
const { assignments, quizzes, pages } = useModuleDataQuery(
|
const { data: assignmentNames } = useAssignmentNamesQuery(moduleName);
|
||||||
moduleName
|
const { data: quizNames } = useQuizNamesQuery(moduleName);
|
||||||
|
const { data: pageNames } = usePageNamesQuery(moduleName);
|
||||||
|
|
||||||
|
const { data: assignments } = useAssignmentsQueries(
|
||||||
|
moduleName,
|
||||||
|
assignmentNames
|
||||||
);
|
);
|
||||||
|
const { data: quizzes } = useQuizzesQueries(moduleName, quizNames);
|
||||||
|
const { data: pages } = usePagesQueries(moduleName, pageNames);
|
||||||
|
|
||||||
const [expanded, setExpanded] = useState(false);
|
const [expanded, setExpanded] = useState(false);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
"use client"
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { localCourseKeys } from "./localCourseKeys";
|
import { localCourseKeys } from "./localCourseKeys";
|
||||||
import { LocalAssignment } from "@/models/local/assignmnet/localAssignment";
|
import { LocalAssignment } from "@/models/local/assignment/localAssignment";
|
||||||
import { useSuspenseQuery, useSuspenseQueries } from "@tanstack/react-query";
|
import { useSuspenseQuery, useSuspenseQueries } from "@tanstack/react-query";
|
||||||
import { useCourseContext } from "@/app/course/[courseName]/context/courseContext";
|
import { useCourseContext } from "@/app/course/[courseName]/context/courseContext";
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
"use client";
|
||||||
import { LocalCourseSettings } from "@/models/local/localCourse";
|
import { LocalCourseSettings } from "@/models/local/localCourse";
|
||||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
@@ -45,32 +46,35 @@ export const useModuleNamesQuery = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useModuleDataQuery = (moduleName: string) => {
|
// dangerous? really slowed down page...
|
||||||
const { data: assignmentNames } = useAssignmentNamesQuery(
|
// maybe it only slowed down with react query devtools...
|
||||||
moduleName
|
// export const useModuleDataQuery = (moduleName: string) => {
|
||||||
);
|
// console.log("running");
|
||||||
const { data: quizNames } = useQuizNamesQuery(moduleName);
|
// const { data: assignmentNames } = useAssignmentNamesQuery(moduleName);
|
||||||
const { data: pageNames } = usePageNamesQuery(moduleName);
|
// const { data: quizNames } = useQuizNamesQuery(moduleName);
|
||||||
|
// const { data: pageNames } = usePageNamesQuery(moduleName);
|
||||||
|
|
||||||
const { data: assignments } = useAssignmentsQueries(
|
// const { data: assignments } = useAssignmentsQueries(
|
||||||
moduleName,
|
// moduleName,
|
||||||
assignmentNames
|
// assignmentNames
|
||||||
);
|
// );
|
||||||
const { data: quizzes } = useQuizzesQueries(
|
// const { data: quizzes } = useQuizzesQueries(moduleName, quizNames);
|
||||||
moduleName,
|
// const { data: pages } = usePagesQueries(moduleName, pageNames);
|
||||||
quizNames
|
|
||||||
);
|
|
||||||
const { data: pages } = usePagesQueries(moduleName, pageNames);
|
|
||||||
|
|
||||||
return useMemo(
|
// return {
|
||||||
() => ({
|
// assignments,
|
||||||
assignments,
|
// quizzes,
|
||||||
quizzes,
|
// pages,
|
||||||
pages,
|
// };
|
||||||
}),
|
// // return useMemo(
|
||||||
[assignments, pages, quizzes]
|
// // () => ({
|
||||||
);
|
// // assignments,
|
||||||
};
|
// // quizzes,
|
||||||
|
// // pages,
|
||||||
|
// // }),
|
||||||
|
// // [assignments, pages, quizzes]
|
||||||
|
// // );
|
||||||
|
// };
|
||||||
|
|
||||||
// export const useUpdateCourseMutation = (courseName: string) => {
|
// export const useUpdateCourseMutation = (courseName: string) => {
|
||||||
// const queryClient = useQueryClient();
|
// const queryClient = useQueryClient();
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
"use client"
|
||||||
import { LocalCoursePage } from "@/models/local/page/localCoursePage";
|
import { LocalCoursePage } from "@/models/local/page/localCoursePage";
|
||||||
import { useSuspenseQueries, useSuspenseQuery } from "@tanstack/react-query";
|
import { useSuspenseQueries, useSuspenseQuery } from "@tanstack/react-query";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
@@ -54,7 +55,6 @@ function getPageQueryConfig(
|
|||||||
"/pages/" +
|
"/pages/" +
|
||||||
encodeURIComponent(pageName);
|
encodeURIComponent(pageName);
|
||||||
try {
|
try {
|
||||||
console.log("making a request to get a page");
|
|
||||||
const response = await axios.get(url);
|
const response = await axios.get(url);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
"use client"
|
||||||
import { LocalQuiz } from "@/models/local/quiz/localQuiz";
|
import { LocalQuiz } from "@/models/local/quiz/localQuiz";
|
||||||
import {
|
import {
|
||||||
useMutation,
|
useMutation,
|
||||||
@@ -66,9 +67,8 @@ function getQuizQueryConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useUpdateQuizMutation = () => {
|
export const useUpdateQuizMutation = () => {
|
||||||
|
|
||||||
const { courseName } = useCourseContext();
|
const { courseName } = useCourseContext();
|
||||||
const queryClient = useQueryClient();
|
// const queryClient = useQueryClient();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({
|
mutationFn: async ({
|
||||||
quiz,
|
quiz,
|
||||||
@@ -89,9 +89,9 @@ export const useUpdateQuizMutation = () => {
|
|||||||
await axios.put(url, quiz);
|
await axios.put(url, quiz);
|
||||||
},
|
},
|
||||||
onSuccess: (_, { moduleName, quizName }) => {
|
onSuccess: (_, { moduleName, quizName }) => {
|
||||||
queryClient.invalidateQueries({
|
// queryClient.invalidateQueries({
|
||||||
queryKey: localCourseKeys.quiz(courseName, moduleName, quizName),
|
// queryKey: localCourseKeys.quiz(courseName, moduleName, quizName),
|
||||||
});
|
// });
|
||||||
// queryClient.invalidateQueries({
|
// queryClient.invalidateQueries({
|
||||||
// queryKey: localCourseKeys.quizNames(courseName, moduleName),
|
// queryKey: localCourseKeys.quizNames(courseName, moduleName),
|
||||||
// });
|
// });
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { LocalAssignmentGroup } from "./assignmnet/localAssignmentGroup";
|
import { LocalAssignmentGroup } from "./assignment/localAssignmentGroup";
|
||||||
import { LocalModule } from "./localModules";
|
import { LocalModule } from "./localModules";
|
||||||
import { parse, stringify } from "yaml";
|
import { parse, stringify } from "yaml";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { LocalAssignment } from "./assignmnet/localAssignment";
|
import { LocalAssignment } from "./assignment/localAssignment";
|
||||||
import { IModuleItem } from "./IModuleItem";
|
import { IModuleItem } from "./IModuleItem";
|
||||||
import { LocalCoursePage } from "./page/localCoursePage";
|
import { LocalCoursePage } from "./page/localCoursePage";
|
||||||
import { LocalQuiz } from "./quiz/localQuiz";
|
import { LocalQuiz } from "./quiz/localQuiz";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { extractLabelValue } from "../assignmnet/utils/markdownUtils";
|
import { extractLabelValue } from "../assignment/utils/markdownUtils";
|
||||||
import { IModuleItem } from "../IModuleItem";
|
import { IModuleItem } from "../IModuleItem";
|
||||||
import { verifyDateOrThrow } from "../timeUtils";
|
import { verifyDateOrThrow } from "../timeUtils";
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
import { LocalAssignment } from "../assignmnet/localAssignment";
|
import { LocalAssignment } from "../assignment/localAssignment";
|
||||||
import { AssignmentSubmissionType } from "../assignmnet/assignmentSubmissionType";
|
import { AssignmentSubmissionType } from "../assignment/assignmentSubmissionType";
|
||||||
import { assignmentMarkdownSerializer } from "../assignmnet/utils/assignmentMarkdownSerializer";
|
import { assignmentMarkdownSerializer } from "../assignment/utils/assignmentMarkdownSerializer";
|
||||||
import { assignmentMarkdownParser } from "../assignmnet/utils/assignmentMarkdownParser";
|
import { assignmentMarkdownParser } from "../assignment/utils/assignmentMarkdownParser";
|
||||||
|
|
||||||
describe("AssignmentMarkdownTests", () => {
|
describe("AssignmentMarkdownTests", () => {
|
||||||
it("can parse assignment settings", () => {
|
it("can parse assignment settings", () => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
import { RubricItem, rubricItemIsExtraCredit } from "../assignmnet/rubricItem";
|
import { RubricItem, rubricItemIsExtraCredit } from "../assignment/rubricItem";
|
||||||
import { assignmentMarkdownParser } from "../assignmnet/utils/assignmentMarkdownParser";
|
import { assignmentMarkdownParser } from "../assignment/utils/assignmentMarkdownParser";
|
||||||
|
|
||||||
describe("RubricMarkdownTests", () => {
|
describe("RubricMarkdownTests", () => {
|
||||||
it("can parse one item", () => {
|
it("can parse one item", () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
import { getDateFromString } from "../timeUtils";
|
import { dateToMarkdownString, getDateFromString } from "../timeUtils";
|
||||||
|
|
||||||
describe("Can properly handle expected date formats", () => {
|
describe("Can properly handle expected date formats", () => {
|
||||||
it("can use AM/PM dates", () => {
|
it("can use AM/PM dates", () => {
|
||||||
@@ -39,4 +39,12 @@ describe("Can properly handle expected date formats", () => {
|
|||||||
expect(dateObject?.getHours()).toBe(1);
|
expect(dateObject?.getHours()).toBe(1);
|
||||||
expect(dateObject?.getSeconds()).toBe(0);
|
expect(dateObject?.getSeconds()).toBe(0);
|
||||||
});
|
});
|
||||||
|
it("can get correct time from format", () => {
|
||||||
|
const dateString = "08/27/2024 23:59:00";
|
||||||
|
const dateObject = getDateFromString(dateString);
|
||||||
|
|
||||||
|
expect(dateObject).not.toBeUndefined()
|
||||||
|
const updatedString = dateToMarkdownString(dateObject!)
|
||||||
|
expect(updatedString).toBe(dateString)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
directoryOrFileExists,
|
directoryOrFileExists,
|
||||||
hasFileSystemEntries,
|
hasFileSystemEntries,
|
||||||
} from "./utils/fileSystemUtils";
|
} from "./utils/fileSystemUtils";
|
||||||
import { localAssignmentMarkdown } from "@/models/local/assignmnet/localAssignment";
|
import { localAssignmentMarkdown } from "@/models/local/assignment/localAssignment";
|
||||||
import { LocalQuiz, localQuizMarkdownUtils } from "@/models/local/quiz/localQuiz";
|
import { LocalQuiz, localQuizMarkdownUtils } from "@/models/local/quiz/localQuiz";
|
||||||
import { localPageMarkdownUtils } from "@/models/local/page/localCoursePage";
|
import { localPageMarkdownUtils } from "@/models/local/page/localCoursePage";
|
||||||
import { quizMarkdownUtils } from "@/models/local/quiz/utils/quizMarkdownUtils";
|
import { quizMarkdownUtils } from "@/models/local/quiz/utils/quizMarkdownUtils";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
LocalAssignment,
|
LocalAssignment,
|
||||||
localAssignmentMarkdown,
|
localAssignmentMarkdown,
|
||||||
} from "@/models/local/assignmnet/localAssignment";
|
} from "@/models/local/assignment/localAssignment";
|
||||||
import {
|
import {
|
||||||
LocalCourse,
|
LocalCourse,
|
||||||
LocalCourseSettings,
|
LocalCourseSettings,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { localAssignmentMarkdown } from "@/models/local/assignmnet/localAssignment";
|
import { localAssignmentMarkdown } from "@/models/local/assignment/localAssignment";
|
||||||
import { LocalCourse, localCourseYamlUtils } from "@/models/local/localCourse";
|
import { LocalCourse, localCourseYamlUtils } from "@/models/local/localCourse";
|
||||||
import { LocalModule } from "@/models/local/localModules";
|
import { LocalModule } from "@/models/local/localModules";
|
||||||
import { localPageMarkdownUtils } from "@/models/local/page/localCoursePage";
|
import { localPageMarkdownUtils } from "@/models/local/page/localCoursePage";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
import { LocalCourse } from "@/models/local/localCourse";
|
import { LocalCourse } from "@/models/local/localCourse";
|
||||||
import { CourseDifferences } from "../fileStorage/utils/courseDifferences";
|
import { CourseDifferences } from "../fileStorage/utils/courseDifferences";
|
||||||
import { AssignmentSubmissionType } from "@/models/local/assignmnet/assignmentSubmissionType";
|
import { AssignmentSubmissionType } from "@/models/local/assignment/assignmentSubmissionType";
|
||||||
|
|
||||||
describe("CourseDifferencesChangesTests", () => {
|
describe("CourseDifferencesChangesTests", () => {
|
||||||
it("can detect new settings", () => {
|
it("can detect new settings", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user