From b5d8f2b9e13ef4e45245370798dcdabf24de56b9 Mon Sep 17 00:00:00 2001 From: Harshil Sharma <18575143+harshilsharma63@users.noreply.github.com> Date: Tue, 5 Jul 2022 13:24:31 +0530 Subject: [PATCH] Fixed a bug where rmeoved board members showed up in comment list (#3223) * Fixed a bug where rmeoved board members showed up in comment list * Review fixes --- webapp/src/mutator.ts | 6 ++++++ webapp/src/store/boards.ts | 9 +++++++-- webapp/src/store/users.ts | 7 ++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/webapp/src/mutator.ts b/webapp/src/mutator.ts index 0d306488e..97bdc30df 100644 --- a/webapp/src/mutator.ts +++ b/webapp/src/mutator.ts @@ -28,6 +28,7 @@ import {updateViews} from './store/views' import {updateCards} from './store/cards' import {updateComments} from './store/comments' import {updateContents} from './store/contents' +import {addBoardUsers, removeBoardUsersById} from "./store/users" function updateAllBoardsAndBlocks(boards: Board[], blocks: Block[]) { return batch(() => { @@ -384,9 +385,14 @@ class Mutator { await undoManager.perform( async () => { await octoClient.deleteBoardMember(member) + store.dispatch(removeBoardUsersById([member.userId])) }, async () => { await octoClient.createBoardMember(member) + const user = await octoClient.getUser(member.userId) + if (user) { + store.dispatch(addBoardUsers([user])) + } }, description, this.undoGroupId, diff --git a/webapp/src/store/boards.ts b/webapp/src/store/boards.ts index d536ccd19..72c1a57ab 100644 --- a/webapp/src/store/boards.ts +++ b/webapp/src/store/boards.ts @@ -9,7 +9,7 @@ import {IUser} from '../user' import {initialLoad, initialReadOnlyLoad, loadBoardData} from './initialLoad' -import {addBoardUsers, setBoardUsers} from './users' +import {addBoardUsers, removeBoardUsersById, setBoardUsers} from './users' import {RootState} from './index' @@ -81,7 +81,12 @@ export const updateMembersEnsuringBoardsAndUsers = createAsyncThunk( } const user = await client.getUser(m.userId) if (user) { - thunkAPI.dispatch(addBoardUsers([user])) + const deleted = !m.schemeAdmin && !m.schemeEditor && !m.schemeViewer && !m.schemeCommenter + if (deleted) { + thunkAPI.dispatch(removeBoardUsersById([user.id])) + } else { + thunkAPI.dispatch(addBoardUsers([user])) + } } }) diff --git a/webapp/src/store/users.ts b/webapp/src/store/users.ts index a964e1ef7..fd1d31430 100644 --- a/webapp/src/store/users.ts +++ b/webapp/src/store/users.ts @@ -60,6 +60,11 @@ const usersSlice = createSlice({ state.boardUsers[user.id] = user }) }, + removeBoardUsersById: (state, action: PayloadAction) => { + action.payload.forEach((userId: string) => { + delete state.boardUsers[userId] + }) + }, followBlock: (state, action: PayloadAction) => { state.blockSubscriptions.push(action.payload) }, @@ -97,7 +102,7 @@ const usersSlice = createSlice({ }, }) -export const {setMe, setBoardUsers, addBoardUsers, followBlock, unfollowBlock, patchProps} = usersSlice.actions +export const {setMe, setBoardUsers, removeBoardUsersById, addBoardUsers, followBlock, unfollowBlock, patchProps} = usersSlice.actions export const {reducer} = usersSlice export const getMe = (state: RootState): IUser|null => state.users.me