File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
packages/markdown-editor/src/components/markdown-editor Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export const MarkdownEditor = ({}: MarkdownEditorProps) => {
15
15
const [ isAutoSave , setAutoSave ] = useState < boolean > ( false )
16
16
const [ isFocus , setIsFocus ] = useState < boolean > ( false )
17
17
const codemirror = useRef < HTMLDivElement | null > ( null )
18
+ const interval = useRef < NodeJS . Timeout | null > ( null )
18
19
const { state, view } = useCodemirror ( codemirror , {
19
20
autoFocus : true ,
20
21
minHeight : '100%' ,
@@ -41,6 +42,19 @@ export const MarkdownEditor = ({}: MarkdownEditorProps) => {
41
42
}
42
43
} , [ router , view ] )
43
44
45
+ // 30초마다 자동 저장
46
+ useEffect ( ( ) => {
47
+ if ( ! view ) return
48
+ interval . current = setInterval ( ( ) => {
49
+ setAutoSave ( true )
50
+ saveExecute ( view )
51
+ } , 30000 ) // 30초
52
+ return ( ) => {
53
+ if ( ! interval . current ) return
54
+ clearInterval ( interval . current )
55
+ }
56
+ } , [ view ] )
57
+
44
58
// 저장 되고 나면 toast 메시지
45
59
useEffect ( ( ) => {
46
60
const updateItemResult = ( e : CustomEventInit < CustomEventDetail [ 'updateItemResultEvent' ] > ) => {
Original file line number Diff line number Diff line change @@ -49,7 +49,6 @@ export function saveExecute(view: EditorView) {
49
49
}
50
50
51
51
prevDoc . set ( currentUrl , doc )
52
- console . log ( 'save!' )
53
52
const event = new CustomEvent < CustomEventDetail [ 'updateItemEvent' ] > (
54
53
markdownCustomEventName . updateItemEvent ,
55
54
{
You can’t perform that action at this time.
0 commit comments