Cleanup the store on the initial load call (#970)

This commit is contained in:
Jesús Espino 2021-08-13 15:39:57 +02:00 committed by GitHub
parent 1f36db5579
commit 9d4da24e6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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