Unverified Commit 6ee95a2c authored by Athurg Gooth's avatar Athurg Gooth Committed by GitHub

fix: clear localStorage while draft is empty (#2510)

* Clear localStorage while draft is empty

* change == into ===
parent 6814915c
...@@ -45,7 +45,8 @@ const MemoEditor = (props: Props) => { ...@@ -45,7 +45,8 @@ const MemoEditor = (props: Props) => {
const { className, editorClassName, cacheKey, memoId, onConfirm } = props; const { className, editorClassName, cacheKey, memoId, onConfirm } = props;
const { i18n } = useTranslation(); const { i18n } = useTranslation();
const t = useTranslate(); const t = useTranslate();
const [contentCache, setContentCache] = useLocalStorage<string>(`memo-editor-${cacheKey}`, ""); const contentCacheKey = `memo-editor-${cacheKey}`;
const [contentCache, setContentCache] = useLocalStorage<string>(contentCacheKey, "");
const { const {
state: { systemStatus }, state: { systemStatus },
} = useGlobalStore(); } = useGlobalStore();
...@@ -284,7 +285,11 @@ const MemoEditor = (props: Props) => { ...@@ -284,7 +285,11 @@ const MemoEditor = (props: Props) => {
const handleContentChange = (content: string) => { const handleContentChange = (content: string) => {
setHasContent(content !== ""); setHasContent(content !== "");
setContentCache(content); if (content !== "") {
setContentCache(content);
} else {
localStorage.removeItem(contentCacheKey);
}
}; };
const handleSaveBtnClick = async () => { const handleSaveBtnClick = async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment