mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 23:58:31 -06:00
editing assignments
This commit is contained in:
@@ -2,6 +2,7 @@ import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
|
|||||||
import { getQueryClient } from "@/app/providersQueryClientUtils";
|
import { getQueryClient } from "@/app/providersQueryClientUtils";
|
||||||
import { hydrateCourse } from "@/hooks/hookHydration";
|
import { hydrateCourse } from "@/hooks/hookHydration";
|
||||||
import CourseContextProvider from "./context/CourseContextProvider";
|
import CourseContextProvider from "./context/CourseContextProvider";
|
||||||
|
import { Suspense } from "react";
|
||||||
|
|
||||||
export default async function CourseLayout({
|
export default async function CourseLayout({
|
||||||
children,
|
children,
|
||||||
@@ -10,7 +11,7 @@ export default async function CourseLayout({
|
|||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
params: { courseName: string };
|
params: { courseName: string };
|
||||||
}) {
|
}) {
|
||||||
const decodedCourseName = decodeURIComponent(courseName)
|
const decodedCourseName = decodeURIComponent(courseName);
|
||||||
if (courseName.includes(".js.map")) {
|
if (courseName.includes(".js.map")) {
|
||||||
console.log("cannot load course that is .js.map " + decodedCourseName);
|
console.log("cannot load course that is .js.map " + decodedCourseName);
|
||||||
return <div></div>;
|
return <div></div>;
|
||||||
@@ -22,8 +23,12 @@ export default async function CourseLayout({
|
|||||||
|
|
||||||
// console.log("hydrated course state", courseName, dehydratedState);
|
// console.log("hydrated course state", courseName, dehydratedState);
|
||||||
return (
|
return (
|
||||||
|
<Suspense>
|
||||||
<CourseContextProvider localCourseName={decodedCourseName}>
|
<CourseContextProvider localCourseName={decodedCourseName}>
|
||||||
<HydrationBoundary state={dehydratedState}>{children}</HydrationBoundary>
|
<HydrationBoundary state={dehydratedState}>
|
||||||
|
{children}
|
||||||
|
</HydrationBoundary>
|
||||||
</CourseContextProvider>
|
</CourseContextProvider>
|
||||||
|
</Suspense>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { MonacoEditor } from "@/components/editor/MonacoEditor";
|
import { MonacoEditor } from "@/components/editor/MonacoEditor";
|
||||||
import { useAssignmentQuery } from "@/hooks/localCourse/assignmentHooks";
|
import {
|
||||||
|
useAssignmentQuery,
|
||||||
|
useUpdateAssignmentMutation,
|
||||||
|
} from "@/hooks/localCourse/assignmentHooks";
|
||||||
import { localAssignmentMarkdown } from "@/models/local/assignment/localAssignment";
|
import { localAssignmentMarkdown } from "@/models/local/assignment/localAssignment";
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import AssignmentPreview from "./AssignmentPreview";
|
import AssignmentPreview from "./AssignmentPreview";
|
||||||
|
|
||||||
export default function EditAssignment({
|
export default function EditAssignment({
|
||||||
@@ -13,11 +16,47 @@ export default function EditAssignment({
|
|||||||
moduleName: string;
|
moduleName: string;
|
||||||
}) {
|
}) {
|
||||||
const { data: assignment } = useAssignmentQuery(moduleName, assignmentName);
|
const { data: assignment } = useAssignmentQuery(moduleName, assignmentName);
|
||||||
|
const updateAssignment = useUpdateAssignmentMutation();
|
||||||
|
|
||||||
const [assignmentText, setAssignmentText] = useState(
|
const [assignmentText, setAssignmentText] = useState(
|
||||||
localAssignmentMarkdown.toMarkdown(assignment)
|
localAssignmentMarkdown.toMarkdown(assignment)
|
||||||
);
|
);
|
||||||
|
console.log(assignmentText);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const delay = 500;
|
||||||
|
const handler = setTimeout(() => {
|
||||||
|
const updatedAssignment =
|
||||||
|
localAssignmentMarkdown.parseMarkdown(assignmentText);
|
||||||
|
if (
|
||||||
|
localAssignmentMarkdown.toMarkdown(assignment) !==
|
||||||
|
localAssignmentMarkdown.toMarkdown(updatedAssignment)
|
||||||
|
) {
|
||||||
|
console.log("updating assignment");
|
||||||
|
try {
|
||||||
|
updateAssignment.mutate({
|
||||||
|
assignment: updatedAssignment,
|
||||||
|
moduleName,
|
||||||
|
assignmentName,
|
||||||
|
});
|
||||||
|
} catch (e: any) {
|
||||||
|
setError(e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, delay);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearTimeout(handler);
|
||||||
|
};
|
||||||
|
}, [
|
||||||
|
assignment,
|
||||||
|
assignmentName,
|
||||||
|
assignmentText,
|
||||||
|
moduleName,
|
||||||
|
updateAssignment,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full flex flex-col">
|
<div className="h-full flex flex-col">
|
||||||
<div className="columns-2 min-h-0 flex-1">
|
<div className="columns-2 min-h-0 flex-1">
|
||||||
|
|||||||
@@ -54,3 +54,7 @@ ol {
|
|||||||
hr {
|
hr {
|
||||||
@apply border-t border-gray-200 my-4;
|
@apply border-t border-gray-200 my-4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blockquote {
|
||||||
|
@apply border-l-4 border-gray-300 pl-4 italic text-gray-700;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import React, { useRef, useEffect } from "react";
|
import React, { useRef, useEffect } from "react";
|
||||||
// import * as monaco from "monaco-editor";
|
|
||||||
import Editor, { Monaco } from "@monaco-editor/react";
|
|
||||||
import loader from "@monaco-editor/loader";
|
import loader from "@monaco-editor/loader";
|
||||||
import { editor } from "monaco-editor/esm/vs/editor/editor.api";
|
import { editor } from "monaco-editor/esm/vs/editor/editor.api";
|
||||||
|
|
||||||
@@ -48,7 +46,6 @@ export default function InnerMonacoEditor({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
id="myMonacoEditor"
|
|
||||||
className="Editor"
|
className="Editor"
|
||||||
ref={divRef}
|
ref={divRef}
|
||||||
style={{ height: "100%", overflow: "hidden" }}
|
style={{ height: "100%", overflow: "hidden" }}
|
||||||
|
|||||||
Reference in New Issue
Block a user