mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
latex rendering slowed pc down
This commit is contained in:
@@ -8,6 +8,8 @@ import { quizMarkdownUtils } from "@/models/local/quiz/utils/quizMarkdownUtils";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import QuizPreview from "./QuizPreview";
|
import QuizPreview from "./QuizPreview";
|
||||||
import { QuizButtons } from "./QuizButton";
|
import { QuizButtons } from "./QuizButton";
|
||||||
|
import ClientOnly from "@/components/ClientOnly";
|
||||||
|
import { SuspenseAndErrorHandling } from "@/components/SuspenseAndErrorHandling";
|
||||||
|
|
||||||
const helpString = `QUESTION REFERENCE
|
const helpString = `QUESTION REFERENCE
|
||||||
---
|
---
|
||||||
@@ -50,7 +52,6 @@ this is a matching question
|
|||||||
^ left answer - right dropdown
|
^ left answer - right dropdown
|
||||||
^ other thing - another option`;
|
^ other thing - another option`;
|
||||||
|
|
||||||
|
|
||||||
export default function EditQuiz({
|
export default function EditQuiz({
|
||||||
moduleName,
|
moduleName,
|
||||||
quizName,
|
quizName,
|
||||||
@@ -65,9 +66,10 @@ export default function EditQuiz({
|
|||||||
const [showHelp, setShowHelp] = useState(false);
|
const [showHelp, setShowHelp] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const delay = 500;
|
const delay = 1000;
|
||||||
const handler = setTimeout(() => {
|
const handler = setTimeout(() => {
|
||||||
try {
|
try {
|
||||||
|
console.log("checking if the same...");
|
||||||
if (
|
if (
|
||||||
quizMarkdownUtils.toMarkdown(quiz) !==
|
quizMarkdownUtils.toMarkdown(quiz) !==
|
||||||
quizMarkdownUtils.toMarkdown(
|
quizMarkdownUtils.toMarkdown(
|
||||||
@@ -94,7 +96,7 @@ export default function EditQuiz({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full flex flex-col align-middle px-1">
|
<div className="h-full flex flex-col align-middle px-1">
|
||||||
<div className={"min-h-0 flex flex-row w-full"}>
|
<div className={"min-h-96 flex flex-row w-full"}>
|
||||||
{showHelp && (
|
{showHelp && (
|
||||||
<pre className=" max-w-96">
|
<pre className=" max-w-96">
|
||||||
<code>{helpString}</code>
|
<code>{helpString}</code>
|
||||||
@@ -105,14 +107,18 @@ export default function EditQuiz({
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex-1 h-full">
|
<div className="flex-1 h-full">
|
||||||
<div className="text-red-300">{error && error}</div>
|
<div className="text-red-300">{error && error}</div>
|
||||||
<QuizPreview quiz={quiz} />
|
<QuizPreview moduleName={moduleName} quizName={quizName} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<ClientOnly>
|
||||||
|
<SuspenseAndErrorHandling>
|
||||||
<QuizButtons
|
<QuizButtons
|
||||||
moduleName={moduleName}
|
moduleName={moduleName}
|
||||||
quizName={quizName}
|
quizName={quizName}
|
||||||
toggleHelp={() => setShowHelp((h) => !h)}
|
toggleHelp={() => setShowHelp((h) => !h)}
|
||||||
/>
|
/>
|
||||||
|
</SuspenseAndErrorHandling>
|
||||||
|
</ClientOnly>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { useQuizQuery } from "@/hooks/localCourse/quizHooks";
|
||||||
import { LocalQuiz } from "@/models/local/quiz/localQuiz";
|
import { LocalQuiz } from "@/models/local/quiz/localQuiz";
|
||||||
import {
|
import {
|
||||||
LocalQuizQuestion,
|
LocalQuizQuestion,
|
||||||
@@ -6,7 +7,14 @@ import {
|
|||||||
import { quizQuestionMarkdownUtils } from "@/models/local/quiz/utils/quizQuestionMarkdownUtils";
|
import { quizQuestionMarkdownUtils } from "@/models/local/quiz/utils/quizQuestionMarkdownUtils";
|
||||||
import { markdownToHTMLSafe } from "@/services/htmlMarkdownUtils";
|
import { markdownToHTMLSafe } from "@/services/htmlMarkdownUtils";
|
||||||
|
|
||||||
export default function QuizPreview({ quiz }: { quiz: LocalQuiz }) {
|
export default function QuizPreview({
|
||||||
|
moduleName,
|
||||||
|
quizName,
|
||||||
|
}: {
|
||||||
|
quizName: string;
|
||||||
|
moduleName: string;
|
||||||
|
}) {
|
||||||
|
const { data: quiz } = useQuizQuery(moduleName, quizName);
|
||||||
return (
|
return (
|
||||||
<div style={{ overflow: "scroll", height: "100%" }}>
|
<div style={{ overflow: "scroll", height: "100%" }}>
|
||||||
<div className="columns-2">
|
<div className="columns-2">
|
||||||
@@ -40,13 +48,9 @@ export default function QuizPreview({ quiz }: { quiz: LocalQuiz }) {
|
|||||||
<div className="p-3" style={{ whiteSpace: "pre-wrap" }}>
|
<div className="p-3" style={{ whiteSpace: "pre-wrap" }}>
|
||||||
{quiz.description}
|
{quiz.description}
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
|
||||||
<div className="p-3 rounded-md bg-slate-950 m-5 flex flex-col gap-3">
|
<div className="p-3 rounded-md bg-slate-950 m-5 flex flex-col gap-3">
|
||||||
{quiz.questions.map((question, i) => (
|
{quiz.questions.map((question, i) => (
|
||||||
<QuizQuestionPreview
|
<QuizQuestionPreview key={i} question={question} />
|
||||||
key={quizQuestionMarkdownUtils.toMarkdown(question)}
|
|
||||||
question={question}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
@@ -102,7 +106,7 @@ function QuizQuestionPreview({ question }: { question: LocalQuizQuestion }) {
|
|||||||
{question.answers.map((answer) => (
|
{question.answers.map((answer) => (
|
||||||
<div
|
<div
|
||||||
key={JSON.stringify(answer)}
|
key={JSON.stringify(answer)}
|
||||||
className="mx-3 mb-1 bg-dark rounded border-slate-700 flex flex-row border"
|
className="mx-3 mb-1 pt-1 border-t border-slate-700 flex flex-row"
|
||||||
>
|
>
|
||||||
<div className="w-8 flex flex-col justify-center">
|
<div className="w-8 flex flex-col justify-center">
|
||||||
{answer.correct ? (
|
{answer.correct ? (
|
||||||
|
|||||||
@@ -3,6 +3,31 @@ import React, { useRef, useEffect } from "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";
|
||||||
import * as monaco from "monaco-editor";
|
import * as monaco from "monaco-editor";
|
||||||
|
|
||||||
|
// import * as editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
|
||||||
|
// import * as jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
|
||||||
|
// import * as cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker';
|
||||||
|
// import * as htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker';
|
||||||
|
// import * as tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
|
||||||
|
|
||||||
|
// self.MonacoEnvironment = {
|
||||||
|
// getWorker(_, label) {
|
||||||
|
// if (label === 'json') {
|
||||||
|
// return new jsonWorker();
|
||||||
|
// }
|
||||||
|
// if (label === 'css' || label === 'scss' || label === 'less') {
|
||||||
|
// return new cssWorker();
|
||||||
|
// }
|
||||||
|
// if (label === 'html' || label === 'handlebars' || label === 'razor') {
|
||||||
|
// return new htmlWorker();
|
||||||
|
// }
|
||||||
|
// if (label === 'typescript' || label === 'javascript') {
|
||||||
|
// return new tsWorker();
|
||||||
|
// }
|
||||||
|
// return new editorWorker();
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
|
||||||
loader.config({ monaco });
|
loader.config({ monaco });
|
||||||
|
|
||||||
export default function InnerMonacoEditor({
|
export default function InnerMonacoEditor({
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import markedKatex from "marked-katex-extension";
|
|||||||
import * as DOMPurify from "isomorphic-dompurify";
|
import * as DOMPurify from "isomorphic-dompurify";
|
||||||
|
|
||||||
export function markdownToHTMLSafe(markdownString: string) {
|
export function markdownToHTMLSafe(markdownString: string) {
|
||||||
const options = {
|
// const options = {
|
||||||
throwOnError: false,
|
// throwOnError: false,
|
||||||
nonStandard: true
|
// nonStandard: true
|
||||||
};
|
// };
|
||||||
|
|
||||||
marked.use(markedKatex(options));
|
// marked.use(markedKatex(options));
|
||||||
|
|
||||||
const clean = DOMPurify.sanitize(
|
const clean = DOMPurify.sanitize(
|
||||||
marked.parse(markdownString, { async: false, pedantic: false, gfm: true })
|
marked.parse(markdownString, { async: false, pedantic: false, gfm: true })
|
||||||
|
|||||||
Reference in New Issue
Block a user