forked from accordproject/template-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplateMarkdown.tsx
More file actions
48 lines (43 loc) · 1.74 KB
/
TemplateMarkdown.tsx
File metadata and controls
48 lines (43 loc) · 1.74 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
48
import MarkdownEditor from "../MarkdownEditor";
import useAppStore from "../../store/store";
import useUndoRedo from "../../components/useUndoRedo";
import { useCallback } from "react";
import { debounce } from "ts-debounce";
import { FaUndo, FaRedo } from "react-icons/fa";
function TemplateMarkdown() {
const textColor = useAppStore((state) => state.textColor);
const backgroundColor = useAppStore((state) => state.backgroundColor);
const setTemplateMarkdown = useAppStore((state) => state.setTemplateMarkdown);
const { value, setValue, undo, redo } = useUndoRedo(
useAppStore((state) => state.editorValue),
setTemplateMarkdown // Ensures preview updates when undo/redo happens
);
const debouncedSetTemplateMarkdown = useCallback(
debounce((value: string) => {
void setTemplateMarkdown(value);
}, 500),
[setTemplateMarkdown]
);
const handleChange = (value: string | undefined) => {
if (value !== undefined) {
setValue(value);
debouncedSetTemplateMarkdown(value);
}
};
return (
<div className="column" style={{ backgroundColor }}>
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
<h3 style={{ color: textColor }}>TemplateMark</h3>
<div>
<FaUndo onClick={undo} title="Undo" style={{ cursor: "pointer", color: textColor, marginRight: "8px" }} />
<FaRedo onClick={redo} title="Redo" style={{ cursor: "pointer", color: textColor }} />
</div>
</div>
<p style={{ color: textColor }}>
A natural language template with embedded variables, conditional sections, and TypeScript code.
</p>
<MarkdownEditor value={value} onChange={handleChange} />
</div>
);
}
export default TemplateMarkdown;