diff options
| author | Ivan Chen <ivan@tagg.id> | 2021-02-05 17:35:05 -0500 |
|---|---|---|
| committer | Ivan Chen <ivan@tagg.id> | 2021-02-05 17:35:05 -0500 |
| commit | 231fed8c645dc29334b946dccca94fbb13116fe2 (patch) | |
| tree | fc7bcd0f9e11b943d89877c621e95681e89a18d7 /src/store/actions | |
| parent | a5f746525df9bb2967c252b70e7a4e2f9daa2b8d (diff) | |
| parent | bad7fac394f8ef2870a9a139fd46d0def4421bf1 (diff) | |
Merge branch 'master' into TMA-579-Redesign-Snapchat-Tiktok
# Conflicts:
# src/components/common/TaggSquareButton.tsx
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 ( |
