mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
faster renders for drag and drop
This commit is contained in:
@@ -8,6 +8,7 @@ export default function Day({ day, month }: { day: Date; month: number }) {
|
||||
const { data: moduleNames } = useModuleNamesQuery(courseName);
|
||||
const isInSameMonth = day.getMonth() + 1 != month;
|
||||
const backgroundClass = isInSameMonth ? "" : "bg-slate-900";
|
||||
console.log("render");
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"use client";
|
||||
import { ReactNode, useState } from "react";
|
||||
import { ReactNode, useCallback, useState } from "react";
|
||||
import { CourseContext, DraggableItem } from "./courseContext";
|
||||
import { LocalQuiz } from "@/models/local/quiz/localQuiz";
|
||||
import { dateToMarkdownString } from "@/models/local/timeUtils";
|
||||
@@ -17,49 +17,8 @@ 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={{
|
||||
courseName: localCourseName,
|
||||
startItemDrag: (d) => {
|
||||
setItemBeingDragged(d);
|
||||
},
|
||||
endItemDrag: () => {
|
||||
setItemBeingDragged(undefined);
|
||||
},
|
||||
itemDrop: (day) => {
|
||||
const itemDrop = useCallback(
|
||||
(day: Date | undefined) => {
|
||||
if (itemBeingDragged && day) {
|
||||
if (itemBeingDragged.type === "quiz") {
|
||||
const quiz: LocalQuiz = {
|
||||
@@ -75,6 +34,20 @@ export default function CourseContextProvider({
|
||||
}
|
||||
setItemBeingDragged(undefined);
|
||||
},
|
||||
[itemBeingDragged, updateQuizMutation]
|
||||
);
|
||||
|
||||
return (
|
||||
<CourseContext.Provider
|
||||
value={{
|
||||
courseName: localCourseName,
|
||||
startItemDrag: (d) => {
|
||||
setItemBeingDragged(d);
|
||||
},
|
||||
endItemDrag: () => {
|
||||
setItemBeingDragged(undefined);
|
||||
},
|
||||
itemDrop,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type { Metadata } from "next";
|
||||
import "./globals.css";
|
||||
import { dehydrate } from "@tanstack/react-query";
|
||||
import { hydrateCourses } from "@/hooks/hookHydration";
|
||||
import { createQueryClientForServer } from "@/services/utils/queryClientServer";
|
||||
import Providers from "./providers";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
@@ -16,9 +13,9 @@ export default function RootLayout({
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<Providers>
|
||||
<body className="bg-slate-900 h-screen p-1 text-slate-300">{children}</body>
|
||||
</Providers>
|
||||
<body className="bg-slate-900 h-screen p-1 text-slate-300">
|
||||
<Providers>{children}</Providers>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user