diff options
author | Ashm Walia <40498934+ashmgarv@users.noreply.github.com> | 2020-11-10 16:28:15 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-10 19:28:15 -0500 |
commit | 3362da273a4ffcc7d6362278bcb9fd919deda2b9 (patch) | |
tree | 6df5f6a0585fc327b0f378851f770b6d31aefebe /src/components/profile/ProfilePreview.tsx | |
parent | 9f048868f560dbd1672c1a504deb383ec601589e (diff) |
[TMA - 388] Block Users (Frontend) (#115)
* initial
* Final
* sc
* sc
* sall change
* Remove follow button when blocked
* Small change
* small changes again
Diffstat (limited to 'src/components/profile/ProfilePreview.tsx')
-rw-r--r-- | src/components/profile/ProfilePreview.tsx | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/components/profile/ProfilePreview.tsx b/src/components/profile/ProfilePreview.tsx index 9c953e7d..abc29422 100644 --- a/src/components/profile/ProfilePreview.tsx +++ b/src/components/profile/ProfilePreview.tsx @@ -7,12 +7,15 @@ import { StyleSheet, ViewProps, TouchableOpacity, + Alert, } from 'react-native'; import {useNavigation} from '@react-navigation/native'; import RNFetchBlob from 'rn-fetch-blob'; import AsyncStorage from '@react-native-community/async-storage'; import {AVATAR_PHOTO_ENDPOINT} from '../../constants'; import {UserType} from '../../types'; +import {AuthContext} from '../../routes/'; +import {isUserBlocked} from '../../services'; const NO_USER: UserType = { userId: '', username: '', @@ -38,6 +41,7 @@ const ProfilePreview: React.FC<ProfilePreviewProps> = ({ style, }) => { const navigation = useNavigation(); + const {user: loggedInUser, logout} = React.useContext(AuthContext); const [avatarURI, setAvatarURI] = useState<string | null>(null); const [user, setUser] = useState<UserType>(NO_USER); useEffect(() => { @@ -80,6 +84,16 @@ const ProfilePreview: React.FC<ProfilePreviewProps> = ({ * Cache maintains 10 recently searched users, popping off the oldest one if * needed to make space. */ + + const checkIfUserIsBlocked = async (userId: string) => { + const token = await AsyncStorage.getItem('token'); + if (!token) { + logout(); + return false; + } + return await isUserBlocked(userId, loggedInUser.userId, token); + }; + const addToRecentlyStoredAndNavigateToProfile = async () => { let user: ProfilePreviewType = { id, @@ -87,7 +101,14 @@ const ProfilePreview: React.FC<ProfilePreviewProps> = ({ first_name, last_name, }; + try { + //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; + } if (!isComment) { const jsonValue = await AsyncStorage.getItem( '@recently_searched_users', |