editing assignments

This commit is contained in:
2024-09-03 17:03:16 -06:00
parent d75ccf3a8c
commit 59de726d54
5 changed files with 54 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
import { getQueryClient } from "@/app/providersQueryClientUtils";
import { hydrateCourse } from "@/hooks/hookHydration";
import CourseContextProvider from "./context/CourseContextProvider";
import { Suspense } from "react";
export default async function CourseLayout({
children,
@@ -10,7 +11,7 @@ export default async function CourseLayout({
children: React.ReactNode;
params: { courseName: string };
}) {
const decodedCourseName = decodeURIComponent(courseName)
const decodedCourseName = decodeURIComponent(courseName);
if (courseName.includes(".js.map")) {
console.log("cannot load course that is .js.map " + decodedCourseName);
return <div></div>;
@@ -22,8 +23,12 @@ export default async function CourseLayout({
// console.log("hydrated course state", courseName, dehydratedState);
return (
<CourseContextProvider localCourseName={decodedCourseName}>
<HydrationBoundary state={dehydratedState}>{children}</HydrationBoundary>
</CourseContextProvider>
<Suspense>
<CourseContextProvider localCourseName={decodedCourseName}>
<HydrationBoundary state={dehydratedState}>
{children}
</HydrationBoundary>
</CourseContextProvider>
</Suspense>
);
}

View File

@@ -1,8 +1,11 @@
"use client";
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 { useState } from "react";
import { useEffect, useState } from "react";
import AssignmentPreview from "./AssignmentPreview";
export default function EditAssignment({
@@ -13,11 +16,47 @@ export default function EditAssignment({
moduleName: string;
}) {
const { data: assignment } = useAssignmentQuery(moduleName, assignmentName);
const updateAssignment = useUpdateAssignmentMutation();
const [assignmentText, setAssignmentText] = useState(
localAssignmentMarkdown.toMarkdown(assignment)
);
console.log(assignmentText);
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 (
<div className="h-full flex flex-col">
<div className="columns-2 min-h-0 flex-1">