aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorShravya Ramesh <shravs1208@gmail.com>2021-01-29 15:14:26 -0800
committerShravya Ramesh <shravs1208@gmail.com>2021-01-29 15:14:26 -0800
commit96fda980905d0c7a30813c364c6623dda695012f (patch)
tree8a29aca6c75d38ac52c6d941a427a9b55e69dc78 /src/utils
parent77002bb0e78d5c47e6daca14e8c699706a3f94a2 (diff)
full screen; with button; needs refresh&alignment;
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/friends.ts65
-rw-r--r--src/utils/index.ts1
2 files changed, 66 insertions, 0 deletions
diff --git a/src/utils/friends.ts b/src/utils/friends.ts
new file mode 100644
index 00000000..c10cf1de
--- /dev/null
+++ b/src/utils/friends.ts
@@ -0,0 +1,65 @@
+// Handles click on friend/requested/unfriend button
+
+import {useSelector} from 'react-redux';
+import {RootState} from '../store/rootReducer';
+import {NO_USER} from '../store/initialStates';
+import {ProfilePreviewType, ProfileType, ScreenType, UserType} from '../types';
+import {AppDispatch} from '../store/configureStore';
+import {
+ friendUnfriendUser,
+ unfriendUser,
+ updateUserXFriends,
+ updateUserXProfileAllScreens,
+} from '../store/actions';
+import {getUserAsProfilePreviewType} from './users';
+
+/*
+ * When user logged in clicks on the friend button:
+ A request is sent.
+ Which means you have to update the status of their friendshpi to requested
+ When the status is changed to requested the button should change to requested.
+ When the button is changed to requested and thr user clicks on it,
+ a request much go to the backend to delete that request
+ When that succeeds, their friendship must be updated to no-record again;
+ When the button is changed to no_record, the add friends button should be displayed again
+ */
+export const handleFriendUnfriend = async (
+ screenType: ScreenType,
+ user: UserType,
+ profile: ProfileType,
+ dispatch: AppDispatch,
+ state: RootState,
+ loggedInUser: UserType,
+) => {
+ const {friendship_status} = profile;
+ await dispatch(
+ friendUnfriendUser(
+ loggedInUser,
+ getUserAsProfilePreviewType(user, profile),
+ friendship_status,
+ screenType,
+ ),
+ );
+ await dispatch(updateUserXFriends(user.userId, state));
+ dispatch(updateUserXProfileAllScreens(user.userId, state));
+};
+
+/*
+ * When user logged in clicks on the friend button:
+ A request is sent.
+ Which means you have to update the status of their friendshpi to requested
+ When the status is changed to requested the button should change to requested.
+ When the button is changed to requested and thr user clicks on it,
+ a request much go to the backend to delete that request
+ When that succeeds, their friendship must be updated to no-record again;
+ When the button is changed to no_record, the add friends button should be displayed again
+ */
+export const handleUnfriend = async (
+ screenType: ScreenType,
+ friend: ProfilePreviewType,
+ dispatch: AppDispatch,
+ state: RootState,
+) => {
+ await dispatch(unfriendUser(friend, screenType));
+ await dispatch(updateUserXFriends(friend.id, state));
+};
diff --git a/src/utils/index.ts b/src/utils/index.ts
index 629a0091..82c94100 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -2,3 +2,4 @@ export * from './layouts';
export * from './moments';
export * from './common';
export * from './users';
+export * from './friends';