diff options
-rw-r--r-- | src/store/reducers/userFriendsReducer.ts | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/store/reducers/userFriendsReducer.ts b/src/store/reducers/userFriendsReducer.ts index 2041a181..92402db1 100644 --- a/src/store/reducers/userFriendsReducer.ts +++ b/src/store/reducers/userFriendsReducer.ts @@ -11,8 +11,14 @@ const userFriendsSlice = createSlice({ updateFriends: (state, action) => { const {isFriend, data} = action.payload; - if (!isFriend) state.friends.push(data); - else { + if (!isFriend) { + const friendInList: boolean = state.friends.some( + (friend) => friend.username === data.username, + ); + if (!friendInList) { + state.friends.push(data); + } + } else { state.friends = state.friends.filter( (friend) => friend.username !== data.username, ); |