From 9d4da24e6c659b1b121574ffe7195c68739b416f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Fri, 13 Aug 2021 15:39:57 +0200 Subject: [PATCH] Cleanup the store on the initial load call (#970) --- webapp/src/store/boards.ts | 4 ++++ webapp/src/store/cards.ts | 4 ++++ webapp/src/store/comments.ts | 2 ++ webapp/src/store/contents.ts | 2 ++ webapp/src/store/views.ts | 2 ++ 5 files changed, 14 insertions(+) diff --git a/webapp/src/store/boards.ts b/webapp/src/store/boards.ts index 987b6f700..c0d57a061 100644 --- a/webapp/src/store/boards.ts +++ b/webapp/src/store/boards.ts @@ -37,6 +37,8 @@ const boardsSlice = createSlice({ }, extraReducers: (builder) => { builder.addCase(initialReadOnlyLoad.fulfilled, (state, action) => { + state.boards = {} + state.templates = {} for (const block of action.payload) { if (block.type === 'board' && block.fields.isTemplate) { state.templates[block.id] = block as Board @@ -46,6 +48,8 @@ const boardsSlice = createSlice({ } }) builder.addCase(initialLoad.fulfilled, (state, action) => { + state.boards = {} + state.templates = {} for (const block of action.payload.blocks) { if (block.type === 'board' && block.fields.isTemplate) { state.templates[block.id] = block as Board diff --git a/webapp/src/store/cards.ts b/webapp/src/store/cards.ts index 29f73edaf..0cbd2fcac 100644 --- a/webapp/src/store/cards.ts +++ b/webapp/src/store/cards.ts @@ -57,6 +57,8 @@ const cardsSlice = createSlice({ }, extraReducers: (builder) => { builder.addCase(initialReadOnlyLoad.fulfilled, (state, action) => { + state.cards = {} + state.templates = {} for (const block of action.payload) { if (block.type === 'card' && block.fields.isTemplate) { state.templates[block.id] = block as Card @@ -66,6 +68,8 @@ const cardsSlice = createSlice({ } }) builder.addCase(initialLoad.fulfilled, (state, action) => { + state.cards = {} + state.templates = {} for (const block of action.payload.blocks) { if (block.type === 'card' && block.fields.isTemplate) { state.templates[block.id] = block as Card diff --git a/webapp/src/store/comments.ts b/webapp/src/store/comments.ts index cb580ddfa..e49274b6c 100644 --- a/webapp/src/store/comments.ts +++ b/webapp/src/store/comments.ts @@ -25,6 +25,7 @@ const commentsSlice = createSlice({ }, extraReducers: (builder) => { builder.addCase(initialReadOnlyLoad.fulfilled, (state, action) => { + state.comments = {} for (const block of action.payload) { if (block.type === 'comment') { state.comments[block.id] = block as CommentBlock @@ -32,6 +33,7 @@ const commentsSlice = createSlice({ } }) builder.addCase(initialLoad.fulfilled, (state, action) => { + state.comments = {} for (const block of action.payload.blocks) { if (block.type === 'comment') { state.comments[block.id] = block as CommentBlock diff --git a/webapp/src/store/contents.ts b/webapp/src/store/contents.ts index f9639f6f7..9cf3c7721 100644 --- a/webapp/src/store/contents.ts +++ b/webapp/src/store/contents.ts @@ -26,6 +26,7 @@ const contentsSlice = createSlice({ }, extraReducers: (builder) => { builder.addCase(initialReadOnlyLoad.fulfilled, (state, action) => { + state.contents = {} for (const block of action.payload) { if (block.type !== 'board' && block.type !== 'view' && block.type !== 'comment') { state.contents[block.id] = block as ContentBlock @@ -33,6 +34,7 @@ const contentsSlice = createSlice({ } }) builder.addCase(initialLoad.fulfilled, (state, action) => { + state.contents = {} for (const block of action.payload.blocks) { if (block.type !== 'board' && block.type !== 'view' && block.type !== 'comment') { state.contents[block.id] = block as ContentBlock diff --git a/webapp/src/store/views.ts b/webapp/src/store/views.ts index 943f2c71d..fafb013db 100644 --- a/webapp/src/store/views.ts +++ b/webapp/src/store/views.ts @@ -37,6 +37,7 @@ const viewsSlice = createSlice({ }, extraReducers: (builder) => { builder.addCase(initialReadOnlyLoad.fulfilled, (state, action) => { + state.views = {} for (const block of action.payload) { if (block.type === 'view') { state.views[block.id] = block as BoardView @@ -44,6 +45,7 @@ const viewsSlice = createSlice({ } }) builder.addCase(initialLoad.fulfilled, (state, action) => { + state.views = {} for (const block of action.payload.blocks) { if (block.type === 'view') { state.views[block.id] = block as BoardView