aboutsummaryrefslogtreecommitdiff
path: root/src/store
diff options
context:
space:
mode:
Diffstat (limited to 'src/store')
-rw-r--r--src/store/actions/userFriends.ts65
1 files changed, 55 insertions, 10 deletions
diff --git a/src/store/actions/userFriends.ts b/src/store/actions/userFriends.ts
index 763f2575..054b7fbf 100644
--- a/src/store/actions/userFriends.ts
+++ b/src/store/actions/userFriends.ts
@@ -8,10 +8,10 @@ import {
} from '../../types/types';
import {
acceptFriendRequestService,
- declineFriendRequestService,
+ addFriendService,
friendOrUnfriendUser,
loadFriends,
- unfriendService,
+ deleteFriendshipService,
} from '../../services';
import {Action, ThunkAction} from '@reduxjs/toolkit';
import {
@@ -88,6 +88,34 @@ export const friendUnfriendUser = (
}
};
+export const addFriend = (
+ friend: ProfilePreviewType, // userX's profile preview
+ screenType: ScreenType, //screentype from content
+): ThunkAction<
+ Promise<boolean | undefined>,
+ RootState,
+ unknown,
+ Action<string>
+> => async (dispatch) => {
+ try {
+ const token = await getTokenOrLogout(dispatch);
+ const success = await addFriendService(friend.id, token);
+ if (success) {
+ dispatch({
+ type: userXFriendshipEdited.type,
+ payload: {
+ userId: friend.id,
+ screenType,
+ data: 'requested',
+ },
+ });
+ return true;
+ }
+ } catch (error) {
+ console.log(error);
+ }
+};
+
export const unfriendUser = (
friend: ProfilePreviewType, // userX's profile preview
screenType: ScreenType, //screentype from content
@@ -97,7 +125,8 @@ export const unfriendUser = (
try {
const token = await getTokenOrLogout(dispatch);
// Calls method to send post or delete request
- const success = await unfriendService(friend.id, token);
+ const reason = 'unfriended';
+ const success = await deleteFriendshipService(friend.id, reason, token);
if (success) {
let data = 'no_record';
await dispatch({
@@ -150,16 +179,32 @@ export const declineFriendRequest = (
) => {
try {
const token = await getTokenOrLogout(dispatch);
- const success = await declineFriendRequestService(user_id, token);
+ const reason = 'declined';
+ const success = await deleteFriendshipService(user_id, reason, token);
if (success) {
// Get profile of requester
console.log('declined request: ', success);
- // dispatch({
- // type: updateFriends.type,
- // payload: {
- // data: requester, // has to be a requester not id
- // },
- // });
+ } else {
+ console.log('Unsuccessful call');
+ }
+ } catch (error) {
+ console.log(error);
+ }
+};
+
+export const cancelFriendRequest = (
+ user_id: string,
+): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
+ dispatch,
+) => {
+ try {
+ console.log('cancelFriendRequest!');
+ const token = await getTokenOrLogout(dispatch);
+ const reason = 'cancelled';
+ const success = await deleteFriendshipService(user_id, reason, token);
+ if (success) {
+ // Get profile of requester
+ console.log('cancelled request: ', success);
} else {
console.log('Unsuccessful call');
}