diff options
author | Ashm Walia <40498934+ashmgarv@users.noreply.github.com> | 2021-01-16 10:43:03 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-16 10:43:03 -0800 |
commit | ae9cbb026f6128e732d36138751e319c926c72b1 (patch) | |
tree | 4946280bb00f8081370c3602a404c041a7cc28d5 /src/components/profile/ProfilePreview.tsx | |
parent | 30391867438bb28cbcba9fc9ee2ff6d00027fd86 (diff) | |
parent | 23ccc2d6441aca0c89d0ba30e9d990b4aedb73cb (diff) |
Merge pull request #187 from shravyaramesh/tma538-friend-requests
[TMA485] friend request frontend
Diffstat (limited to 'src/components/profile/ProfilePreview.tsx')
-rw-r--r-- | src/components/profile/ProfilePreview.tsx | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/src/components/profile/ProfilePreview.tsx b/src/components/profile/ProfilePreview.tsx index 23cb2155..e6311daa 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'; import {ERROR_UNABLE_TO_VIEW_PROFILE} from '../../constants/strings'; @@ -73,15 +73,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 () => { @@ -93,13 +84,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(ERROR_UNABLE_TO_VIEW_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(ERROR_UNABLE_TO_VIEW_PROFILE); - return; - } const jsonValue = await AsyncStorage.getItem( '@recently_searched_users', ); |