Commit 8aae0d00 authored by Steven's avatar Steven

chore: fix fetch comments

parent 16dad8b0
...@@ -70,20 +70,12 @@ const MemoDetail = () => { ...@@ -70,20 +70,12 @@ const MemoDetail = () => {
} }
(async () => { (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]); }, [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) { if (!memo) {
return null; return null;
} }
...@@ -107,6 +99,10 @@ const MemoDetail = () => { ...@@ -107,6 +99,10 @@ const MemoDetail = () => {
toast.success(t("message.succeed-copy-link")); toast.success(t("message.succeed-copy-link"));
}; };
const handleCommentCreated = async () => {
await memoStore.fetchMemoById(memoId);
};
return ( return (
<> <>
<section className="relative top-0 w-full min-h-full overflow-x-hidden bg-zinc-100 dark:bg-zinc-900"> <section className="relative top-0 w-full min-h-full overflow-x-hidden bg-zinc-100 dark:bg-zinc-900">
...@@ -210,7 +206,7 @@ const MemoDetail = () => { ...@@ -210,7 +206,7 @@ const MemoDetail = () => {
key={memo.id} key={memo.id}
className="!border" className="!border"
relationList={[{ memoId: UNKNOWN_ID, relatedMemoId: memo.id, type: "COMMENT" }]} relationList={[{ memoId: UNKNOWN_ID, relatedMemoId: memo.id, type: "COMMENT" }]}
onConfirm={() => fetchMemoComments()} onConfirm={handleCommentCreated}
/> />
)} )}
</div> </div>
......
...@@ -14,7 +14,7 @@ const memoSlice = createSlice({ ...@@ -14,7 +14,7 @@ const memoSlice = createSlice({
upsertMemos: (state, action: PayloadAction<Memo[]>) => { upsertMemos: (state, action: PayloadAction<Memo[]>) => {
return { return {
...state, ...state,
memos: uniqBy([...state.memos, ...action.payload], "id"), memos: uniqBy([...action.payload, ...state.memos], "id"),
}; };
}, },
createMemo: (state, action: PayloadAction<Memo>) => { createMemo: (state, action: PayloadAction<Memo>) => {
......
...@@ -21,7 +21,7 @@ const resourceSlice = createSlice({ ...@@ -21,7 +21,7 @@ const resourceSlice = createSlice({
upsertResources: (state, action: PayloadAction<Resource[]>) => { upsertResources: (state, action: PayloadAction<Resource[]>) => {
return { return {
...state, ...state,
resources: uniqBy([...state.resources, ...action.payload], "id"), resources: uniqBy([...action.payload, ...state.resources], "id"),
}; };
}, },
patchResource: (state, action: PayloadAction<Partial<Resource>>) => { patchResource: (state, action: PayloadAction<Partial<Resource>>) => {
......
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