From e43eb6bdba34244df665725082dac96e0cf0d877 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Wed, 14 Jul 2021 21:22:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=94=A8=E6=88=B7=E5=A5=BD?= =?UTF-8?q?=E5=8F=8B=E8=AF=B7=E6=B1=82=E9=80=9A=E7=9F=A5=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/redux/setup.ts | 11 +++++++++++ shared/redux/slices/user.ts | 15 +++++++++++++++ web/src/styles/overwrite.less | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/shared/redux/setup.ts b/shared/redux/setup.ts index 3d0ef9de..ad9e0267 100644 --- a/shared/redux/setup.ts +++ b/shared/redux/setup.ts @@ -24,4 +24,15 @@ export function setupRedux(socket: AppSocket, store: AppStore) { } store.dispatch(userActions.appendFriend(userId)); }); + + socket.listen('friend.request.add', (request) => { + store.dispatch(userActions.appendFriendRequest(request)); + }); + + socket.listen<{ requestId: string }>( + 'friend.request.remove', + ({ requestId }) => { + store.dispatch(userActions.removeFriendRequest(requestId)); + } + ); } diff --git a/shared/redux/slices/user.ts b/shared/redux/slices/user.ts index 8bbbbd69..5c65e7ed 100644 --- a/shared/redux/slices/user.ts +++ b/shared/redux/slices/user.ts @@ -30,6 +30,21 @@ const userSlice = createSlice({ state.friends.push(action.payload); }, + appendFriendRequest(state, action: PayloadAction) { + if (state.friendRequests.some(({ _id }) => _id === action.payload._id)) { + return; + } + + state.friendRequests.push(action.payload); + }, + removeFriendRequest(state, action: PayloadAction) { + const index = state.friendRequests.findIndex( + ({ _id }) => _id === action.payload + ); + if (index >= 0) { + state.friendRequests.splice(index, 1); + } + }, }, }); diff --git a/web/src/styles/overwrite.less b/web/src/styles/overwrite.less index 3d05d69b..6b186c25 100644 --- a/web/src/styles/overwrite.less +++ b/web/src/styles/overwrite.less @@ -7,6 +7,6 @@ vertical-align: text-top; } -.ant-typography-expand { +.ant-typography-expand, .ant-typography-copy { vertical-align: text-bottom; }