1
1
import MarkdownEditor from "../MarkdownEditor" ;
2
2
import useAppStore from "../../store/store" ;
3
+ import useUndoRedo from "../../components/useUndoRedo" ;
3
4
import { useCallback } from "react" ;
4
5
import { debounce } from "ts-debounce" ;
6
+ import { FaUndo , FaRedo } from "react-icons/fa" ;
5
7
6
8
function TemplateMarkdown ( ) {
7
- const editorValue = useAppStore ( ( state ) => state . editorValue ) ;
8
- const setEditorValue = useAppStore ( ( state ) => state . setEditorValue ) ;
9
- const setTemplateMarkdown = useAppStore ( ( state ) => state . setTemplateMarkdown ) ;
10
- const backgroundColor = useAppStore ( ( state ) => state . backgroundColor ) ;
11
9
const textColor = useAppStore ( ( state ) => state . textColor ) ;
12
-
10
+ const backgroundColor = useAppStore ( ( state ) => state . backgroundColor ) ;
11
+ const setTemplateMarkdown = useAppStore ( ( state ) => state . setTemplateMarkdown ) ;
12
+ const { value, setValue, undo, redo } = useUndoRedo (
13
+ useAppStore ( ( state ) => state . editorValue ) ,
14
+ setTemplateMarkdown // Ensures preview updates when undo/redo happens
15
+ ) ;
16
+
13
17
const debouncedSetTemplateMarkdown = useCallback (
14
18
debounce ( ( value : string ) => {
15
19
void setTemplateMarkdown ( value ) ;
16
20
} , 500 ) ,
17
- [ ]
21
+ [ setTemplateMarkdown ]
18
22
) ;
19
23
20
24
const handleChange = ( value : string | undefined ) => {
21
25
if ( value !== undefined ) {
22
- setEditorValue ( value ) ;
26
+ setValue ( value ) ;
23
27
debouncedSetTemplateMarkdown ( value ) ;
24
28
}
25
29
} ;
26
30
27
31
return (
28
- < div className = "column" style = { { backgroundColor : backgroundColor } } >
29
- < h2 style = { { color : textColor } } > TemplateMark</ h2 >
32
+ < div className = "column" style = { { backgroundColor } } >
33
+ < div style = { { display : "flex" , alignItems : "center" , justifyContent : "space-between" } } >
34
+ < h3 style = { { color : textColor } } > TemplateMark</ h3 >
35
+ < div >
36
+ < FaUndo onClick = { undo } title = "Undo" style = { { cursor : "pointer" , color : textColor , marginRight : "8px" } } />
37
+ < FaRedo onClick = { redo } title = "Redo" style = { { cursor : "pointer" , color : textColor } } />
38
+ </ div >
39
+ </ div >
30
40
< p style = { { color : textColor } } >
31
- A natural language template with embedded variables, conditional
32
- sections, and TypeScript code.
41
+ A natural language template with embedded variables, conditional sections, and TypeScript code.
33
42
</ p >
34
- < MarkdownEditor value = { editorValue } onChange = { handleChange } />
43
+ < MarkdownEditor value = { value } onChange = { handleChange } />
35
44
</ div >
36
45
) ;
37
46
}
38
47
39
- export default TemplateMarkdown ;
48
+ export default TemplateMarkdown ;
0 commit comments