mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
updates
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
"use client"
|
||||
import { useLocalCoursesQuery } from "@/hooks/localCoursesHooks";
|
||||
"use client";
|
||||
import { useLocalCourseNamesQuery } from "@/hooks/localCoursesHooks";
|
||||
import Link from "next/link";
|
||||
|
||||
export default function CourseList() {
|
||||
const { data: courses } = useLocalCoursesQuery();
|
||||
const { data: courses } = useLocalCourseNamesQuery();
|
||||
return (
|
||||
<div>
|
||||
{courses.map((c) => (
|
||||
|
||||
@@ -12,3 +12,12 @@ export async function PUT(
|
||||
await fileStorageService.saveCourseAsync(updatedCourse, previousCourse);
|
||||
return Response.json({});
|
||||
}
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params: { courseName } }: { params: { courseName: string } }
|
||||
) {
|
||||
const courses = await fileStorageService.loadSavedCourses();
|
||||
const course = courses.find((c) => c.settings.name === courseName);
|
||||
return Response.json(course);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||
|
||||
export async function GET() {
|
||||
return Response.json([]);
|
||||
const courses = await fileStorageService.loadSavedCourses();
|
||||
return Response.json(courses);
|
||||
}
|
||||
|
||||
@@ -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