mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
parsing and errors
This commit is contained in:
@@ -61,7 +61,6 @@
|
|||||||
|
|
||||||
@foreach(var question in Quiz.Questions)
|
@foreach(var question in Quiz.Questions)
|
||||||
{
|
{
|
||||||
|
|
||||||
<div class="bg-dark-subtle mt-1 p-1 ps-2 rounded rounded-2">
|
<div class="bg-dark-subtle mt-1 p-1 ps-2 rounded rounded-2">
|
||||||
<MarkdownQuestionPreview
|
<MarkdownQuestionPreview
|
||||||
Question="question"
|
Question="question"
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { MonacoEditor } from "@/components/editor/MonacoEditor";
|
import { MonacoEditor } from "@/components/editor/MonacoEditor";
|
||||||
import { useQuizQuery } from "@/hooks/localCourse/quizHooks";
|
import {
|
||||||
|
useQuizQuery,
|
||||||
|
useUpdateQuizMutation,
|
||||||
|
} from "@/hooks/localCourse/quizHooks";
|
||||||
import { quizMarkdownUtils } from "@/models/local/quiz/utils/quizMarkdownUtils";
|
import { quizMarkdownUtils } from "@/models/local/quiz/utils/quizMarkdownUtils";
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import QuizPreview from "./QuizPreview";
|
||||||
|
|
||||||
export default function EditQuiz({
|
export default function EditQuiz({
|
||||||
moduleName,
|
moduleName,
|
||||||
@@ -12,13 +16,47 @@ export default function EditQuiz({
|
|||||||
moduleName: string;
|
moduleName: string;
|
||||||
}) {
|
}) {
|
||||||
const { data: quiz } = useQuizQuery(moduleName, quizName);
|
const { data: quiz } = useQuizQuery(moduleName, quizName);
|
||||||
|
const updateQuizMutation = useUpdateQuizMutation();
|
||||||
const [quizText, setQuizText] = useState(quizMarkdownUtils.toMarkdown(quiz));
|
const [quizText, setQuizText] = useState(quizMarkdownUtils.toMarkdown(quiz));
|
||||||
|
const [error, setError] = useState("");
|
||||||
// console.log(quizText);
|
// console.log(quizText);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const delay = 500;
|
||||||
|
const handler = setTimeout(() => {
|
||||||
|
if (quizMarkdownUtils.toMarkdown(quiz) !== quizText) {
|
||||||
|
// handle when parsing does not work
|
||||||
|
try {
|
||||||
|
const updatedQuiz = quizMarkdownUtils.parseMarkdown(quizText);
|
||||||
|
updateQuizMutation.mutate({
|
||||||
|
quiz: updatedQuiz,
|
||||||
|
moduleName,
|
||||||
|
quizName,
|
||||||
|
});
|
||||||
|
} catch (e: any) {
|
||||||
|
setError(e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, delay);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearTimeout(handler);
|
||||||
|
};
|
||||||
|
}, [moduleName, quiz, quizName, quizText, updateQuizMutation]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="h-full flex flex-col">
|
||||||
{quiz.name}
|
{quiz.name}
|
||||||
|
<div className="columns-2 min-h-0 flex-1">
|
||||||
<MonacoEditor value={quizText} onChange={setQuizText} />
|
<MonacoEditor value={quizText} onChange={setQuizText} />
|
||||||
|
<div>
|
||||||
|
<div className="text-red-300">
|
||||||
|
|
||||||
|
{error && error}
|
||||||
|
</div>
|
||||||
|
<QuizPreview quiz={quiz} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { LocalQuiz } from "@/models/local/quiz/localQuiz";
|
||||||
|
|
||||||
|
export default function QuizPreview({quiz}: {quiz: LocalQuiz}) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<div>{quiz.description}</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -9,3 +9,8 @@
|
|||||||
text-wrap: balance;
|
text-wrap: balance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* monaco editor */
|
||||||
|
.monaco-editor-background, .monaco-editor .margin {
|
||||||
|
background-color: black !important;
|
||||||
|
}
|
||||||
@@ -15,8 +15,6 @@ export default function InnerMonacoEditor({
|
|||||||
const editorRef = useRef<editor.IStandaloneCodeEditor | null>(null);
|
const editorRef = useRef<editor.IStandaloneCodeEditor | null>(null);
|
||||||
const divRef = useRef<HTMLDivElement>(null);
|
const divRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
// const monacoRef = useRef<Monaco | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (divRef.current && !editorRef.current) {
|
if (divRef.current && !editorRef.current) {
|
||||||
loader.init().then((monaco) => {
|
loader.init().then((monaco) => {
|
||||||
@@ -47,12 +45,13 @@ export default function InnerMonacoEditor({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [onChange, value]);
|
}, [onChange, value]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
id="myMonacoEditor"
|
id="myMonacoEditor"
|
||||||
className="Editor"
|
className="Editor"
|
||||||
ref={divRef}
|
ref={divRef}
|
||||||
style={{ height: "500px", width: "100%" }}
|
style={{ height: "100%", overflow: "hidden" }}
|
||||||
></div>
|
></div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user