aboutsummaryrefslogtreecommitdiff
path: root/src/components/profile/Content.tsx
diff options
context:
space:
mode:
authorAshm Walia <40498934+ashmgarv@users.noreply.github.com>2020-12-30 11:36:44 -0800
committerGitHub <noreply@github.com>2020-12-30 14:36:44 -0500
commit38661e00281363b0f4ad32f0b29d739e1ca09164 (patch)
tree316cd837b6cc6ae24783f1d93d6c9ee7fb898f68 /src/components/profile/Content.tsx
parentbd2f89805d0bb1c2f1d08fe8d91099aa4f109d35 (diff)
[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 ?
Diffstat (limited to 'src/components/profile/Content.tsx')
-rw-r--r--src/components/profile/Content.tsx68
1 files changed, 38 insertions, 30 deletions
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<number>;
@@ -64,9 +63,13 @@ const Content: React.FC<ContentProps> = ({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<ContentProps> = ({y, userXId, screenType}) => {
const [imagesMap, setImagesMap] = useState<Map<string, MomentType[]>>(
new Map(),
);
- const [isFollowed, setIsFollowed] = useState<boolean>(false);
+ const [isFriend, setIsFriend] = useState<boolean>(false);
const [isBlocked, setIsBlocked] = useState<boolean>(false);
const [profileBodyHeight, setProfileBodyHeight] = useState(0);
const [shouldBounce, setShouldBounce] = useState<boolean>(true);
@@ -143,16 +146,16 @@ const Content: React.FC<ContentProps> = ({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<ContentProps> = ({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<ContentProps> = ({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<ContentProps> = ({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<ContentProps> = ({y, userXId, screenType}) => {
}>
<Cover {...{userXId, screenType}} />
<ProfileCutout />
- <ProfileHeader {...{userXId, screenType}} />
+ <ProfileHeader
+ {...{userXId, screenType, handleBlockUnblock, isBlocked}}
+ />
<ProfileBody
{...{
onLayout,
userXId,
screenType,
- isFollowed,
- handleFollowUnfollow,
- isBlocked,
+ isFriend,
+ handleFriendUnfriend,
handleBlockUnblock,
+ isBlocked,
}}
/>
<TaggsBar {...{y, profileBodyHeight, userXId, screenType}} />