From 96fda980905d0c7a30813c364c6623dda695012f Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 29 Jan 2021 15:14:26 -0800 Subject: full screen; with button; needs refresh&alignment; --- src/utils/friends.ts | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/utils/index.ts | 1 + 2 files changed, 66 insertions(+) create mode 100644 src/utils/friends.ts (limited to 'src/utils') 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'; -- cgit v1.2.3-70-g09d2 From 7361492c3d25f71bb444f5f7e35b3113647318f9 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Mon, 1 Feb 2021 22:02:25 -0800 Subject: fullscreen friends + unfriend button --- src/components/profile/Content.tsx | 2 -- src/components/profile/Friends.tsx | 46 ++++++++++++++----------------- src/components/profile/ProfilePreview.tsx | 12 ++++++-- src/screens/profile/FriendsListScreen.tsx | 13 ++++----- src/store/actions/userFriends.ts | 2 +- src/utils/friends.ts | 3 +- 6 files changed, 36 insertions(+), 42 deletions(-) (limited to 'src/utils') diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx index 56ae1e51..28000dd7 100644 --- a/src/components/profile/Content.tsx +++ b/src/components/profile/Content.tsx @@ -25,11 +25,9 @@ import { import { blockUnblockUser, deleteUserMomentsForCategory, - friendUnfriendUser, loadFriendsData, updateMomentCategories, updateUserXFriends, - updateUserXProfileAllScreens, } from '../../store/actions'; import { EMPTY_MOMENTS_LIST, diff --git a/src/components/profile/Friends.tsx b/src/components/profile/Friends.tsx index ec2b6a68..44ce4e63 100644 --- a/src/components/profile/Friends.tsx +++ b/src/components/profile/Friends.tsx @@ -1,27 +1,27 @@ import React from 'react'; -import {View, StyleSheet, Text, ScrollView} from 'react-native'; +import {View, StyleSheet, ScrollView} from 'react-native'; import {ProfilePreviewType, ScreenType} from '../../types'; import {ProfilePreview} from '..'; -import {useNavigation} from '@react-navigation/native'; import {Button} from 'react-native-elements'; -import {SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; +import {normalize, SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; import {TAGG_LIGHT_BLUE} from '../../constants'; import {RootState} from '../../store/rootReducer'; import {useDispatch, useStore} from 'react-redux'; import {handleUnfriend} from '../../utils/friends'; +import {NO_USER} from '../../store/initialStates'; interface FriendsProps { result: Array; screenType: ScreenType; - userXId: string; + userId: string; } -const Friends: React.FC = ({result, screenType, userXId}) => { - const navigation = useNavigation(); - +const Friends: React.FC = ({result, screenType, userId}) => { const state: RootState = useStore().getState(); const dispatch = useDispatch(); + const {user: loggedInUser = NO_USER} = state; + return ( = ({result, screenType, userXId}) => { previewType={'Friend'} screenType={screenType} /> -