From 38661e00281363b0f4ad32f0b29d739e1ca09164 Mon Sep 17 00:00:00 2001 From: Ashm Walia <40498934+ashmgarv@users.noreply.github.com> Date: Wed, 30 Dec 2020 11:36:44 -0800 Subject: [TMA - 457]Change followers to friends (#149) * One commit to replace followers with friends * Move block unblock to drawer and some cosmetic changes * Options to edit own profile when viewing * Changes for University Class * Small fix * Made ProfileOnboarding a scroll view and other small changes * Small fix * Small fix thanks to ivan and tanmay * Add ? --- src/assets/universities/brown.png | Bin 0 -> 3234 bytes src/components/notifications/Notification.tsx | 2 +- src/components/profile/Content.tsx | 68 ++++---- src/components/profile/FollowCount.tsx | 74 -------- src/components/profile/Followers.tsx | 70 -------- src/components/profile/Friends.tsx | 65 +++++++ src/components/profile/FriendsCount.tsx | 66 +++++++ src/components/profile/ProfileBody.tsx | 31 ++-- src/components/profile/ProfileHeader.tsx | 63 ++++--- src/components/profile/ProfileMoreInfoDrawer.tsx | 42 ++++- src/components/profile/ProfilePreview.tsx | 26 +-- src/components/profile/ToggleButton.tsx | 23 ++- src/components/profile/UniversityIcon.tsx | 58 +++++++ src/components/profile/index.ts | 3 +- src/constants/api.ts | 5 +- src/constants/constants.ts | 14 +- src/routes/main/MainStackNavigator.tsx | 3 +- src/routes/main/MainStackScreen.tsx | 6 +- src/screens/onboarding/ProfileOnboarding.tsx | 210 ++++++++++++++--------- src/screens/profile/FollowersListScreen.tsx | 83 --------- src/screens/profile/FriendsListScreen.tsx | 71 ++++++++ src/screens/profile/index.ts | 2 +- src/services/UserFollowServices.ts | 85 --------- src/services/UserFriendsServices.ts | 63 +++++++ src/services/UserProfileService.ts | 22 ++- src/services/index.ts | 2 +- src/store/actions/index.ts | 2 +- src/store/actions/userFollow.ts | 57 ------ src/store/actions/userFriends.ts | 52 ++++++ src/store/actions/userX.ts | 30 +--- src/store/initialStates.ts | 13 +- src/store/reducers/index.ts | 2 +- src/store/reducers/userFollowReducer.ts | 27 --- src/store/reducers/userFriendsReducer.ts | 25 +++ src/store/reducers/userXReducer.ts | 13 +- src/store/rootReducer.ts | 4 +- src/types/types.ts | 6 +- src/utils/common.ts | 15 +- src/utils/users.ts | 4 +- 39 files changed, 768 insertions(+), 639 deletions(-) create mode 100644 src/assets/universities/brown.png delete mode 100644 src/components/profile/FollowCount.tsx delete mode 100644 src/components/profile/Followers.tsx create mode 100644 src/components/profile/Friends.tsx create mode 100644 src/components/profile/FriendsCount.tsx create mode 100644 src/components/profile/UniversityIcon.tsx delete mode 100644 src/screens/profile/FollowersListScreen.tsx create mode 100644 src/screens/profile/FriendsListScreen.tsx delete mode 100644 src/services/UserFollowServices.ts create mode 100644 src/services/UserFriendsServices.ts delete mode 100644 src/store/actions/userFollow.ts create mode 100644 src/store/actions/userFriends.ts delete mode 100644 src/store/reducers/userFollowReducer.ts create mode 100644 src/store/reducers/userFriendsReducer.ts (limited to 'src') diff --git a/src/assets/universities/brown.png b/src/assets/universities/brown.png new file mode 100644 index 00000000..1f1fd887 Binary files /dev/null and b/src/assets/universities/brown.png differ diff --git a/src/components/notifications/Notification.tsx b/src/components/notifications/Notification.tsx index f533e42d..38e4d597 100644 --- a/src/components/notifications/Notification.tsx +++ b/src/components/notifications/Notification.tsx @@ -63,7 +63,7 @@ const Notification: React.FC = (props) => { const onNotificationTap = async () => { switch (notification_type) { - case 'FLO': + case 'FRD': if (!userXInStore(state, screenType, id)) { await fetchUserX( dispatch, diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx index 17713ea3..a6c3abdc 100644 --- a/src/components/profile/Content.tsx +++ b/src/components/profile/Content.tsx @@ -33,10 +33,10 @@ import ProfileHeader from './ProfileHeader'; import {useDispatch, useSelector, useStore} from 'react-redux'; import {RootState} from '../../store/rootreducer'; import { - followUnfollowUser, + friendUnfriendUser, blockUnblockUser, - loadFollowData, - updateUserXFollowersAndFollowing, + loadFriendsData, + updateUserXFriends, updateMomentCategories, } from '../../store/actions'; import { @@ -49,7 +49,6 @@ import { import {Cover} from '.'; import {TouchableOpacity} from 'react-native-gesture-handler'; import {useNavigation} from '@react-navigation/native'; -import {deleteMomentCategories} from '../../services'; interface ContentProps { y: Animated.Value; @@ -64,9 +63,13 @@ const Content: React.FC = ({y, userXId, screenType}) => { ? useSelector((state: RootState) => state.userX[screenType][userXId]) : useSelector((state: RootState) => state.user); - const {followers = EMPTY_PROFILE_PREVIEW_LIST} = userXId + const {friends = EMPTY_PROFILE_PREVIEW_LIST} = userXId ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.follow); + : 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]) @@ -92,7 +95,7 @@ const Content: React.FC = ({y, userXId, screenType}) => { const [imagesMap, setImagesMap] = useState>( new Map(), ); - const [isFollowed, setIsFollowed] = useState(false); + const [isFriend, setIsFriend] = useState(false); const [isBlocked, setIsBlocked] = useState(false); const [profileBodyHeight, setProfileBodyHeight] = useState(0); const [shouldBounce, setShouldBounce] = useState(true); @@ -143,16 +146,16 @@ const Content: React.FC = ({y, userXId, screenType}) => { }, [createImagesMap]); /** - * This hook is called on load of profile and when you update the followers list. + * This hook is called on load of profile and when you update the friends list. */ useEffect(() => { - const isActuallyFollowed = followers.some( - (follower) => follower.username === loggedInUser.username, + const isActuallyAFriend = friendsLoggedInUser.some( + (friend) => friend.username === user.username, ); - if (isFollowed != isActuallyFollowed) { - setIsFollowed(isActuallyFollowed); + if (isFriend != isActuallyAFriend) { + setIsFriend(isActuallyAFriend); } - }, [followers]); + }, [friends]); useEffect(() => { const isActuallyBlocked = blockedUsers.some( @@ -164,7 +167,7 @@ const Content: React.FC = ({y, userXId, screenType}) => { }, [blockedUsers, user]); /** - * The object returned by this method is added to the list of blocked / followed users by the reducer. + * 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 = ( @@ -181,28 +184,28 @@ const Content: React.FC = ({y, userXId, screenType}) => { }; /** - * Handles a click on the follow / unfollow button. - * followUnfollowUser takes care of updating the following list for loggedInUser - * updateUserXFollowersAndFollowing updates followers and following list for the followed user. + * 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. */ - const handleFollowUnfollow = async () => { + const handleFriendUnfriend = async () => { await dispatch( - followUnfollowUser( + friendUnfriendUser( loggedInUser, getUserAsProfilePreviewType(user, profile), - isFollowed, + isFriend, ), ); - await dispatch(updateUserXFollowersAndFollowing(user.userId, state)); + await dispatch(updateUserXFriends(user.userId, state)); }; /** * Handles a click on the block / unblock button. - * loadFollowData updates followers / following list for the logged in user - * updateUserXFollowersAndFollowing updates followers and following list for the followed user. + * loadFriends updates friends list for the logged in user + * updateUserXFriends updates friends list for the user. */ - const handleBlockUnblock = async () => { + const handleBlockUnblock = async (callback?: () => void) => { await dispatch( blockUnblockUser( loggedInUser, @@ -210,8 +213,11 @@ const Content: React.FC = ({y, userXId, screenType}) => { isBlocked, ), ); - await dispatch(loadFollowData(loggedInUser.userId)); - await dispatch(updateUserXFollowersAndFollowing(user.userId, state)); + await dispatch(loadFriendsData(loggedInUser.userId)); + await dispatch(updateUserXFriends(user.userId, state)); + if (callback) { + callback(); + } }; /** @@ -272,16 +278,18 @@ const Content: React.FC = ({y, userXId, screenType}) => { }> - + diff --git a/src/components/profile/FollowCount.tsx b/src/components/profile/FollowCount.tsx deleted file mode 100644 index 95b953dc..00000000 --- a/src/components/profile/FollowCount.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import React from 'react'; -import {View, Text, StyleSheet, ViewProps} from 'react-native'; -import {TouchableOpacity} from 'react-native-gesture-handler'; -import {useNavigation} from '@react-navigation/native'; -import {RootState} from '../../store/rootReducer'; -import {useSelector} from 'react-redux'; -import {ScreenType} from '../../types'; -import {EMPTY_PROFILE_PREVIEW_LIST} from '../../store/initialStates'; - -interface FollowCountProps extends ViewProps { - mode: 'followers' | 'following'; - userXId: string | undefined; - screenType: ScreenType; -} - -const FollowCount: React.FC = ({ - style, - mode, - userXId, - screenType, -}) => { - const { - followers = EMPTY_PROFILE_PREVIEW_LIST, - following = EMPTY_PROFILE_PREVIEW_LIST, - } = userXId - ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.follow); - - const isFollowers = mode === 'followers'; - const count = isFollowers ? followers.length : following.length; - - const navigation = useNavigation(); - const displayed: string = - count < 5e3 - ? `${count}` - : count < 1e5 - ? `${(count / 1e3).toFixed(1)}k` - : count < 1e6 - ? `${(count / 1e3).toFixed(0)}k` - : `${count / 1e6}m`; - return ( - - navigation.push('FollowersListScreen', { - isFollowers, - userXId, - screenType, - }) - }> - - {displayed} - - {isFollowers ? 'Followers' : 'Following'} - - - - ); -}; - -const styles = StyleSheet.create({ - container: { - alignItems: 'center', - }, - count: { - fontWeight: '700', - fontSize: 18, - }, - label: { - fontWeight: '400', - fontSize: 16, - }, -}); - -export default FollowCount; diff --git a/src/components/profile/Followers.tsx b/src/components/profile/Followers.tsx deleted file mode 100644 index 44ae4399..00000000 --- a/src/components/profile/Followers.tsx +++ /dev/null @@ -1,70 +0,0 @@ -import React from 'react'; -import {View, StyleSheet, ViewProps, Text} from 'react-native'; -import {ProfilePreviewType, ScreenType} from '../../types'; -import {ProfilePreview} from '..'; -import {useNavigation} from '@react-navigation/native'; -import {Button} from 'react-native-elements'; - -interface FollowersListProps { - result: Array; - sectionTitle: string; - screenType: ScreenType; -} - -const Followers: React.FC = ({ - result, - sectionTitle, - screenType, -}) => { - const navigation = useNavigation(); - return ( - <> - -