diff options
| author | Ivan Chen <ivan@thetaggid.com> | 2021-02-05 16:50:13 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-05 16:50:13 -0500 |
| commit | 55914efe03da970f03970a2a9fa85196fce41b75 (patch) | |
| tree | d475e92b463926fc4430b02fb80350aa50aefa1f /src/store/actions | |
| parent | f591dd437a1273d99709aa6a3637a3a2922e6f4d (diff) | |
| parent | 212eae20eb33d224525c52cea600b86fb2fd1126 (diff) | |
Merge pull request #212 from shravyaramesh/tma590-friendslist-buttons
[TMA-590] New Friends Screen
Diffstat (limited to 'src/store/actions')
| -rw-r--r-- | src/store/actions/userFriends.ts | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/store/actions/userFriends.ts b/src/store/actions/userFriends.ts index 18ad247c..763f2575 100644 --- a/src/store/actions/userFriends.ts +++ b/src/store/actions/userFriends.ts @@ -11,6 +11,7 @@ import { declineFriendRequestService, friendOrUnfriendUser, loadFriends, + unfriendService, } from '../../services'; import {Action, ThunkAction} from '@reduxjs/toolkit'; import { @@ -61,15 +62,17 @@ export const friendUnfriendUser = ( data = 'requested'; break; case 'requested': // cancel request: update to no relationship + break; case 'friends': // unfriend: update to no relationship dispatch({ type: updateFriends.type, payload: { - friend, + data: friend, isFriend: true, }, }); data = 'no_record'; + break; } dispatch({ type: userXFriendshipEdited.type, @@ -85,6 +88,39 @@ export const friendUnfriendUser = ( } }; +export const unfriendUser = ( + friend: ProfilePreviewType, // userX's profile preview + screenType: ScreenType, //screentype from content +): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async ( + dispatch, +) => { + try { + const token = await getTokenOrLogout(dispatch); + // Calls method to send post or delete request + const success = await unfriendService(friend.id, token); + if (success) { + let data = 'no_record'; + await dispatch({ + type: updateFriends.type, + payload: { + data: friend, + isFriend: true, + }, + }); + await dispatch({ + type: userXFriendshipEdited.type, + payload: { + userId: friend.id, + screenType, + data, + }, + }); + } + } catch (error) { + console.log(error); + } +}; + export const acceptFriendRequest = ( requester: ProfilePreviewType, ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async ( |
