aboutsummaryrefslogtreecommitdiff
path: root/src/screens/profile/ProfileScreen.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/screens/profile/ProfileScreen.tsx')
-rw-r--r--src/screens/profile/ProfileScreen.tsx74
1 files changed, 35 insertions, 39 deletions
diff --git a/src/screens/profile/ProfileScreen.tsx b/src/screens/profile/ProfileScreen.tsx
index d32eca98..a2a1b5bd 100644
--- a/src/screens/profile/ProfileScreen.tsx
+++ b/src/screens/profile/ProfileScreen.tsx
@@ -1,11 +1,15 @@
-import React, {useContext, useEffect} from 'react';
+import React, {useContext, useEffect, useState} from 'react';
import {StatusBar} from 'react-native';
import Animated from 'react-native-reanimated';
import {Content, Cover, TabsGradient} from '../../components';
-import {RouteProp} from '@react-navigation/native';
-import {ProfileStackParams, ProfileProvider, AuthContext} from '../../routes/';
-
-/**
+import {RouteProp, useFocusEffect} from '@react-navigation/native';
+import {ProfileStackParams, ProfileProvider} from '../../routes/';
+import {resetScreenType} from '../../store/actions';
+import {useDispatch, useStore} from 'react-redux';
+import {ScreenType} from '../../types';
+import {DUMMY_USERID} from '../../store/initialStates';
+
+/**r
* Profile Screen for a user's profile
* including posts, messaging, and settings
*/
@@ -17,45 +21,37 @@ interface ProfileOnboardingProps {
}
const ProfileScreen: React.FC<ProfileOnboardingProps> = ({route}) => {
- const {isProfileView, username, userId} = route.params;
+ const {screenType} = route.params;
+ let {userXId} = route.params;
const y = Animated.useValue(0);
- const {updateIsEditedProfile} = useContext(AuthContext);
-
- useEffect(() => {
- updateIsEditedProfile(false);
- });
+ const dispatch = useDispatch();
- const profileView = () => {
- return (
- <>
- <StatusBar />
- <Cover {...{y, isProfileView}} />
- <Content {...{y, isProfileView}} />
- <TabsGradient />
- </>
- );
- };
+ /**
+ * This is a double safety check to avoid app crash.
+ * Checks if the required userXId is present in the store, if not userXId is set to dummy id
+ */
+ if (userXId && !(userXId in useStore().getState().userX[screenType])) {
+ userXId = DUMMY_USERID;
+ }
/**
- * Every profile to have it's own ProfileContext if a profile is being visited by the logged in user.
- * Pass userid and username of the user whose profile needs to be viewed and the information gets loaded to the ProfileContext.
- * Now this profile context is local to every user being viewed.
- * This comes with BENEFITS and CAVEATS
- * BENEFITS :
- * 1 - The app now remembers which user was visited last.
- * 2 - The Search and Profile stacks (and potentially more stacks in the future) now have totally unrelated stacks of profiles being visited.
- * 3 - This will help us manage the navigation stack better if we introduce a feature to go back to the last profile visited.
- * CAVEATS :
- * 1 - Since the ProfileContext is not global, whenever we navigate to some component that is not in the child tree of the ProfileProvider, we would not be able to use anything in the context (It would basically have default values).
- * 2 - For example, the followers list (FollowersListScreen) and profile picture on the Taggs screen (AvatarTile) now no longer have access to the ProfileContext.
- * 3 - Components like these now have to have data passed in via props, instead of using the context.
+ * Code under useFocusEffect gets executed every time the screen comes under focus / is being viewed by the user.
+ * This is done to reset the users stored in our store for the Search screen.
+ * Read more about useFocusEffect here : https://reactnavigation.org/docs/function-after-focusing-screen/
*/
- return isProfileView ? (
- <ProfileProvider uId={userId} uname={username}>
- {profileView()}
- </ProfileProvider>
- ) : (
- profileView()
+ useFocusEffect(() => {
+ if (!userXId) {
+ dispatch(resetScreenType(screenType));
+ }
+ });
+
+ return (
+ <>
+ <StatusBar />
+ <Cover {...{y, userXId, screenType}} />
+ <Content {...{y, userXId, screenType}} />
+ <TabsGradient />
+ </>
);
};