forked from accordproject/template-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgreementData.tsx
More file actions
47 lines (42 loc) · 1.55 KB
/
AgreementData.tsx
File metadata and controls
47 lines (42 loc) · 1.55 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 JSONEditor from "../JSONEditor";
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 AgreementData() {
const textColor = useAppStore((state) => state.textColor);
const setData = useAppStore((state) => state.setData);
const { value, setValue, undo, redo } = useUndoRedo(
useAppStore((state) => state.editorAgreementData),
setData // Pass setData to update the preview when undo/redo happens
);
const debouncedSetData = useCallback(
debounce((value: string) => {
void setData(value);
}, 500),
[setData]
);
const handleChange = (value: string | undefined) => {
if (value !== undefined) {
setValue(value);
debouncedSetData(value);
}
};
return (
<div className="column" >
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
<h3 style={{ color: textColor }}>Data</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 }}>
JSON data (an instance of the Concerto model) used to preview output from the template.
</p>
<JSONEditor value={value} onChange={handleChange} />
</div>
);
}
export default AgreementData;