aboutsummaryrefslogtreecommitdiff
path: root/src/routes
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/profile/Profile.tsx7
-rw-r--r--src/routes/profile/ProfileStack.tsx12
-rw-r--r--src/routes/viewProfile/ProfileProvider.tsx41
3 files changed, 31 insertions, 29 deletions
diff --git a/src/routes/profile/Profile.tsx b/src/routes/profile/Profile.tsx
index abf967c6..bffa22ce 100644
--- a/src/routes/profile/Profile.tsx
+++ b/src/routes/profile/Profile.tsx
@@ -15,7 +15,6 @@ import {RouteProp} from '@react-navigation/native';
* What will be the First Screen of the stack depends on value of isProfileView (Search if its true else Profile)
* Trying to explain the purpose of each route on the stack (ACTUALLY A STACK)
* Profile : To display the logged in user's profile when isProfileView is false, else displays profile of any user the logged in user wants to view.
- * ProfileView : To display profile of a commenter / any user who has commented on a photo.
* When you click on the profile icon after looking at a user's profile, the stack is reset and you come back to the top of the stack (First screen : Profile in this case)
* Search : To display the search screen. Search for a user on this screen, click on a result tile and navigate to the same (isProfileView = true).
* When you click on the search icon after looking at a user's profile, the stack gets reset and you come back to the top of the stack (First screen : Search in this case)
@@ -90,12 +89,6 @@ const Profile: React.FC<ProfileStackProps> = ({route}) => {
initialParams={{isProfileView: isProfileView}}
/>
<ProfileStack.Screen
- name="ProfileView"
- component={ProfileScreen}
- options={{headerShown: false}}
- initialParams={{isProfileView: isProfileView}}
- />
- <ProfileStack.Screen
name="MomentCommentsScreen"
component={MomentCommentsScreen}
options={{headerShown: false}}
diff --git a/src/routes/profile/ProfileStack.tsx b/src/routes/profile/ProfileStack.tsx
index b535d90d..cba646f8 100644
--- a/src/routes/profile/ProfileStack.tsx
+++ b/src/routes/profile/ProfileStack.tsx
@@ -1,15 +1,20 @@
import {createStackNavigator} from '@react-navigation/stack';
-import {MomentType} from '../../types';
+import {MomentType, ProfilePreviewType, SocialAccountType} from '../../types';
export type ProfileStackParams = {
Search: undefined;
Profile: {
isProfileView: boolean;
+ username: string;
+ userId: string;
};
SocialMediaTaggs: {
socialMediaType: string;
socialMediaHandle: string;
isProfileView: boolean;
+ name: string;
+ accountData: SocialAccountType;
+ avatar: string;
};
CaptionScreen: {
title: string;
@@ -23,12 +28,9 @@ export type ProfileStackParams = {
isProfileView: boolean;
moment_id: string;
};
- ProfileView: {
- isProfileView: boolean;
- };
FollowersListScreen: {
- isProfileView: boolean;
isFollowers: boolean;
+ list: ProfilePreviewType[];
};
};
diff --git a/src/routes/viewProfile/ProfileProvider.tsx b/src/routes/viewProfile/ProfileProvider.tsx
index f9b29dc6..f2d27a84 100644
--- a/src/routes/viewProfile/ProfileProvider.tsx
+++ b/src/routes/viewProfile/ProfileProvider.tsx
@@ -22,11 +22,8 @@ import {
interface ProfileContextProps {
user: UserType;
profile: ProfileType;
- loadProfile: (userId: string, username: string) => void;
avatar: string | null;
cover: string | null;
- newMomentsAvailable: boolean;
- updateMoments: (value: boolean) => void;
socialAccounts: Record<string, SocialAccountType>;
socialsNeedUpdate: (_: string[]) => void;
moments: MomentType[];
@@ -54,11 +51,8 @@ const NO_SOCIAL_ACCOUNTS: Record<string, SocialAccountType> = {
export const ProfileContext = createContext<ProfileContextProps>({
user: NO_USER,
profile: NO_PROFILE,
- loadProfile: () => {},
avatar: null,
cover: null,
- newMomentsAvailable: true,
- updateMoments: () => {},
socialAccounts: NO_SOCIAL_ACCOUNTS,
socialsNeedUpdate: () => {},
moments: [],
@@ -70,9 +64,20 @@ export const ProfileContext = createContext<ProfileContextProps>({
/**
* This is the context provider for user profiles that the logged in user wants to see
+ * The ProfileProviderProps is used to initialise data as soon as the component is initialised.
*/
-const ProfileProvider: React.FC = ({children}) => {
- const [user, setUser] = useState<UserType>(NO_USER);
+
+type ProfileProviderProps = {
+ uname: string;
+ uId: string;
+};
+
+const ProfileProvider: React.FC<ProfileProviderProps> = ({
+ children,
+ uId,
+ uname,
+}) => {
+ const [user, setUser] = useState<UserType>({userId: uId, username: uname});
const [profile, setProfile] = useState<ProfileType>(NO_PROFILE);
const [avatar, setAvatar] = useState<string | null>(null);
const [cover, setCover] = useState<string | null>(null);
@@ -157,8 +162,17 @@ const ProfileProvider: React.FC = ({children}) => {
if (socialsNeedUpdate.length > 0 && userId) {
for (let social of socialsNeedUpdate) {
loadSocialPosts(userId, social).then((accountData) => {
- socialAccounts[social] = accountData;
- setSocialAccounts(socialAccounts);
+ /**
+ * Please use the following syntax when updating an object, fixing this problem broke our head. LOLs
+ * ref1 : https://stackoverflow.com/questions/56423256/set-dynamic-key-in-state-via-usestate-react-hooks
+ * ref2: https://stackoverflow.com/questions/43638938/updating-an-object-with-setstate-in-react/43639228
+ * The spread operator {...} helps us make a simple copy of the object
+ * And form there on we can use the [] to specify the dynamically constructed key and set its value.
+ */
+ setSocialAccounts((prevSocialAccounts) => ({
+ ...prevSocialAccounts,
+ [social]: accountData,
+ }));
console.log('Updated posts data', social);
});
}
@@ -173,18 +187,11 @@ const ProfileProvider: React.FC = ({children}) => {
profile,
avatar,
cover,
- newMomentsAvailable,
socialAccounts,
moments,
followers,
following,
followersNeedUpdate,
- loadProfile: (id, username) => {
- setUser({...user, userId: id, username});
- },
- updateMoments: (value) => {
- setNewMomentsAvailable(value);
- },
socialsNeedUpdate: (socials: string[]) => {
setSocialsNeedUpdate(socials);
},