-
-
Notifications
You must be signed in to change notification settings - Fork 215
Expand file tree
/
Copy pathTemplateMarkdown.tsx
More file actions
47 lines (40 loc) · 1.48 KB
/
TemplateMarkdown.tsx
File metadata and controls
47 lines (40 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { useRef, useEffect } from "react";
import { editor as MonacoEditorNS } from "monaco-editor";
import MarkdownEditor from "../MarkdownEditor";
import useAppStore from "../../store/store";
import { updateEditorActivity } from "../../ai-assistant/activityTracker";
import { useMarkdownEditorContext } from "../../contexts/MarkdownEditorContext";
import { createMarkdownCommands } from "./markdownCommands";
function TemplateMarkdown() {
const editorValue = useAppStore((state) => state.editorValue);
const setEditorValue = useAppStore((state) => state.setEditorValue);
const setTemplateMarkdown = useAppStore((state) => state.setTemplateMarkdown);
const { setCommands } = useMarkdownEditorContext();
const editorRef = useRef<MonacoEditorNS.IStandaloneCodeEditor | null>(null);
useEffect(() => {
return () => {
// Clear commands when unmounting
setCommands(undefined);
};
}, [setCommands]);
const handleChange = (value: string | undefined) => {
if (value !== undefined) {
updateEditorActivity("markdown");
setEditorValue(value);
void setTemplateMarkdown(value);
}
};
const handleEditorReady = (editor: MonacoEditorNS.IStandaloneCodeEditor) => {
editorRef.current = editor;
const commands = createMarkdownCommands(editorRef);
setCommands(commands);
};
return (
<MarkdownEditor
value={editorValue}
onChange={handleChange}
onEditorReady={handleEditorReady}
/>
);
}
export default TemplateMarkdown;