diff options
author | Shravya Ramesh <shravs1208@gmail.com> | 2021-02-05 12:07:02 -0800 |
---|---|---|
committer | Shravya Ramesh <shravs1208@gmail.com> | 2021-02-05 12:07:02 -0800 |
commit | 212eae20eb33d224525c52cea600b86fb2fd1126 (patch) | |
tree | 43b3e25ae960ebef29217e0a9ab872b5d89e47c1 /src | |
parent | 951c62d8573fbef56a4f7d27ad3fbde57cec0b9e (diff) |
checks if user already in friendlist before update
Diffstat (limited to 'src')
-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, ); |