forked from accordproject/template-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplateModel.tsx
More file actions
47 lines (42 loc) · 1.61 KB
/
TemplateModel.tsx
File metadata and controls
47 lines (42 loc) · 1.61 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 ConcertoEditor from "../ConcertoEditor";
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 TemplateModel() {
const textColor = useAppStore((state) => state.textColor);
const setModelCto = useAppStore((state) => state.setModelCto);
const { value, setValue, undo, redo } = useUndoRedo(
useAppStore((state) => state.editorModelCto),
setModelCto // Ensures errors and preview update when undo/redo happens
);
const debouncedSetModelCto = useCallback(
debounce((value: string) => {
void setModelCto(value);
}, 500),
[setModelCto]
);
const handleChange = (value: string | undefined) => {
if (value !== undefined) {
setValue(value);
debouncedSetModelCto(value);
}
};
return (
<div className="column">
<div className="tooltip" style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
<h3 style={{ color: textColor }}>Concerto Model</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>
<span style={{ color: textColor }} className="tooltiptext">
Defines the data model for the template and its logic.
</span>
<ConcertoEditor value={value} onChange={handleChange} />
</div>
);
}
export default TemplateModel;