From 6ee95a2c0c0b11ba3e74dcabe7ba483869e33aa5 Mon Sep 17 00:00:00 2001 From: Athurg Gooth Date: Tue, 14 Nov 2023 10:02:16 +0800 Subject: [PATCH] fix: clear localStorage while draft is empty (#2510) * Clear localStorage while draft is empty * change == into === --- web/src/components/MemoEditor/index.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/web/src/components/MemoEditor/index.tsx b/web/src/components/MemoEditor/index.tsx index 768bf471..a1b7d980 100644 --- a/web/src/components/MemoEditor/index.tsx +++ b/web/src/components/MemoEditor/index.tsx @@ -45,7 +45,8 @@ const MemoEditor = (props: Props) => { const { className, editorClassName, cacheKey, memoId, onConfirm } = props; const { i18n } = useTranslation(); const t = useTranslate(); - const [contentCache, setContentCache] = useLocalStorage(`memo-editor-${cacheKey}`, ""); + const contentCacheKey = `memo-editor-${cacheKey}`; + const [contentCache, setContentCache] = useLocalStorage(contentCacheKey, ""); const { state: { systemStatus }, } = useGlobalStore(); @@ -284,7 +285,11 @@ const MemoEditor = (props: Props) => { const handleContentChange = (content: string) => { setHasContent(content !== ""); - setContentCache(content); + if (content !== "") { + setContentCache(content); + } else { + localStorage.removeItem(contentCacheKey); + } }; const handleSaveBtnClick = async () => {