diff --git a/web/src/pages/MemoDetail.tsx b/web/src/pages/MemoDetail.tsx index e4d094cb8..935c40eb8 100644 --- a/web/src/pages/MemoDetail.tsx +++ b/web/src/pages/MemoDetail.tsx @@ -70,20 +70,12 @@ const MemoDetail = () => { } (async () => { - await fetchMemoComments(); + const commentRelations = memo.relationList.filter((relation) => relation.relatedMemoId === memo.id && relation.type === "COMMENT"); + const requests = commentRelations.map((relation) => memoStore.fetchMemoById(relation.memoId)); + await Promise.all(requests); })(); }, [memo?.relationList]); - const fetchMemoComments = async () => { - if (!memo) { - return; - } - - const commentRelations = memo.relationList.filter((relation) => relation.relatedMemoId === memo.id && relation.type === "COMMENT"); - const requests = commentRelations.map((relation) => memoStore.fetchMemoById(relation.memoId)); - await Promise.all(requests); - }; - if (!memo) { return null; } @@ -107,6 +99,10 @@ const MemoDetail = () => { toast.success(t("message.succeed-copy-link")); }; + const handleCommentCreated = async () => { + await memoStore.fetchMemoById(memoId); + }; + return ( <>
@@ -210,7 +206,7 @@ const MemoDetail = () => { key={memo.id} className="!border" relationList={[{ memoId: UNKNOWN_ID, relatedMemoId: memo.id, type: "COMMENT" }]} - onConfirm={() => fetchMemoComments()} + onConfirm={handleCommentCreated} /> )} diff --git a/web/src/store/reducer/memo.ts b/web/src/store/reducer/memo.ts index c4aaa8120..3f8718f03 100644 --- a/web/src/store/reducer/memo.ts +++ b/web/src/store/reducer/memo.ts @@ -14,7 +14,7 @@ const memoSlice = createSlice({ upsertMemos: (state, action: PayloadAction) => { return { ...state, - memos: uniqBy([...state.memos, ...action.payload], "id"), + memos: uniqBy([...action.payload, ...state.memos], "id"), }; }, createMemo: (state, action: PayloadAction) => { diff --git a/web/src/store/reducer/resource.ts b/web/src/store/reducer/resource.ts index 5f87c413d..b1709952b 100644 --- a/web/src/store/reducer/resource.ts +++ b/web/src/store/reducer/resource.ts @@ -21,7 +21,7 @@ const resourceSlice = createSlice({ upsertResources: (state, action: PayloadAction) => { return { ...state, - resources: uniqBy([...state.resources, ...action.payload], "id"), + resources: uniqBy([...action.payload, ...state.resources], "id"), }; }, patchResource: (state, action: PayloadAction>) => {