diff options
author | George Rusu <56009869+grusu6928@users.noreply.github.com> | 2020-10-25 15:21:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-25 18:21:38 -0400 |
commit | 9da19cdcb6c7596d60afde6d0d559f06a24a0627 (patch) | |
tree | 8f11b6e0a5fcdc2eb983d498fa7b016d4daf44ba /src/routes/authentication/AuthProvider.tsx | |
parent | 44a25bfabd356f5eee5ec4f580452407a7e40246 (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/authentication/AuthProvider.tsx')
-rw-r--r-- | src/routes/authentication/AuthProvider.tsx | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/src/routes/authentication/AuthProvider.tsx b/src/routes/authentication/AuthProvider.tsx index a705f074..5bd4278d 100644 --- a/src/routes/authentication/AuthProvider.tsx +++ b/src/routes/authentication/AuthProvider.tsx @@ -1,10 +1,6 @@ import AsyncStorage from '@react-native-community/async-storage'; import React, {createContext, useEffect, useState} from 'react'; -import { - GET_FB_POSTS_ENDPOINT, - GET_IG_POSTS_ENDPOINT, - GET_TWITTER_POSTS_ENDPOINT, -} from '../../constants'; +import {INTEGRATED_SOCIAL_LIST} from '../../constants'; import { loadAvatar, loadCover, @@ -30,6 +26,7 @@ interface AuthContextProps { recentSearches: Array<ProfilePreviewType>; newMomentsAvailable: boolean; updateMoments: (value: boolean) => void; + socialsNeedUpdate: (_: string[]) => void; } const NO_USER: UserType = { @@ -43,11 +40,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 AuthContext = createContext<AuthContextProps>({ @@ -57,10 +53,11 @@ export const AuthContext = createContext<AuthContextProps>({ logout: () => {}, avatar: null, cover: null, - socialAccounts: NO_SOCIAL_ACCOUNTS, recentSearches: [], newMomentsAvailable: true, updateMoments: () => {}, + socialAccounts: NO_SOCIAL_ACCOUNTS, + socialsNeedUpdate: () => {}, }); /** @@ -78,6 +75,10 @@ const AuthProvider: React.FC = ({children}) => { Array<ProfilePreviewType> >([]); const [newMomentsAvailable, setNewMomentsAvailable] = useState<boolean>(true); + // Default update all integrated social lists on start + const [socialsNeedUpdate, setSocialsNeedUpdate] = useState<string[]>([ + ...INTEGRATED_SOCIAL_LIST, + ]); const {userId} = user; useEffect(() => { if (!userId) { @@ -95,33 +96,25 @@ const AuthProvider: React.FC = ({children}) => { loadAvatar(token, userId, setAvatar); loadCover(token, userId, setCover); loadRecentlySearchedUsers(setRecentSearches); - loadSocialPosts( - token, - userId, - 'Instagram', - GET_IG_POSTS_ENDPOINT, - socialAccounts, - ).then((newSocialAccounts) => setSocialAccounts(newSocialAccounts)); - loadSocialPosts( - token, - userId, - 'Facebook', - GET_FB_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 ( <AuthContext.Provider @@ -150,6 +143,9 @@ const AuthProvider: React.FC = ({children}) => { updateMoments: (value) => { setNewMomentsAvailable(value); }, + socialsNeedUpdate: (socials: string[]) => { + setSocialsNeedUpdate(socials); + }, }}> {children} </AuthContext.Provider> |