diff --git a/src/hooks/note/useAutoSaveNoteDraft.ts b/src/hooks/note/useAutoSaveNoteDraft.ts index ea1f7984..fdffe287 100644 --- a/src/hooks/note/useAutoSaveNoteDraft.ts +++ b/src/hooks/note/useAutoSaveNoteDraft.ts @@ -37,21 +37,6 @@ export const useAutoSaveNoteDraft = ({ const toastIntervalRef = useRef(null); const saveDraftNoteAndShowToast = () => { - const [title, plainContent, linkUrl] = getValues([ - "title", - "plainContent", - "linkUrl", - ] as Path[]); - - if (isEmptyNote({ title, plainContent, linkUrl })) { - addToast({ - variant: "error", - content: "빈 노트는 저장할 수 없습니다", - }); - - return; - } - saveDraftNote(getValues()); addToast({ content: "임시 저장이 완료되었습니다", @@ -69,11 +54,37 @@ export const useAutoSaveNoteDraft = ({ removeInterval(); toastIntervalRef.current = setInterval(() => { + const [title, plainContent, linkUrl] = getValues([ + "title", + "plainContent", + "linkUrl", + ] as Path[]); + + console.log(isEmptyNote({ title, plainContent, linkUrl })); + if (isEmptyNote({ title, plainContent, linkUrl })) { + return; + } + saveDraftNoteAndShowToast(); }, TOAST_INTERVAL_TIME); }; const handleClickSaveDraft = () => { + const [title, plainContent, linkUrl] = getValues([ + "title", + "plainContent", + "linkUrl", + ] as Path[]); + + if (isEmptyNote({ title, plainContent, linkUrl })) { + addToast({ + variant: "error", + content: "빈 노트는 저장할 수 없습니다", + }); + + return; + } + saveDraftNoteAndShowToast(); addInterval(); };