Skip to content

Commit da98554

Browse files
committed
feat: Implement auto-save functionality in MarkdownEditor
1 parent 15fdb08 commit da98554

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/markdown-editor/src/components/markdown-editor/markdown-editor.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const MarkdownEditor = ({}: MarkdownEditorProps) => {
1515
const [isAutoSave, setAutoSave] = useState<boolean>(false)
1616
const [isFocus, setIsFocus] = useState<boolean>(false)
1717
const codemirror = useRef<HTMLDivElement | null>(null)
18+
const interval = useRef<NodeJS.Timeout | null>(null)
1819
const { state, view } = useCodemirror(codemirror, {
1920
autoFocus: true,
2021
minHeight: '100%',
@@ -41,6 +42,19 @@ export const MarkdownEditor = ({}: MarkdownEditorProps) => {
4142
}
4243
}, [router, view])
4344

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+
4458
// 저장 되고 나면 toast 메시지
4559
useEffect(() => {
4660
const updateItemResult = (e: CustomEventInit<CustomEventDetail['updateItemResultEvent']>) => {

packages/markdown-editor/src/components/markdown-editor/toolbar/commands/save.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export function saveExecute(view: EditorView) {
4949
}
5050

5151
prevDoc.set(currentUrl, doc)
52-
console.log('save!')
5352
const event = new CustomEvent<CustomEventDetail['updateItemEvent']>(
5453
markdownCustomEventName.updateItemEvent,
5554
{

0 commit comments

Comments
 (0)