aboutsummaryrefslogtreecommitdiff
path: root/src/components/profile/Content.tsx
diff options
context:
space:
mode:
authorankit-thanekar007 <ankit.thanekar007@gmail.com>2021-03-25 17:09:45 -0700
committerankit-thanekar007 <ankit.thanekar007@gmail.com>2021-03-25 17:09:45 -0700
commit82acd049763452decdab0c40e6cf7286dd2ed57d (patch)
treeca6af18b1cc9f3f4fbd54fb3e16470543c445e14 /src/components/profile/Content.tsx
parentf662d1cd85447de0f6be945a350d1f2d1be5033e (diff)
Private account toggle changes
Diffstat (limited to 'src/components/profile/Content.tsx')
-rw-r--r--src/components/profile/Content.tsx29
1 files changed, 22 insertions, 7 deletions
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<ContentProps> = ({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<ContentProps> = ({y, userXId, screenType}) => {
*/
const [isFriend, setIsFriend] = useState<boolean>(false);
const [isBlocked, setIsBlocked] = useState<boolean>(false);
- const [isPrivate, setIsPrivate] = useState<boolean>(true);
const [profileBodyHeight, setProfileBodyHeight] = useState(0);
const [shouldBounce, setShouldBounce] = useState<boolean>(true);
const [refreshing, setRefreshing] = useState<boolean>(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<ContentProps> = ({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<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
@@ -153,13 +165,16 @@ const Content: React.FC<ContentProps> = ({y, userXId, screenType}) => {
isBlocked,
}}
/>
- {isPrivate ? (
- <PrivateProfile />
- ) : (
+ {canViewProfile() ? (
<>
- <TaggsBar {...{y, profileBodyHeight, userXId, screenType}} />
+ <TaggsBar
+ {...{y, profileBodyHeight, userXId, screenType}}
+ whiteRing={undefined}
+ />
<PublicProfile {...{y, userXId, screenType}} />
</>
+ ) : (
+ <PrivateProfile />
)}
</Animated.ScrollView>
);