refactor: 用户好友请求通知管理

pull/13/head
moonrailgun 4 years ago
parent 2a12916428
commit e43eb6bdba

@ -24,4 +24,15 @@ export function setupRedux(socket: AppSocket, store: AppStore) {
}
store.dispatch(userActions.appendFriend(userId));
});
socket.listen<FriendRequest>('friend.request.add', (request) => {
store.dispatch(userActions.appendFriendRequest(request));
});
socket.listen<{ requestId: string }>(
'friend.request.remove',
({ requestId }) => {
store.dispatch(userActions.removeFriendRequest(requestId));
}
);
}

@ -30,6 +30,21 @@ const userSlice = createSlice({
state.friends.push(action.payload);
},
appendFriendRequest(state, action: PayloadAction<FriendRequest>) {
if (state.friendRequests.some(({ _id }) => _id === action.payload._id)) {
return;
}
state.friendRequests.push(action.payload);
},
removeFriendRequest(state, action: PayloadAction<string>) {
const index = state.friendRequests.findIndex(
({ _id }) => _id === action.payload
);
if (index >= 0) {
state.friendRequests.splice(index, 1);
}
},
},
});

@ -7,6 +7,6 @@
vertical-align: text-top;
}
.ant-typography-expand {
.ant-typography-expand, .ant-typography-copy {
vertical-align: text-bottom;
}

Loading…
Cancel
Save