aboutsummaryrefslogtreecommitdiff
path: root/src/routes/viewProfile/ProfileProvider.tsx
diff options
context:
space:
mode:
authorGeorge Rusu <56009869+grusu6928@users.noreply.github.com>2020-10-25 15:21:38 -0700
committerGitHub <noreply@github.com>2020-10-25 18:21:38 -0400
commit9da19cdcb6c7596d60afde6d0d559f06a24a0627 (patch)
tree8f11b6e0a5fcdc2eb983d498fa7b016d4daf44ba /src/routes/viewProfile/ProfileProvider.tsx
parent44a25bfabd356f5eee5ec4f580452407a7e40246 (diff)
[TMA-237] Added modal for user registration and redirect (#61)
* move async-storage * removed lock files * added lock files to gitignore * added the wrong file to gitignore * added modal for user registration and redirect * api call to get list of linked socials for each user to display appropriate icon * fixed indentation and linting * refactored modal and browser sign-in * now dynamically adding linked and unlinked taggs, added a bunch of TODOs for tomorrow * added svg icons * done? finished taggs bar UI and all the navigations including modal * fixed some bugs and added more TODOs * fixed some bugs and refactored posts fetching logic * fixed taggs bar bug * done, it will update everything correctly * added comments * added tiktok Co-authored-by: hsalhab <husam_salhab@brown.edu> Co-authored-by: george <grus6928@gmail.com> Co-authored-by: Ivan Chen <ivan@thetaggid.com>
Diffstat (limited to 'src/routes/viewProfile/ProfileProvider.tsx')
-rw-r--r--src/routes/viewProfile/ProfileProvider.tsx49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/routes/viewProfile/ProfileProvider.tsx b/src/routes/viewProfile/ProfileProvider.tsx
index a4b6cb14..c4942ea0 100644
--- a/src/routes/viewProfile/ProfileProvider.tsx
+++ b/src/routes/viewProfile/ProfileProvider.tsx
@@ -1,9 +1,6 @@
import AsyncStorage from '@react-native-community/async-storage';
import React, {createContext, useEffect, useState} from 'react';
-import {
- GET_IG_POSTS_ENDPOINT,
- GET_TWITTER_POSTS_ENDPOINT,
-} from '../../constants';
+import {INTEGRATED_SOCIAL_LIST} from '../../constants';
import {
loadAvatar,
loadCover,
@@ -21,6 +18,7 @@ interface ProfileContextProps {
newMomentsAvailable: boolean;
updateMoments: (value: boolean) => void;
socialAccounts: Record<string, SocialAccountType>;
+ socialsNeedUpdate: (_: string[]) => void;
}
const NO_USER: UserType = {
userId: '',
@@ -32,11 +30,10 @@ const NO_PROFILE: ProfileType = {
name: '',
};
-// Not necessary, but safer, in case SocialAccountType object is undefined
const NO_SOCIAL_ACCOUNTS: Record<string, SocialAccountType> = {
- Instagram: {},
- Facebook: {},
- Twitter: {},
+ Instagram: {posts: []},
+ Facebook: {posts: []},
+ Twitter: {posts: []},
};
export const ProfileContext = createContext<ProfileContextProps>({
@@ -48,6 +45,7 @@ export const ProfileContext = createContext<ProfileContextProps>({
newMomentsAvailable: true,
updateMoments: () => {},
socialAccounts: NO_SOCIAL_ACCOUNTS,
+ socialsNeedUpdate: () => {},
});
/**
@@ -59,10 +57,14 @@ const ProfileProvider: React.FC = ({children}) => {
const [avatar, setAvatar] = useState<string | null>(null);
const [cover, setCover] = useState<string | null>(null);
const [newMomentsAvailable, setNewMomentsAvailable] = useState<boolean>(true);
-
const [socialAccounts, setSocialAccounts] = useState<
Record<string, SocialAccountType>
>(NO_SOCIAL_ACCOUNTS);
+ // Default update all integrated social lists on start
+ const [socialsNeedUpdate, setSocialsNeedUpdate] = useState<string[]>([
+ ...INTEGRATED_SOCIAL_LIST,
+ ]);
+
const {userId} = user;
useEffect(() => {
if (!userId) {
@@ -79,26 +81,25 @@ const ProfileProvider: React.FC = ({children}) => {
loadProfileInfo(token, userId, setProfile);
loadAvatar(token, userId, setAvatar);
loadCover(token, userId, setCover);
- loadSocialPosts(
- token,
- userId,
- 'Instagram',
- GET_IG_POSTS_ENDPOINT,
- socialAccounts,
- ).then((newSocialAccounts) => setSocialAccounts(newSocialAccounts));
- loadSocialPosts(
- token,
- userId,
- 'Twitter',
- GET_TWITTER_POSTS_ENDPOINT,
- socialAccounts,
- ).then((newSocialAccounts) => setSocialAccounts(newSocialAccounts));
} catch (err) {
console.log(err);
}
};
loadData();
- }, [socialAccounts, userId]);
+ }, [userId]);
+
+ useEffect(() => {
+ if (socialsNeedUpdate.length > 0 && userId) {
+ for (let social of socialsNeedUpdate) {
+ loadSocialPosts(userId, social).then((accountData) => {
+ socialAccounts[social] = accountData;
+ setSocialAccounts(socialAccounts);
+ console.log('Updated posts data', social);
+ });
+ }
+ setSocialsNeedUpdate([]);
+ }
+ }, [socialAccounts, socialsNeedUpdate, userId]);
return (
<ProfileContext.Provider