From 89a270cedebaa36430d3f5bb9ccacb00e8e06b62 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 28 Feb 2024 00:34:55 +0800 Subject: [PATCH] chore: add username to cache key --- web/src/components/MemoEditor/index.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web/src/components/MemoEditor/index.tsx b/web/src/components/MemoEditor/index.tsx index 5ad6ac0a..b8125b70 100644 --- a/web/src/components/MemoEditor/index.tsx +++ b/web/src/components/MemoEditor/index.tsx @@ -6,6 +6,7 @@ import useLocalStorage from "react-use/lib/useLocalStorage"; import { memoServiceClient } from "@/grpcweb"; import { TAB_SPACE_WIDTH, UNKNOWN_ID } from "@/helpers/consts"; import { isValidUrl } from "@/helpers/utils"; +import useCurrentUser from "@/hooks/useCurrentUser"; import { useGlobalStore, useResourceStore, useTagStore } from "@/store/module"; import { useMemoStore, useUserStore } from "@/store/v1"; import { MemoRelation, MemoRelation_Type } from "@/types/proto/api/v2/memo_relation_service"; @@ -50,8 +51,6 @@ const MemoEditor = (props: Props) => { const { className, editorClassName, cacheKey, memoId, parentMemoId, autoFocus, onConfirm } = props; const { i18n } = useTranslation(); const t = useTranslate(); - const contentCacheKey = `memo-editor-${cacheKey}`; - const [contentCache, setContentCache] = useLocalStorage(contentCacheKey, ""); const { state: { systemStatus }, } = useGlobalStore(); @@ -59,6 +58,7 @@ const MemoEditor = (props: Props) => { const memoStore = useMemoStore(); const resourceStore = useResourceStore(); const tagStore = useTagStore(); + const currentUser = useCurrentUser(); const [state, setState] = useState({ memoVisibility: Visibility.PRIVATE, resourceList: [], @@ -69,6 +69,8 @@ const MemoEditor = (props: Props) => { const [hasContent, setHasContent] = useState(false); const editorRef = useRef(null); const userSetting = userStore.userSetting as UserSetting; + const contentCacheKey = `${currentUser.name}-${cacheKey || ""}`; + const [contentCache, setContentCache] = useLocalStorage(contentCacheKey, ""); const referenceRelations = memoId ? state.relationList.filter( (relation) => relation.memoId === memoId && relation.relatedMemoId !== memoId && relation.type === MemoRelation_Type.REFERENCE,