Skip to content

Commit

Permalink
chore: Refactor MarkdownEditorContainer.tsx for improved temp save fu…
Browse files Browse the repository at this point in the history
…nctionality
  • Loading branch information
winverse committed Aug 6, 2024
1 parent 5e02e2b commit f9d2c37
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/containers/write/MarkdownEditorContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
dispatch(setWritePostId(id));
history.replace(`/write?id=${id}`);
}

if (!id) return;

const url = URL.createObjectURL(file);
Expand All @@ -306,16 +306,16 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {

useEffect(() => {
const changed = !shallowEqual(lastSavedData, { title, body: markdown });
if (!changed) return;

const timeoutId = setTimeout(() => {
if (!postId && !title && markdown.length < 30) return;
onTempSave(false);
}, 1000 * 10);

return () => {
clearTimeout(timeoutId);
};
if (changed) {
const timeoutId = setTimeout(() => {
if (!postId && !title && markdown.length < 30) return;
onTempSave(true);
}, 10 * 1000);

return () => {
clearTimeout(timeoutId);
};
}
}, [title, postId, onTempSave, lastSavedData, markdown]);

useSaveHotKey(() => onTempSave(true));
Expand Down

0 comments on commit f9d2c37

Please sign in to comment.