diff options
| author | Ashm Walia <ashmwalia@outlook.com> | 2021-01-15 19:04:07 -0800 |
|---|---|---|
| committer | Ashm Walia <ashmwalia@outlook.com> | 2021-01-15 19:04:07 -0800 |
| commit | 72aabf60d815cdecf59aaef86df57be6a557efd0 (patch) | |
| tree | 4fac8f3fe8c44d0730fa3d7707500aa1a68afcd0 /src/components/profile | |
| parent | ed91266981e1662b512baa1856d8c921a8718e68 (diff) | |
Done
Diffstat (limited to 'src/components/profile')
| -rw-r--r-- | src/components/profile/Content.tsx | 25 | ||||
| -rw-r--r-- | src/components/profile/ProfileBody.tsx | 4 | ||||
| -rw-r--r-- | src/components/profile/ProfilePreview.tsx | 27 |
3 files changed, 15 insertions, 41 deletions
diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx index f7b4b71c..cc9849e6 100644 --- a/src/components/profile/Content.tsx +++ b/src/components/profile/Content.tsx @@ -42,6 +42,7 @@ import { updateUserXFriends, updateMomentCategories, deleteUserMomentsForCategory, + updateUserXProfileAllScreens, } from '../../store/actions'; import { NO_USER, @@ -214,29 +215,6 @@ const Content: React.FC<ContentProps> = ({y, userXId, screenType}) => { } }, [blockedUsers, user]); - // /** - // * The object returned by this method is added to the list of blocked / friended users by the reducer. - // * Which helps us prevent an extra api call to the backend just to fetch a user. - // */ - // const getUserAsProfilePreviewType = ( - // passedInUser: UserType, - // passedInProfile: ProfileType, - // ): ProfilePreviewType => { - // const fullName = passedInProfile.name.split(' '); - // return { - // id: passedInUser.userId, - // username: passedInUser.username, - // first_name: fullName[0], - // last_name: fullName[1], - // }; - // }; - - /** - * Handles a click on the friend / unfriend button. - * friendUnfriendUser takes care of updating the friends list for loggedInUser - * updateUserXFriends updates friends list for the new friend. - */ - // Handles click on friend/requested/unfriend button /* * When user logged in clicks on the friend button: @@ -259,6 +237,7 @@ const Content: React.FC<ContentProps> = ({y, userXId, screenType}) => { ), ); await dispatch(updateUserXFriends(user.userId, state)); + dispatch(updateUserXProfileAllScreens(user.userId, state)); }; /** diff --git a/src/components/profile/ProfileBody.tsx b/src/components/profile/ProfileBody.tsx index edda5d43..4076e473 100644 --- a/src/components/profile/ProfileBody.tsx +++ b/src/components/profile/ProfileBody.tsx @@ -62,7 +62,7 @@ const ProfileBody: React.FC<ProfileBodyProps> = ({ acceptFriendRequest({id, username, first_name, last_name}), ); await dispatch(updateUserXFriends(id, state)); - dispatch(updateUserXProfileAllScreens(id)); + dispatch(updateUserXProfileAllScreens(id, state)); } catch (err) { console.log(err); } @@ -70,7 +70,7 @@ const ProfileBody: React.FC<ProfileBodyProps> = ({ const handleDeclineFriendRequest = async () => { await dispatch(declineFriendRequest(id)); - dispatch(updateUserXProfileAllScreens(id)); + dispatch(updateUserXProfileAllScreens(id, state)); }; return ( diff --git a/src/components/profile/ProfilePreview.tsx b/src/components/profile/ProfilePreview.tsx index 6f008540..0d8d9852 100644 --- a/src/components/profile/ProfilePreview.tsx +++ b/src/components/profile/ProfilePreview.tsx @@ -18,7 +18,7 @@ import {isUserBlocked, loadAvatar} from '../../services'; import {useSelector, useDispatch, useStore} from 'react-redux'; import {RootState} from '../../store/rootreducer'; import {logout} from '../../store/actions'; -import {fetchUserX, userXInStore} from '../../utils'; +import {checkIfUserIsBlocked, fetchUserX, userXInStore} from '../../utils'; import {SearchResultsBackground} from '../search'; import NavigationBar from 'src/routes/tabs'; @@ -72,15 +72,6 @@ const ProfilePreview: React.FC<ProfilePreviewProps> = ({ * needed to make space. */ - const checkIfUserIsBlocked = async (userId: string) => { - const token = await AsyncStorage.getItem('token'); - if (!token) { - dispatch(logout()); - return false; - } - return await isUserBlocked(userId, loggedInUser.userId, token); - }; - const state: RootState = useStore().getState(); const addToRecentlyStoredAndNavigateToProfile = async () => { @@ -92,13 +83,17 @@ const ProfilePreview: React.FC<ProfilePreviewProps> = ({ }; try { + //If the logged in user is blocked by the user being viewed, do not proceed. + const isUserBlocked = await checkIfUserIsBlocked( + user.id, + dispatch, + loggedInUser, + ); + if (isUserBlocked) { + Alert.alert('You cannot view this profile'); + return; + } if (previewType !== 'Comment') { - //If the logged in user is blocked by the user being viewed, do not proceed. - const isUserBlocked = await checkIfUserIsBlocked(user.id); - if (isUserBlocked) { - Alert.alert('You cannot view this profile'); - return; - } const jsonValue = await AsyncStorage.getItem( '@recently_searched_users', ); |
