From 568f08d610b81a46cba0ed5ffaae58361f4a65e1 Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Wed, 31 Aug 2022 10:51:54 -0600 Subject: [PATCH] update to break and not push to parent if already exists --- webapp/src/store/contents.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webapp/src/store/contents.ts b/webapp/src/store/contents.ts index c2d9df117..f393f1095 100644 --- a/webapp/src/store/contents.ts +++ b/webapp/src/store/contents.ts @@ -22,6 +22,7 @@ const contentsSlice = createSlice({ updateContents: (state, action: PayloadAction) => { for (const content of action.payload) { if (content.deleteAt === 0) { + let existsInParent = false state.contents[content.id] = content if (!state.contentsByCard[content.parentId]) { state.contentsByCard[content.parentId] = [content] @@ -30,9 +31,13 @@ const contentsSlice = createSlice({ for (let i = 0; i < state.contentsByCard[content.parentId].length; i++) { if (state.contentsByCard[content.parentId][i].id === content.id) { state.contentsByCard[content.parentId][i] = content + existsInParent = true + break } } - state.contentsByCard[content.parentId].push(content) + if( !existsInParent ){ + state.contentsByCard[content.parentId].push(content) + } } else { const parentId = state.contents[content.id]?.parentId if (!state.contentsByCard[parentId]) {