diff options
author | Ivan Chen <ivan@tagg.id> | 2021-03-26 17:28:23 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-03-26 17:28:23 -0400 |
commit | 64f8829ab55bfe6851f10ca933043877769c56bf (patch) | |
tree | 1e28d37d626b85bf5f131f5a1f9e8b787f3cf069 | |
parent | 82acd049763452decdab0c40e6cf7286dd2ed57d (diff) |
show taggsbar, prevent taggsbar navigation on profile and SP
-rw-r--r-- | src/components/profile/Content.tsx | 28 | ||||
-rw-r--r-- | src/components/profile/PublicProfile.tsx | 5 | ||||
-rw-r--r-- | src/components/taggs/Tagg.tsx | 30 | ||||
-rw-r--r-- | src/components/taggs/TaggsBar.tsx | 4 | ||||
-rw-r--r-- | src/screens/suggestedPeople/SPBody.tsx | 14 | ||||
-rw-r--r-- | src/types/types.ts | 1 | ||||
-rw-r--r-- | src/utils/users.ts | 8 |
7 files changed, 60 insertions, 30 deletions
diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx index 8d77d798..9fb6f79b 100644 --- a/src/components/profile/Content.tsx +++ b/src/components/profile/Content.tsx @@ -22,6 +22,7 @@ import { import {RootState} from '../../store/rootreducer'; import {ContentProps} from '../../types'; import { + canViewProfile, fetchUserX, getUserAsProfilePreviewType, SCREEN_HEIGHT, @@ -81,7 +82,7 @@ const Content: React.FC<ContentProps> = ({y, userXId, screenType}) => { const isActuallyBlocked = blockedUsers.some( (cur_user) => user.username === cur_user.username, ); - if (isBlocked != isActuallyBlocked) { + if (isBlocked !== isActuallyBlocked) { setIsBlocked(isActuallyBlocked); } }, [blockedUsers, user]); @@ -110,16 +111,6 @@ const Content: React.FC<ContentProps> = ({y, userXId, screenType}) => { } }; - const canViewProfile = () => { - if (loggedInUser.userId === user.userId) { - return true; - } else if (profile.is_private && !isFriend) { - return false; - } else { - return true; - } - }; - const handleScroll = (e: NativeSyntheticEvent<NativeScrollEvent>) => { /** * Set the new y position @@ -165,7 +156,11 @@ const Content: React.FC<ContentProps> = ({y, userXId, screenType}) => { isBlocked, }} /> - {canViewProfile() ? ( + {canViewProfile( + loggedInUser.userId === user.userId, + profile.is_private, + isFriend, + ) ? ( <> <TaggsBar {...{y, profileBodyHeight, userXId, screenType}} @@ -174,7 +169,14 @@ const Content: React.FC<ContentProps> = ({y, userXId, screenType}) => { <PublicProfile {...{y, userXId, screenType}} /> </> ) : ( - <PrivateProfile /> + <> + <TaggsBar + {...{y, profileBodyHeight, userXId, screenType}} + whiteRing={undefined} + allowNavigation={false} + /> + <PrivateProfile /> + </> )} </Animated.ScrollView> ); diff --git a/src/components/profile/PublicProfile.tsx b/src/components/profile/PublicProfile.tsx index 4b5166f0..a70e8e50 100644 --- a/src/components/profile/PublicProfile.tsx +++ b/src/components/profile/PublicProfile.tsx @@ -2,7 +2,7 @@ import {useFocusEffect, useNavigation} from '@react-navigation/native'; import React, {useCallback, useEffect, useState} from 'react'; import {Alert, StyleSheet, Text, View} from 'react-native'; import {TouchableOpacity} from 'react-native-gesture-handler'; -import {useDispatch, useSelector, useStore} from 'react-redux'; +import {useDispatch, useSelector} from 'react-redux'; import GreyPlusLogo from '../../assets/icons/grey-plus-logo.svg'; import {TAGG_LIGHT_BLUE} from '../../constants'; import { @@ -17,7 +17,6 @@ import { } from '../../store/actions'; import { EMPTY_MOMENTS_LIST, - EMPTY_PROFILE_PREVIEW_LIST, NO_PROFILE, NO_USER, } from '../../store/initialStates'; @@ -159,7 +158,7 @@ const PublicProfile: React.FC<ContentProps> = ({y, userXId, screenType}) => { const createImagesMap = useCallback(() => { let map = new Map(); moments.forEach(function (imageObject) { - let moment_category = imageObject.moment_category; + let moment_category = imageObject.moment_category; if (map.has(moment_category)) { map.get(moment_category).push(imageObject); } else { diff --git a/src/components/taggs/Tagg.tsx b/src/components/taggs/Tagg.tsx index 547a77cb..ae9ab091 100644 --- a/src/components/taggs/Tagg.tsx +++ b/src/components/taggs/Tagg.tsx @@ -34,6 +34,7 @@ interface TaggProps { userXId: string | undefined; user: UserType; whiteRing: boolean | undefined; + allowNavigation?: boolean; } const Tagg: React.FC<TaggProps> = ({ @@ -45,6 +46,7 @@ const Tagg: React.FC<TaggProps> = ({ userXId, user, whiteRing, + allowNavigation = true, }) => { const navigation = useNavigation(); const [modalVisible, setModalVisible] = useState(false); @@ -70,19 +72,21 @@ const Tagg: React.FC<TaggProps> = ({ const modalOrAuthBrowserOrPass = async () => { if (youMayPass) { - if (INTEGRATED_SOCIAL_LIST.indexOf(social) !== -1) { - navigation.push('SocialMediaTaggs', { - socialMediaType: social, - userXId, - }); - } else { - getNonIntegratedURL(social, user.userId).then((socialURL) => { - if (socialURL) { - Linking.openURL(socialURL); - } else { - Alert.alert(ERROR_UNABLE_TO_FIND_PROFILE); - } - }); + if (allowNavigation) { + if (INTEGRATED_SOCIAL_LIST.indexOf(social) !== -1) { + navigation.push('SocialMediaTaggs', { + socialMediaType: social, + userXId, + }); + } else { + getNonIntegratedURL(social, user.userId).then((socialURL) => { + if (socialURL) { + Linking.openURL(socialURL); + } else { + Alert.alert(ERROR_UNABLE_TO_FIND_PROFILE); + } + }); + } } } else { if (isIntegrated) { diff --git a/src/components/taggs/TaggsBar.tsx b/src/components/taggs/TaggsBar.tsx index f952c53f..a9c428b2 100644 --- a/src/components/taggs/TaggsBar.tsx +++ b/src/components/taggs/TaggsBar.tsx @@ -22,6 +22,7 @@ interface TaggsBarProps { screenType: ScreenType; whiteRing: boolean | undefined; linkedSocials?: string[]; + allowNavigation?: boolean; } const TaggsBar: React.FC<TaggsBarProps> = ({ y, @@ -30,6 +31,7 @@ const TaggsBar: React.FC<TaggsBarProps> = ({ screenType, whiteRing, linkedSocials, + allowNavigation = true, }) => { let [taggs, setTaggs] = useState<Object[]>([]); let [taggsNeedUpdate, setTaggsNeedUpdate] = useState(true); @@ -79,6 +81,7 @@ const TaggsBar: React.FC<TaggsBarProps> = ({ setTaggsNeedUpdate={setTaggsNeedUpdate} setSocialDataNeedUpdate={handleSocialUpdate} whiteRing={whiteRing ? whiteRing : undefined} + allowNavigation={allowNavigation} />, ); i++; @@ -96,6 +99,7 @@ const TaggsBar: React.FC<TaggsBarProps> = ({ userXId={userXId} user={user} whiteRing={whiteRing ? whiteRing : undefined} + allowNavigation={allowNavigation} />, ); i++; diff --git a/src/screens/suggestedPeople/SPBody.tsx b/src/screens/suggestedPeople/SPBody.tsx index 8e0801c2..7bedb137 100644 --- a/src/screens/suggestedPeople/SPBody.tsx +++ b/src/screens/suggestedPeople/SPBody.tsx @@ -14,7 +14,13 @@ import { SuggestedPeopleDataType, UniversityBadge, } from '../../types'; -import {isIPhoneX, normalize, SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; +import { + canViewProfile, + isIPhoneX, + normalize, + SCREEN_HEIGHT, + SCREEN_WIDTH, +} from '../../utils'; interface SPBodyProps { item: SuggestedPeopleDataType; @@ -32,6 +38,7 @@ const SPBody: React.FC<SPBodyProps> = ({ suggested_people_url, friendship, badges, + is_private, }, itemIndex, onAddFriend, @@ -156,6 +163,11 @@ const SPBody: React.FC<SPBodyProps> = ({ screenType={screenType} whiteRing={true} linkedSocials={social_links} + allowNavigation={canViewProfile( + loggedInUserId === user.id, + is_private, + friendship.status === 'friends', + )} /> <View style={styles.marginManager}> <MutualFriends user={user} friends={mutual_friends} /> diff --git a/src/types/types.ts b/src/types/types.ts index e96d35a9..b2d39cd9 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -251,6 +251,7 @@ export type SuggestedPeopleDataType = { social_links: string[]; suggested_people_url: string; friendship: FriendshipType; + is_private: boolean; }; export type FriendshipType = { diff --git a/src/utils/users.ts b/src/utils/users.ts index d5e44b36..6cb6d46c 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -174,3 +174,11 @@ export const defaultUserProfile = () => { const defaultImage = require('../assets/images/avatar-placeholder.png'); return defaultImage; }; + +export const canViewProfile = ( + ownProfile: boolean, + isPrivate: boolean, + isFriend: boolean, +) => { + return ownProfile || isFriend || !isPrivate; +}; |