From f662d1cd85447de0f6be945a350d1f2d1be5033e Mon Sep 17 00:00:00 2001 From: ankit-thanekar007 Date: Wed, 17 Mar 2021 11:07:45 -0700 Subject: Separated Private and Public Profiles --- src/assets/images/private-profile.png | Bin 0 -> 3750 bytes src/assets/images/private-profile@2x.png | Bin 0 -> 7999 bytes src/assets/images/private-profile@3x.png | Bin 0 -> 10081 bytes src/components/common/TaggPrompt.tsx | 2 +- src/components/profile/Content.tsx | 281 ++--------------------------- src/components/profile/PrivateProfile.tsx | 33 ++++ src/components/profile/PublicProfile.tsx | 284 ++++++++++++++++++++++++++++++ src/constants/strings.ts | 1 + src/types/types.ts | 7 + 9 files changed, 342 insertions(+), 266 deletions(-) create mode 100644 src/assets/images/private-profile.png create mode 100644 src/assets/images/private-profile@2x.png create mode 100644 src/assets/images/private-profile@3x.png create mode 100644 src/components/profile/PrivateProfile.tsx create mode 100644 src/components/profile/PublicProfile.tsx (limited to 'src') diff --git a/src/assets/images/private-profile.png b/src/assets/images/private-profile.png new file mode 100644 index 00000000..820ba287 Binary files /dev/null and b/src/assets/images/private-profile.png differ diff --git a/src/assets/images/private-profile@2x.png b/src/assets/images/private-profile@2x.png new file mode 100644 index 00000000..cdcf44d5 Binary files /dev/null and b/src/assets/images/private-profile@2x.png differ diff --git a/src/assets/images/private-profile@3x.png b/src/assets/images/private-profile@3x.png new file mode 100644 index 00000000..f909fe2a Binary files /dev/null and b/src/assets/images/private-profile@3x.png differ diff --git a/src/components/common/TaggPrompt.tsx b/src/components/common/TaggPrompt.tsx index d65e30c6..6169b3f1 100644 --- a/src/components/common/TaggPrompt.tsx +++ b/src/components/common/TaggPrompt.tsx @@ -66,7 +66,7 @@ const styles = StyleSheet.create({ justifyContent: 'center', alignItems: 'center', backgroundColor: 'white', - height: SCREEN_HEIGHT / 4.5, + height: SCREEN_HEIGHT / 4, }, closeButton: { position: 'relative', diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx index 1a5a205c..860e16c5 100644 --- a/src/components/profile/Content.tsx +++ b/src/components/profile/Content.tsx @@ -1,62 +1,39 @@ -import {useFocusEffect, useNavigation} from '@react-navigation/native'; import React, {useCallback, useEffect, useState} from 'react'; import { - Alert, LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent, RefreshControl, StyleSheet, - Text, - View, } from 'react-native'; -import {TouchableOpacity} from 'react-native-gesture-handler'; import Animated from 'react-native-reanimated'; import {useDispatch, useSelector, useStore} from 'react-redux'; -import Cover from './Cover'; -import GreyPlusLogo from '../../assets/icons/grey-plus-logo.svg'; -import {COVER_HEIGHT, TAGG_LIGHT_BLUE} from '../../constants'; -import { - UPLOAD_MOMENT_PROMPT_THREE_HEADER, - UPLOAD_MOMENT_PROMPT_THREE_MESSAGE, - UPLOAD_MOMENT_PROMPT_TWO_HEADER, - UPLOAD_MOMENT_PROMPT_TWO_MESSAGE, -} from '../../constants/strings'; +import {COVER_HEIGHT} from '../../constants'; import { blockUnblockUser, - deleteUserMomentsForCategory, loadFriendsData, - updateMomentCategories, updateUserXFriends, } from '../../store/actions'; import { - EMPTY_MOMENTS_LIST, EMPTY_PROFILE_PREVIEW_LIST, NO_PROFILE, NO_USER, } from '../../store/initialStates'; import {RootState} from '../../store/rootreducer'; -import {CategorySelectionScreenType, MomentType, ScreenType} from '../../types'; +import {ContentProps} from '../../types'; import { fetchUserX, getUserAsProfilePreviewType, - moveCategory, - normalize, SCREEN_HEIGHT, userLogin, } from '../../utils'; -import {TaggPrompt} from '../common'; -import {Moment} from '../moments'; -import TaggsBar from '../taggs/TaggsBar'; +import Cover from './Cover'; +import PrivateProfile from './PrivateProfile'; import ProfileBody from './ProfileBody'; import ProfileCutout from './ProfileCutout'; import ProfileHeader from './ProfileHeader'; - -interface ContentProps { - y: Animated.Value; - userXId: string | undefined; - screenType: ScreenType; -} +import PublicProfile from './PublicProfile'; +import TaggsBar from '../taggs/TaggsBar'; const Content: React.FC = ({y, userXId, screenType}) => { const dispatch = useDispatch(); @@ -65,22 +42,6 @@ const Content: React.FC = ({y, userXId, screenType}) => { ? useSelector((state: RootState) => state.userX[screenType][userXId]) : useSelector((state: RootState) => state.user); - const {friends = EMPTY_PROFILE_PREVIEW_LIST} = userXId - ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.friends); - - const { - friends: friendsLoggedInUser = EMPTY_PROFILE_PREVIEW_LIST, - } = useSelector((state: RootState) => state.friends); - - const {moments = EMPTY_MOMENTS_LIST} = userXId - ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.moments); - - const {momentCategories = []} = userXId - ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.momentCategories); - const {blockedUsers = EMPTY_PROFILE_PREVIEW_LIST} = useSelector( (state: RootState) => state.blocked, ); @@ -89,31 +50,16 @@ const Content: React.FC = ({y, userXId, screenType}) => { ); const state = useStore().getState(); - const navigation = useNavigation(); - /** * States */ - const [imagesMap, setImagesMap] = useState>( - new Map(), - ); const [isFriend, setIsFriend] = useState(false); const [isBlocked, setIsBlocked] = useState(false); + const [isPrivate, setIsPrivate] = useState(true); const [profileBodyHeight, setProfileBodyHeight] = useState(0); const [shouldBounce, setShouldBounce] = useState(true); const [refreshing, setRefreshing] = useState(false); - const [isStageTwoPromptClosed, setIsStageTwoPromptClosed] = useState( - false, - ); - const [isStageOnePromptClosed, setIsStageOnePromptClosed] = useState( - false, - ); - const [ - isStageThreePromptClosed, - setIsStageThreePromptClosed, - ] = useState(false); - const onRefresh = useCallback(() => { const refrestState = async () => { if (!userXId) { @@ -133,78 +79,6 @@ const Content: React.FC = ({y, userXId, screenType}) => { setProfileBodyHeight(height); }; - const createImagesMap = useCallback(() => { - var map = new Map(); - moments.forEach(function (imageObject) { - var moment_category = imageObject.moment_category; - if (map.has(moment_category)) { - map.get(moment_category).push(imageObject); - } else { - map.set(moment_category, [imageObject]); - } - }); - setImagesMap(map); - }, [moments]); - - useEffect(() => { - createImagesMap(); - }, [createImagesMap]); - - const move = (direction: 'up' | 'down', title: string) => { - let categories = [...momentCategories]; - categories = moveCategory(categories, title, direction === 'up'); - dispatch(updateMomentCategories(categories, false)); - }; - - /** - * Prompt user to perform an activity based on their profile completion stage - * To fire 2 seconds after the screen comes in focus - * 1 means STAGE_1: - * The user must upload a moment, so take them to a screen guiding them to post a moment - * 2 means STAGE_2: - * The user must create another category so show a prompt on top of the screen - * 3 means STAGE_3: - * The user must upload a moment to the second category, so show a prompt on top of the screen - * Else, profile is complete and no prompt needs to be shown - */ - useFocusEffect( - useCallback(() => { - const navigateToMomentUploadPrompt = () => { - switch (profile.profile_completion_stage) { - case 1: - if ( - momentCategories && - momentCategories[0] && - !isStageOnePromptClosed - ) { - navigation.navigate('MomentUploadPrompt', { - screenType, - momentCategory: momentCategories[0], - }); - setIsStageOnePromptClosed(true); - } - break; - case 2: - setIsStageTwoPromptClosed(false); - break; - case 3: - setIsStageThreePromptClosed(false); - break; - default: - break; - } - }; - if (!userXId) { - setTimeout(navigateToMomentUploadPrompt, 2000); - } - }, [ - profile.profile_completion_stage, - momentCategories, - userXId, - isStageOnePromptClosed, - ]), - ); - useEffect(() => { const isActuallyBlocked = blockedUsers.some( (cur_user) => user.username === cur_user.username, @@ -234,37 +108,6 @@ const Content: React.FC = ({y, userXId, screenType}) => { } }; - /** - * Handle deletion of a category - * Confirm with user before deleting the category - * @param category category to be deleted - */ - const handleCategoryDeletion = (category: string) => { - Alert.alert( - 'Category Deletion', - `Are you sure that you want to delete the category ${category} ?`, - [ - { - text: 'Cancel', - style: 'cancel', - }, - { - text: 'Yes', - onPress: () => { - dispatch( - updateMomentCategories( - momentCategories.filter((mc) => mc !== category), - false, - ), - ); - dispatch(deleteUserMomentsForCategory(category)); - }, - }, - ], - {cancelable: true}, - ); - }; - const handleScroll = (e: NativeSyntheticEvent) => { /** * Set the new y position @@ -285,6 +128,7 @@ const Content: React.FC = ({y, userXId, screenType}) => { return ( handleScroll(e)} bounces={shouldBounce} @@ -309,115 +153,22 @@ const Content: React.FC = ({y, userXId, screenType}) => { isBlocked, }} /> - - - {userXId && moments.length === 0 && ( - - - {`Looks like ${ - profile.name.split(' ')[0] - } has not posted any moments yet`} - - )} - {!userXId && - profile.profile_completion_stage === 2 && - !isStageTwoPromptClosed && ( - { - setIsStageTwoPromptClosed(true); - }} - /> - )} - {!userXId && - profile.profile_completion_stage === 3 && - !isStageThreePromptClosed && ( - { - setIsStageThreePromptClosed(true); - }} - /> - )} - {momentCategories.map( - (title, index) => - (!userXId || imagesMap.get(title)) && ( - 1} - showUpButton={index !== 0} - showDownButton={index !== momentCategories.length - 1} - move={move} - /> - ), - )} - {!userXId && ( - - navigation.push('CategorySelection', { - screenType: CategorySelectionScreenType.Profile, - user: loggedInUser, - }) - } - style={styles.createCategoryButton}> - - Create a new category - - - )} - + {isPrivate ? ( + + ) : ( + <> + + + + )} ); }; const styles = StyleSheet.create({ container: { - flex: 1, backgroundColor: '#fff', - }, - momentsContainer: { - backgroundColor: '#f2f2f2', - paddingBottom: SCREEN_HEIGHT / 10, flex: 1, - flexDirection: 'column', - }, - createCategoryButton: { - backgroundColor: TAGG_LIGHT_BLUE, - justifyContent: 'center', - alignItems: 'center', - width: '70%', - height: 30, - marginTop: '15%', - alignSelf: 'center', - }, - createCategoryButtonLabel: { - fontSize: normalize(16), - fontWeight: '500', - color: 'white', - }, - plusIconContainer: { - flexDirection: 'column', - justifyContent: 'center', - alignItems: 'center', - marginVertical: '10%', - }, - noMomentsText: { - fontSize: normalize(14), - fontWeight: 'bold', - color: 'gray', - marginVertical: '8%', }, }); diff --git a/src/components/profile/PrivateProfile.tsx b/src/components/profile/PrivateProfile.tsx new file mode 100644 index 00000000..efa7ff39 --- /dev/null +++ b/src/components/profile/PrivateProfile.tsx @@ -0,0 +1,33 @@ +import React from 'react'; +import {Image, StyleSheet, Text, View} from 'react-native'; +import {PRIVATE_ACCOUNT} from '../../constants/strings'; +import {normalize, SCREEN_HEIGHT} from '../../utils'; + +const PrivateProfile: React.FC = () => { + return ( + + + + {PRIVATE_ACCOUNT} + + + ); +}; + +const styles = StyleSheet.create({ + container: { + backgroundColor: '#F9F9F9', + alignItems: 'center', + justifyContent: 'center', + height: SCREEN_HEIGHT * 0.3, + }, + privateAccountTextContainer: {marginTop: '8%'}, + privateAccountTextStyle: { + fontWeight: '600', + fontSize: normalize(18), + lineHeight: normalize(25), + color: '#828282', + }, +}); + +export default PrivateProfile; diff --git a/src/components/profile/PublicProfile.tsx b/src/components/profile/PublicProfile.tsx new file mode 100644 index 00000000..f453d05b --- /dev/null +++ b/src/components/profile/PublicProfile.tsx @@ -0,0 +1,284 @@ +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 GreyPlusLogo from '../../assets/icons/grey-plus-logo.svg'; +import {TAGG_LIGHT_BLUE} from '../../constants'; +import { + UPLOAD_MOMENT_PROMPT_THREE_HEADER, + UPLOAD_MOMENT_PROMPT_THREE_MESSAGE, + UPLOAD_MOMENT_PROMPT_TWO_HEADER, + UPLOAD_MOMENT_PROMPT_TWO_MESSAGE, +} from '../../constants/strings'; +import { + deleteUserMomentsForCategory, + updateMomentCategories, +} from '../../store/actions'; +import { + EMPTY_MOMENTS_LIST, + EMPTY_PROFILE_PREVIEW_LIST, + NO_PROFILE, + NO_USER, +} from '../../store/initialStates'; +import {RootState} from '../../store/rootreducer'; +import { + CategorySelectionScreenType, + ContentProps, + MomentType, +} from '../../types'; +import {moveCategory, normalize, SCREEN_HEIGHT} from '../../utils'; +import {TaggPrompt} from '../common'; +import {Moment} from '../moments'; + +const PublicProfile: React.FC = ({y, userXId, screenType}) => { + const dispatch = useDispatch(); + + const {profile = NO_PROFILE} = userXId + ? useSelector((state: RootState) => state.userX[screenType][userXId]) + : useSelector((state: RootState) => state.user); + + const {moments = EMPTY_MOMENTS_LIST} = userXId + ? useSelector((state: RootState) => state.userX[screenType][userXId]) + : useSelector((state: RootState) => state.moments); + + const {momentCategories = []} = userXId + ? useSelector((state: RootState) => state.userX[screenType][userXId]) + : useSelector((state: RootState) => state.momentCategories); + + const {user: loggedInUser = NO_USER} = useSelector( + (state: RootState) => state.user, + ); + + const navigation = useNavigation(); + + /** + * States + */ + const [imagesMap, setImagesMap] = useState>( + new Map(), + ); + + const [isStageTwoPromptClosed, setIsStageTwoPromptClosed] = useState( + false, + ); + const [isStageOnePromptClosed, setIsStageOnePromptClosed] = useState( + false, + ); + const [ + isStageThreePromptClosed, + setIsStageThreePromptClosed, + ] = useState(false); + + const move = (direction: 'up' | 'down', title: string) => { + let categories = [...momentCategories]; + categories = moveCategory(categories, title, direction === 'up'); + dispatch(updateMomentCategories(categories, false)); + }; + + /** + * Prompt user to perform an activity based on their profile completion stage + * To fire 2 seconds after the screen comes in focus + * 1 means STAGE_1: + * The user must upload a moment, so take them to a screen guiding them to post a moment + * 2 means STAGE_2: + * The user must create another category so show a prompt on top of the screen + * 3 means STAGE_3: + * The user must upload a moment to the second category, so show a prompt on top of the screen + * Else, profile is complete and no prompt needs to be shown + */ + useFocusEffect( + useCallback(() => { + const navigateToMomentUploadPrompt = () => { + switch (profile.profile_completion_stage) { + case 1: + if ( + momentCategories && + momentCategories[0] && + !isStageOnePromptClosed + ) { + navigation.navigate('MomentUploadPrompt', { + screenType, + momentCategory: momentCategories[0], + }); + setIsStageOnePromptClosed(true); + } + break; + case 2: + setIsStageTwoPromptClosed(false); + break; + case 3: + setIsStageThreePromptClosed(false); + break; + default: + break; + } + }; + if (!userXId) { + setTimeout(navigateToMomentUploadPrompt, 2000); + } + }, [ + profile.profile_completion_stage, + momentCategories, + userXId, + isStageOnePromptClosed, + ]), + ); + + /** + * Handle deletion of a category + * Confirm with user before deleting the category + * @param category category to be deleted + */ + const handleCategoryDeletion = (category: string) => { + Alert.alert( + 'Category Deletion', + `Are you sure that you want to delete the category ${category} ?`, + [ + { + text: 'Cancel', + style: 'cancel', + }, + { + text: 'Yes', + onPress: () => { + dispatch( + updateMomentCategories( + momentCategories.filter((mc) => mc !== category), + false, + ), + ); + dispatch(deleteUserMomentsForCategory(category)); + }, + }, + ], + {cancelable: true}, + ); + }; + + const createImagesMap = useCallback(() => { + let map = new Map(); + moments.forEach(function (imageObject) { + let moment_category = imageObject.moment_category; + if (map.has(moment_category)) { + map.get(moment_category).push(imageObject); + } else { + map.set(moment_category, [imageObject]); + } + }); + setImagesMap(map); + }, [moments]); + + useEffect(() => { + createImagesMap(); + }, [createImagesMap]); + + return ( + + {userXId && moments.length === 0 && ( + + + {`Looks like ${ + profile.name.split(' ')[0] + } has not posted any moments yet`} + + )} + {!userXId && + profile.profile_completion_stage === 2 && + !isStageTwoPromptClosed && ( + { + setIsStageTwoPromptClosed(true); + }} + /> + )} + {!userXId && + profile.profile_completion_stage === 3 && + !isStageThreePromptClosed && ( + { + setIsStageThreePromptClosed(true); + }} + /> + )} + {momentCategories.map( + (title, index) => + (!userXId || imagesMap.get(title)) && ( + 1} + showUpButton={index !== 0} + showDownButton={index !== momentCategories.length - 1} + move={move} + /> + ), + )} + {!userXId && ( + + navigation.push('CategorySelection', { + screenType: CategorySelectionScreenType.Profile, + user: loggedInUser, + }) + } + style={styles.createCategoryButton}> + + Create a new category + + + )} + + ); +}; + +const styles = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: '#fff', + }, + momentsContainer: { + backgroundColor: '#f2f2f2', + paddingBottom: SCREEN_HEIGHT / 10, + flex: 1, + flexDirection: 'column', + }, + createCategoryButton: { + backgroundColor: TAGG_LIGHT_BLUE, + justifyContent: 'center', + alignItems: 'center', + width: '70%', + height: 30, + marginTop: '15%', + alignSelf: 'center', + }, + createCategoryButtonLabel: { + fontSize: normalize(16), + fontWeight: '500', + color: 'white', + }, + plusIconContainer: { + flexDirection: 'column', + justifyContent: 'center', + alignItems: 'center', + marginVertical: '10%', + }, + noMomentsText: { + fontSize: normalize(14), + fontWeight: 'bold', + color: 'gray', + marginVertical: '8%', + }, +}); + +export default PublicProfile; diff --git a/src/constants/strings.ts b/src/constants/strings.ts index cb442b7b..fa1aeb25 100644 --- a/src/constants/strings.ts +++ b/src/constants/strings.ts @@ -54,6 +54,7 @@ export const MARKED_AS_MSG = (str: string) => `Marked as ${str}`; export const MOMENT_DELETED_MSG = 'Moment deleted....Some moments have to go, to create space for greater ones'; export const NO_NEW_NOTIFICATIONS = 'You have no new notifications'; export const NO_RESULTS_FOUND = 'No Results Found!'; +export const PRIVATE_ACCOUNT = 'This account is private'; export const SUCCESS_CATEGORY_DELETE = 'Category successfully deleted, but its memory will live on'; export const SUCCESS_INVITATION_CODE = 'Welcome to Tagg!'; export const SUCCESS_LINK = (str: string) => `Successfully linked ${str} 🎉`; diff --git a/src/types/types.ts b/src/types/types.ts index 9a40e4c0..e96d35a9 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -1,3 +1,5 @@ +import Animated from 'react-native-reanimated'; + export interface UserType { userId: string; username: string; @@ -198,6 +200,11 @@ export interface CommentNotificationType { export interface ThreadNotificationType extends CommentNotificationType { parent_comment: string; } +export interface ContentProps { + y: Animated.Value; + userXId: string | undefined; + screenType: ScreenType; +} export type NotificationType = { actor: ProfilePreviewType; -- cgit v1.2.3-70-g09d2 From 82acd049763452decdab0c40e6cf7286dd2ed57d Mon Sep 17 00:00:00 2001 From: ankit-thanekar007 Date: Thu, 25 Mar 2021 17:09:45 -0700 Subject: Private account toggle changes --- src/components/profile/Content.tsx | 29 ++++++++++++++++++++++------- src/components/profile/PrivateProfile.tsx | 4 ++-- src/components/profile/ProfileBody.tsx | 1 + src/components/profile/PublicProfile.tsx | 2 +- 4 files changed, 26 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx index 860e16c5..8d77d798 100644 --- a/src/components/profile/Content.tsx +++ b/src/components/profile/Content.tsx @@ -41,7 +41,6 @@ const Content: React.FC = ({y, userXId, screenType}) => { const {user = NO_USER, profile = NO_PROFILE} = userXId ? useSelector((state: RootState) => state.userX[screenType][userXId]) : useSelector((state: RootState) => state.user); - const {blockedUsers = EMPTY_PROFILE_PREVIEW_LIST} = useSelector( (state: RootState) => state.blocked, ); @@ -55,20 +54,19 @@ const Content: React.FC = ({y, userXId, screenType}) => { */ const [isFriend, setIsFriend] = useState(false); const [isBlocked, setIsBlocked] = useState(false); - const [isPrivate, setIsPrivate] = useState(true); const [profileBodyHeight, setProfileBodyHeight] = useState(0); const [shouldBounce, setShouldBounce] = useState(true); const [refreshing, setRefreshing] = useState(false); const onRefresh = useCallback(() => { const refrestState = async () => { + setRefreshing(true); if (!userXId) { await userLogin(dispatch, loggedInUser); } else { await fetchUserX(dispatch, user, screenType); } }; - setRefreshing(true); refrestState().then(() => { setRefreshing(false); }); @@ -88,6 +86,10 @@ const Content: React.FC = ({y, userXId, screenType}) => { } }, [blockedUsers, user]); + useEffect(() => { + setIsFriend(profile.friendship_status === 'friends'); + }, [profile.friendship_status]); + /** * Handles a click on the block / unblock button. * loadFriends updates friends list for the logged in user @@ -108,6 +110,16 @@ const Content: React.FC = ({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) => { /** * Set the new y position @@ -153,13 +165,16 @@ const Content: React.FC = ({y, userXId, screenType}) => { isBlocked, }} /> - {isPrivate ? ( - - ) : ( + {canViewProfile() ? ( <> - + + ) : ( + )} ); diff --git a/src/components/profile/PrivateProfile.tsx b/src/components/profile/PrivateProfile.tsx index efa7ff39..07a0dccc 100644 --- a/src/components/profile/PrivateProfile.tsx +++ b/src/components/profile/PrivateProfile.tsx @@ -16,10 +16,10 @@ const PrivateProfile: React.FC = () => { const styles = StyleSheet.create({ container: { - backgroundColor: '#F9F9F9', alignItems: 'center', justifyContent: 'center', - height: SCREEN_HEIGHT * 0.3, + backgroundColor: '#F9F9F9', + height: SCREEN_HEIGHT * 0.35, }, privateAccountTextContainer: {marginTop: '8%'}, privateAccountTextStyle: { diff --git a/src/components/profile/ProfileBody.tsx b/src/components/profile/ProfileBody.tsx index 646be3e0..3aef5990 100644 --- a/src/components/profile/ProfileBody.tsx +++ b/src/components/profile/ProfileBody.tsx @@ -119,6 +119,7 @@ const styles = StyleSheet.create({ flex: 1, paddingTop: '3.5%', paddingBottom: '2%', + width: '50%', }, container: { paddingVertical: '1%', diff --git a/src/components/profile/PublicProfile.tsx b/src/components/profile/PublicProfile.tsx index f453d05b..4b5166f0 100644 --- a/src/components/profile/PublicProfile.tsx +++ b/src/components/profile/PublicProfile.tsx @@ -227,7 +227,7 @@ const PublicProfile: React.FC = ({y, userXId, screenType}) => { {!userXId && ( - navigation.push('CategorySelection', { + navigation.navigate('CategorySelection', { screenType: CategorySelectionScreenType.Profile, user: loggedInUser, }) -- cgit v1.2.3-70-g09d2 From 64f8829ab55bfe6851f10ca933043877769c56bf Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 26 Mar 2021 17:28:23 -0400 Subject: show taggsbar, prevent taggsbar navigation on profile and SP --- src/components/profile/Content.tsx | 28 +++++++++++++++------------- src/components/profile/PublicProfile.tsx | 5 ++--- src/components/taggs/Tagg.tsx | 30 +++++++++++++++++------------- src/components/taggs/TaggsBar.tsx | 4 ++++ src/screens/suggestedPeople/SPBody.tsx | 14 +++++++++++++- src/types/types.ts | 1 + src/utils/users.ts | 8 ++++++++ 7 files changed, 60 insertions(+), 30 deletions(-) (limited to 'src') 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 = ({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 = ({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) => { /** * Set the new y position @@ -165,7 +156,11 @@ const Content: React.FC = ({y, userXId, screenType}) => { isBlocked, }} /> - {canViewProfile() ? ( + {canViewProfile( + loggedInUser.userId === user.userId, + profile.is_private, + isFriend, + ) ? ( <> = ({y, userXId, screenType}) => { ) : ( - + <> + + + )} ); 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 = ({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 = ({ @@ -45,6 +46,7 @@ const Tagg: React.FC = ({ userXId, user, whiteRing, + allowNavigation = true, }) => { const navigation = useNavigation(); const [modalVisible, setModalVisible] = useState(false); @@ -70,19 +72,21 @@ const Tagg: React.FC = ({ 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 = ({ y, @@ -30,6 +31,7 @@ const TaggsBar: React.FC = ({ screenType, whiteRing, linkedSocials, + allowNavigation = true, }) => { let [taggs, setTaggs] = useState([]); let [taggsNeedUpdate, setTaggsNeedUpdate] = useState(true); @@ -79,6 +81,7 @@ const TaggsBar: React.FC = ({ setTaggsNeedUpdate={setTaggsNeedUpdate} setSocialDataNeedUpdate={handleSocialUpdate} whiteRing={whiteRing ? whiteRing : undefined} + allowNavigation={allowNavigation} />, ); i++; @@ -96,6 +99,7 @@ const TaggsBar: React.FC = ({ 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 = ({ suggested_people_url, friendship, badges, + is_private, }, itemIndex, onAddFriend, @@ -156,6 +163,11 @@ const SPBody: React.FC = ({ screenType={screenType} whiteRing={true} linkedSocials={social_links} + allowNavigation={canViewProfile( + loggedInUserId === user.id, + is_private, + friendship.status === '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; +}; -- cgit v1.2.3-70-g09d2 From e8324a7278a82d926acceedc10921f0b14e6d403 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 29 Mar 2021 14:00:39 -0400 Subject: updated helper function, cleaned up code, prevent friends navigation --- src/components/profile/Content.tsx | 24 ++++++++---------------- src/components/profile/FriendsCount.tsx | 17 ++++++++++------- src/components/profile/ProfileBody.tsx | 18 +++++------------- src/components/profile/ProfileHeader.tsx | 8 ++++---- src/services/UserFriendsService.ts | 9 ++------- src/store/actions/userFriends.ts | 23 +++++++++++------------ src/utils/users.ts | 23 +++++++++++++++++++---- 7 files changed, 59 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx index 9fb6f79b..779e0525 100644 --- a/src/components/profile/Content.tsx +++ b/src/components/profile/Content.tsx @@ -38,22 +38,23 @@ import TaggsBar from '../taggs/TaggsBar'; const Content: React.FC = ({y, userXId, screenType}) => { const dispatch = useDispatch(); - - const {user = NO_USER, profile = NO_PROFILE} = userXId - ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.user); + const state: RootState = useStore().getState(); + const { + user = NO_USER, + profile = NO_PROFILE, + } = useSelector((state: RootState) => + userXId ? state.userX[screenType][userXId] : state.user, + ); const {blockedUsers = EMPTY_PROFILE_PREVIEW_LIST} = useSelector( (state: RootState) => state.blocked, ); const {user: loggedInUser = NO_USER} = useSelector( (state: RootState) => state.user, ); - const state = useStore().getState(); /** * States */ - const [isFriend, setIsFriend] = useState(false); const [isBlocked, setIsBlocked] = useState(false); const [profileBodyHeight, setProfileBodyHeight] = useState(0); const [shouldBounce, setShouldBounce] = useState(true); @@ -87,10 +88,6 @@ const Content: React.FC = ({y, userXId, screenType}) => { } }, [blockedUsers, user]); - useEffect(() => { - setIsFriend(profile.friendship_status === 'friends'); - }, [profile.friendship_status]); - /** * Handles a click on the block / unblock button. * loadFriends updates friends list for the logged in user @@ -151,16 +148,11 @@ const Content: React.FC = ({y, userXId, screenType}) => { onLayout, userXId, screenType, - isFriend, handleBlockUnblock, isBlocked, }} /> - {canViewProfile( - loggedInUser.userId === user.userId, - profile.is_private, - isFriend, - ) ? ( + {canViewProfile(state, userXId, screenType) ? ( <> = ({ userXId, screenType, }) => { - const {friends} = userXId - ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.friends); + const {friends} = useSelector((state: RootState) => + userXId ? state.userX[screenType][userXId] : state.friends, + ); const count = friends ? friends.length : 0; const displayedCount: string = @@ -32,15 +32,18 @@ const FriendsCount: React.FC = ({ : `${count / 1e6}m`; const navigation = useNavigation(); + const state: RootState = useStore().getState(); return ( - navigation.push('FriendsListScreen', { + navigation.navigate('FriendsListScreen', { userXId, screenType, }) + } + disabled={ + !canViewProfile(state, userXId, screenType) || friends.length === 0 }> {displayedCount} diff --git a/src/components/profile/ProfileBody.tsx b/src/components/profile/ProfileBody.tsx index 3aef5990..b49e71a3 100644 --- a/src/components/profile/ProfileBody.tsx +++ b/src/components/profile/ProfileBody.tsx @@ -2,21 +2,17 @@ import React from 'react'; import {LayoutChangeEvent, Linking, StyleSheet, Text, View} from 'react-native'; import {normalize} from 'react-native-elements'; import {useDispatch, useSelector, useStore} from 'react-redux'; -import { - TAGG_DARK_BLUE, - TAGG_LIGHT_BLUE, - TOGGLE_BUTTON_TYPE, -} from '../../constants'; +import {TAGG_DARK_BLUE, TOGGLE_BUTTON_TYPE} from '../../constants'; import { acceptFriendRequest, declineFriendRequest, updateUserXFriends, updateUserXProfileAllScreens, } from '../../store/actions'; -import {NO_PROFILE, NO_USER} from '../../store/initialStates'; +import {NO_PROFILE} from '../../store/initialStates'; import {RootState} from '../../store/rootReducer'; import {ScreenType} from '../../types'; -import {getUserAsProfilePreviewType, SCREEN_WIDTH} from '../../utils'; +import {getUserAsProfilePreviewType} from '../../utils'; import {FriendsButton} from '../common'; import ToggleButton from './ToggleButton'; @@ -34,12 +30,8 @@ const ProfileBody: React.FC = ({ userXId, screenType, }) => { - const {profile = NO_PROFILE, user} = userXId - ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.user); - - const {user: loggedInUser = NO_USER} = useSelector( - (state: RootState) => state.user, + const {profile = NO_PROFILE, user} = useSelector((state: RootState) => + userXId ? state.userX[screenType][userXId] : state.user, ); const { diff --git a/src/components/profile/ProfileHeader.tsx b/src/components/profile/ProfileHeader.tsx index e5bd9d93..b5dda399 100644 --- a/src/components/profile/ProfileHeader.tsx +++ b/src/components/profile/ProfileHeader.tsx @@ -1,7 +1,6 @@ import React, {useState} from 'react'; import {StyleSheet, Text, View} from 'react-native'; import {useSelector} from 'react-redux'; -import UniversityIcon from './UniversityIcon'; import {PROFILE_CUTOUT_TOP_Y} from '../../constants'; import {RootState} from '../../store/rootreducer'; import {ScreenType} from '../../types'; @@ -9,6 +8,7 @@ import {normalize} from '../../utils'; import Avatar from './Avatar'; import FriendsCount from './FriendsCount'; import ProfileMoreInfoDrawer from './ProfileMoreInfoDrawer'; +import UniversityIcon from './UniversityIcon'; type ProfileHeaderProps = { userXId: string | undefined; @@ -26,9 +26,9 @@ const ProfileHeader: React.FC = ({ const { profile: {name = '', university_class = 2021} = {}, user: {username: userXName = ''}, - } = userXId - ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.user); + } = useSelector((state: RootState) => + userXId ? state.userX[screenType][userXId] : state.user, + ); const [drawerVisible, setDrawerVisible] = useState(false); const [firstName, lastName] = [...name.split(' ')]; return ( diff --git a/src/services/UserFriendsService.ts b/src/services/UserFriendsService.ts index da39380f..5c41e988 100644 --- a/src/services/UserFriendsService.ts +++ b/src/services/UserFriendsService.ts @@ -1,17 +1,12 @@ -//Abstracted common friends api calls out here - import AsyncStorage from '@react-native-community/async-storage'; import {Alert} from 'react-native'; -import {ContactType, FriendshipStatusType} from '../types'; import { FRIENDS_ENDPOINT, INVITE_FRIEND_ENDPOINT, USERS_FROM_CONTACTS_ENDPOINT, } from '../constants'; -import { - ERROR_SOMETHING_WENT_WRONG, - ERROR_SOMETHING_WENT_WRONG_REFRESH, -} from '../constants/strings'; +import {ERROR_SOMETHING_WENT_WRONG_REFRESH} from '../constants/strings'; +import {ContactType, FriendshipStatusType} from '../types'; export const loadFriends = async (userId: string, token: string) => { try { diff --git a/src/store/actions/userFriends.ts b/src/store/actions/userFriends.ts index 9da3cb4a..4183d0f6 100644 --- a/src/store/actions/userFriends.ts +++ b/src/store/actions/userFriends.ts @@ -1,25 +1,24 @@ -import {getTokenOrLogout, userXInStore} from '../../utils'; -import {RootState} from '../rootReducer'; -import { - FriendshipStatusType, - ProfilePreviewType, - ScreenType, - UserType, -} from '../../types/types'; +import {Action, ThunkAction} from '@reduxjs/toolkit'; import { acceptFriendRequestService, addFriendService, + deleteFriendshipService, friendOrUnfriendUser, loadFriends, - deleteFriendshipService, } from '../../services'; -import {Action, ThunkAction} from '@reduxjs/toolkit'; import { - userFriendsFetched, + FriendshipStatusType, + ProfilePreviewType, + ScreenType, + UserType, +} from '../../types/types'; +import {getTokenOrLogout, userXInStore} from '../../utils'; +import { updateFriends, + userFriendsFetched, userXFriendshipEdited, - userLoggedIn, } from '../reducers'; +import {RootState} from '../rootReducer'; export const loadFriendsData = ( userId: string, diff --git a/src/utils/users.ts b/src/utils/users.ts index 6cb6d46c..0b8a0582 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -176,9 +176,24 @@ export const defaultUserProfile = () => { }; export const canViewProfile = ( - ownProfile: boolean, - isPrivate: boolean, - isFriend: boolean, + state: RootState, + userXId: string | undefined, + screenType: ScreenType, ) => { - return ownProfile || isFriend || !isPrivate; + // own profile + if (!userXId || state.user.user.userId === userXId) { + return true; + } + // not private + if (!(userXId && state.userX[screenType][userXId].profile.is_private)) { + return true; + } + // is friend + if ( + userXId && + state.userX[screenType][userXId].profile.friendship_status === 'friends' + ) { + return true; + } + return false; }; -- cgit v1.2.3-70-g09d2 From 8e4fc71e625e8818773ebfa3d93bbee32b3ffe99 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 29 Mar 2021 14:02:44 -0400 Subject: disabled press animation --- src/components/taggs/Tagg.tsx | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/components/taggs/Tagg.tsx b/src/components/taggs/Tagg.tsx index ae9ab091..4e4987fb 100644 --- a/src/components/taggs/Tagg.tsx +++ b/src/components/taggs/Tagg.tsx @@ -72,21 +72,19 @@ const Tagg: React.FC = ({ const modalOrAuthBrowserOrPass = async () => { if (youMayPass) { - 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); - } - }); - } + 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) { @@ -149,7 +147,8 @@ const Tagg: React.FC = ({ + onPress={modalOrAuthBrowserOrPass} + disabled={!allowNavigation}> {pickTheRightRingHere()} -- cgit v1.2.3-70-g09d2 From f16ab73dbda9ac345c85837b48966ef6574876ed Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 29 Mar 2021 14:07:05 -0400 Subject: code cleanup, prevent navigation from SP taggs bar --- src/components/profile/FriendsCount.tsx | 8 ++++---- src/screens/suggestedPeople/SPBody.tsx | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/components/profile/FriendsCount.tsx b/src/components/profile/FriendsCount.tsx index a733823f..4790743b 100644 --- a/src/components/profile/FriendsCount.tsx +++ b/src/components/profile/FriendsCount.tsx @@ -1,11 +1,11 @@ +import {useNavigation} from '@react-navigation/native'; import React from 'react'; -import {View, Text, StyleSheet, ViewProps} from 'react-native'; +import {StyleSheet, Text, View, ViewProps} from 'react-native'; import {TouchableOpacity} from 'react-native-gesture-handler'; -import {useNavigation} from '@react-navigation/native'; -import {RootState} from '../../store/rootReducer'; import {useSelector, useStore} from 'react-redux'; +import {RootState} from '../../store/rootReducer'; import {ScreenType} from '../../types'; -import {canViewProfile, canViewProfileFoo, normalize} from '../../utils'; +import {canViewProfile, normalize} from '../../utils'; interface FriendsCountProps extends ViewProps { userXId: string | undefined; diff --git a/src/screens/suggestedPeople/SPBody.tsx b/src/screens/suggestedPeople/SPBody.tsx index f38945f7..297f76c0 100644 --- a/src/screens/suggestedPeople/SPBody.tsx +++ b/src/screens/suggestedPeople/SPBody.tsx @@ -4,10 +4,12 @@ import {StyleSheet, Text, View} from 'react-native'; import {Image} from 'react-native-animatable'; import {TouchableOpacity} from 'react-native-gesture-handler'; import Animated from 'react-native-reanimated'; +import {useStore} from 'react-redux'; import RequestedButton from '../../assets/ionicons/requested-button.svg'; import {TaggsBar} from '../../components'; import {BadgesDropdown, MutualFriends} from '../../components/suggestedPeople'; import {BADGE_DATA} from '../../constants/badges'; +import {RootState} from '../../store/rootReducer'; import { ProfilePreviewType, ScreenType, @@ -39,7 +41,6 @@ const SPBody: React.FC = ({ suggested_people_url, friendship, badges, - is_private, }, itemIndex, onAddFriend, @@ -55,6 +56,7 @@ const SPBody: React.FC = ({ }[] >([]); const navigation = useNavigation(); + const state: RootState = useStore().getState(); useEffect(() => { const newBadges: {badge: UniversityBadge; img: any}[] = []; const findBadgeIcons = (badge: UniversityBadge) => { @@ -165,9 +167,9 @@ const SPBody: React.FC = ({ whiteRing={true} linkedSocials={social_links} allowNavigation={canViewProfile( - loggedInUserId === user.id, - is_private, - friendship.status === 'friends', + state, + loggedInUserId === user.id ? undefined : user.id, + screenType, )} /> -- cgit v1.2.3-70-g09d2 From 59f64faa456b7f4852eef3d9281afde8d8f46e9a Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 29 Mar 2021 14:13:06 -0400 Subject: fix linter warnings --- src/components/profile/PublicProfile.tsx | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/components/profile/PublicProfile.tsx b/src/components/profile/PublicProfile.tsx index a70e8e50..8d597986 100644 --- a/src/components/profile/PublicProfile.tsx +++ b/src/components/profile/PublicProfile.tsx @@ -30,20 +30,20 @@ import {moveCategory, normalize, SCREEN_HEIGHT} from '../../utils'; import {TaggPrompt} from '../common'; import {Moment} from '../moments'; -const PublicProfile: React.FC = ({y, userXId, screenType}) => { +const PublicProfile: React.FC = ({userXId, screenType}) => { const dispatch = useDispatch(); - const {profile = NO_PROFILE} = userXId - ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.user); + const {profile = NO_PROFILE} = useSelector((state: RootState) => + userXId ? state.userX[screenType][userXId] : state.user, + ); - const {moments = EMPTY_MOMENTS_LIST} = userXId - ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.moments); + const {moments = EMPTY_MOMENTS_LIST} = useSelector((state: RootState) => + userXId ? state.userX[screenType][userXId] : state.moments, + ); - const {momentCategories = []} = userXId - ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.momentCategories); + const {momentCategories = []} = useSelector((state: RootState) => + userXId ? state.userX[screenType][userXId] : state.momentCategories, + ); const {user: loggedInUser = NO_USER} = useSelector( (state: RootState) => state.user, @@ -117,10 +117,12 @@ const PublicProfile: React.FC = ({y, userXId, screenType}) => { setTimeout(navigateToMomentUploadPrompt, 2000); } }, [ + userXId, profile.profile_completion_stage, momentCategories, - userXId, isStageOnePromptClosed, + navigation, + screenType, ]), ); @@ -188,7 +190,7 @@ const PublicProfile: React.FC = ({y, userXId, screenType}) => { { setIsStageTwoPromptClosed(true); }} @@ -200,7 +202,7 @@ const PublicProfile: React.FC = ({y, userXId, screenType}) => { { setIsStageThreePromptClosed(true); }} -- cgit v1.2.3-70-g09d2 From 872a3e8dbb7182e532d7878f3b1f316b3ca69386 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 29 Mar 2021 14:14:01 -0400 Subject: cleaned up code --- src/components/profile/PublicProfile.tsx | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/components/profile/PublicProfile.tsx b/src/components/profile/PublicProfile.tsx index 8d597986..3272bca1 100644 --- a/src/components/profile/PublicProfile.tsx +++ b/src/components/profile/PublicProfile.tsx @@ -58,16 +58,11 @@ const PublicProfile: React.FC = ({userXId, screenType}) => { new Map(), ); - const [isStageTwoPromptClosed, setIsStageTwoPromptClosed] = useState( + const [isStageTwoPromptClosed, setIsStageTwoPromptClosed] = useState(false); + const [isStageOnePromptClosed, setIsStageOnePromptClosed] = useState(false); + const [isStageThreePromptClosed, setIsStageThreePromptClosed] = useState( false, ); - const [isStageOnePromptClosed, setIsStageOnePromptClosed] = useState( - false, - ); - const [ - isStageThreePromptClosed, - setIsStageThreePromptClosed, - ] = useState(false); const move = (direction: 'up' | 'down', title: string) => { let categories = [...momentCategories]; -- cgit v1.2.3-70-g09d2 From 641a98cd5d184efb5639952812f24c56c90e7f62 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 29 Mar 2021 14:18:00 -0400 Subject: code cleanup --- src/components/profile/Content.tsx | 1 - src/components/taggs/TaggsBar.tsx | 18 +++++++++--------- src/screens/suggestedPeople/SPBody.tsx | 5 ----- 3 files changed, 9 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx index 779e0525..cf2b7d28 100644 --- a/src/components/profile/Content.tsx +++ b/src/components/profile/Content.tsx @@ -165,7 +165,6 @@ const Content: React.FC = ({y, userXId, screenType}) => { diff --git a/src/components/taggs/TaggsBar.tsx b/src/components/taggs/TaggsBar.tsx index a9c428b2..567b58de 100644 --- a/src/components/taggs/TaggsBar.tsx +++ b/src/components/taggs/TaggsBar.tsx @@ -2,7 +2,7 @@ import React, {Fragment, useEffect, useState} from 'react'; import {StyleSheet} from 'react-native'; import Animated from 'react-native-reanimated'; import {useSafeAreaInsets} from 'react-native-safe-area-context'; -import {useDispatch, useSelector} from 'react-redux'; +import {useDispatch, useSelector, useStore} from 'react-redux'; import { INTEGRATED_SOCIAL_LIST, PROFILE_CUTOUT_BOTTOM_Y, @@ -12,6 +12,7 @@ import {getLinkedSocials} from '../../services'; import {loadIndividualSocial, updateSocial} from '../../store/actions'; import {RootState} from '../../store/rootReducer'; import {ScreenType} from '../../types'; +import {canViewProfile} from '../../utils'; import Tagg from './Tagg'; const {View, ScrollView, interpolate, Extrapolate} = Animated; @@ -22,7 +23,6 @@ interface TaggsBarProps { screenType: ScreenType; whiteRing: boolean | undefined; linkedSocials?: string[]; - allowNavigation?: boolean; } const TaggsBar: React.FC = ({ y, @@ -31,14 +31,14 @@ const TaggsBar: React.FC = ({ screenType, whiteRing, linkedSocials, - allowNavigation = true, }) => { let [taggs, setTaggs] = useState([]); let [taggsNeedUpdate, setTaggsNeedUpdate] = useState(true); - - const {user} = userXId - ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.user); + const {user} = useSelector((state: RootState) => + userXId ? state.userX[screenType][userXId] : state.user, + ); + const state: RootState = useStore().getState(); + const allowTaggsNavigation = canViewProfile(state, userXId, screenType); const dispatch = useDispatch(); @@ -81,7 +81,7 @@ const TaggsBar: React.FC = ({ setTaggsNeedUpdate={setTaggsNeedUpdate} setSocialDataNeedUpdate={handleSocialUpdate} whiteRing={whiteRing ? whiteRing : undefined} - allowNavigation={allowNavigation} + allowNavigation={allowTaggsNavigation} />, ); i++; @@ -99,7 +99,7 @@ const TaggsBar: React.FC = ({ userXId={userXId} user={user} whiteRing={whiteRing ? whiteRing : undefined} - allowNavigation={allowNavigation} + allowNavigation={allowTaggsNavigation} />, ); i++; diff --git a/src/screens/suggestedPeople/SPBody.tsx b/src/screens/suggestedPeople/SPBody.tsx index 297f76c0..824f8b1c 100644 --- a/src/screens/suggestedPeople/SPBody.tsx +++ b/src/screens/suggestedPeople/SPBody.tsx @@ -166,11 +166,6 @@ const SPBody: React.FC = ({ screenType={screenType} whiteRing={true} linkedSocials={social_links} - allowNavigation={canViewProfile( - state, - loggedInUserId === user.id ? undefined : user.id, - screenType, - )} /> -- cgit v1.2.3-70-g09d2 From cfd760db7c4d6b7c3f9f9aa8fe53ed4bf2f3affc Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 29 Mar 2021 14:20:52 -0400 Subject: added comments --- src/utils/users.ts | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/utils/users.ts b/src/utils/users.ts index 0b8a0582..f9d6d6b7 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -175,6 +175,15 @@ export const defaultUserProfile = () => { return defaultImage; }; +/** + * Used to determine whether the logged-in user is able to view userX's private + * information or not. + * + * @param state redux store's root state + * @param userXId target userX's id + * @param screenType current screen type + * @returns true if abel to view private info, false otherwise + */ export const canViewProfile = ( state: RootState, userXId: string | undefined, -- cgit v1.2.3-70-g09d2 From decacdda9f9f7e7b7649422ed86005fe7ab4adcf Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 29 Mar 2021 14:32:06 -0400 Subject: fixed taggs bar and added padding for private accounts --- src/components/profile/Content.tsx | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx index cf2b7d28..c9a87ad1 100644 --- a/src/components/profile/Content.tsx +++ b/src/components/profile/Content.tsx @@ -128,7 +128,7 @@ const Content: React.FC = ({y, userXId, screenType}) => { return ( handleScroll(e)} bounces={shouldBounce} @@ -152,22 +152,14 @@ const Content: React.FC = ({y, userXId, screenType}) => { isBlocked, }} /> + {canViewProfile(state, userXId, screenType) ? ( - <> - - - + ) : ( - <> - - - + )} ); @@ -178,6 +170,10 @@ const styles = StyleSheet.create({ backgroundColor: '#fff', flex: 1, }, + contentContainer: { + flexGrow: 1, + paddingBottom: SCREEN_HEIGHT * 0.1, + }, }); export default Content; -- cgit v1.2.3-70-g09d2 From ee80ddfb8a486fea31d845aba4e0b4847fe637e9 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 29 Mar 2021 14:43:35 -0400 Subject: updated padding --- src/components/profile/Content.tsx | 1 - src/components/profile/PrivateProfile.tsx | 3 ++- src/components/profile/PublicProfile.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx index c9a87ad1..a22b9728 100644 --- a/src/components/profile/Content.tsx +++ b/src/components/profile/Content.tsx @@ -172,7 +172,6 @@ const styles = StyleSheet.create({ }, contentContainer: { flexGrow: 1, - paddingBottom: SCREEN_HEIGHT * 0.1, }, }); diff --git a/src/components/profile/PrivateProfile.tsx b/src/components/profile/PrivateProfile.tsx index 07a0dccc..bc75a18a 100644 --- a/src/components/profile/PrivateProfile.tsx +++ b/src/components/profile/PrivateProfile.tsx @@ -19,7 +19,8 @@ const styles = StyleSheet.create({ alignItems: 'center', justifyContent: 'center', backgroundColor: '#F9F9F9', - height: SCREEN_HEIGHT * 0.35, + height: SCREEN_HEIGHT * 0.4, + paddingBottom: SCREEN_HEIGHT * 0.1, }, privateAccountTextContainer: {marginTop: '8%'}, privateAccountTextStyle: { diff --git a/src/components/profile/PublicProfile.tsx b/src/components/profile/PublicProfile.tsx index 3272bca1..9683d8f2 100644 --- a/src/components/profile/PublicProfile.tsx +++ b/src/components/profile/PublicProfile.tsx @@ -245,7 +245,7 @@ const styles = StyleSheet.create({ }, momentsContainer: { backgroundColor: '#f2f2f2', - paddingBottom: SCREEN_HEIGHT / 10, + paddingBottom: SCREEN_HEIGHT * 0.15, flex: 1, flexDirection: 'column', }, -- cgit v1.2.3-70-g09d2