From 52a3fe743e6122d157eaab3ad7bab0c70a96676b Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 22 Oct 2020 17:42:29 -0400 Subject: [TMA-242] Twitter and Facebook Tagg View (#63) * modified the way we store social media data, initial skeleton * MVP? Twitter done? * cleaned up some things * forgot to lint and cleaned up some more code * minor change to text display * fixed some UI bug, linting, and minor adjustment to posts UI * fixed a couple of things * added DateLabel, Facebook taggs view, fixed minor stuff * Some small changes for the PR * removed unused Feed Co-authored-by: Ashm Walia --- src/routes/viewProfile/ProfileProvider.tsx | 49 ++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'src/routes/viewProfile') diff --git a/src/routes/viewProfile/ProfileProvider.tsx b/src/routes/viewProfile/ProfileProvider.tsx index 8fb9a011..a4b6cb14 100644 --- a/src/routes/viewProfile/ProfileProvider.tsx +++ b/src/routes/viewProfile/ProfileProvider.tsx @@ -1,14 +1,16 @@ -import React, {useEffect} from 'react'; -import {createContext, useState} from 'react'; import AsyncStorage from '@react-native-community/async-storage'; -import {UserType, ProfileType, InstagramPostType} from '../../types'; - +import React, {createContext, useEffect, useState} from 'react'; +import { + GET_IG_POSTS_ENDPOINT, + GET_TWITTER_POSTS_ENDPOINT, +} from '../../constants'; import { - loadProfileInfo, loadAvatar, loadCover, - loadInstaPosts, + loadProfileInfo, + loadSocialPosts, } from '../../services'; +import {ProfileType, SocialAccountType, UserType} from '../../types'; interface ProfileContextProps { user: UserType; @@ -16,9 +18,9 @@ interface ProfileContextProps { loadProfile: (userId: string, username: string) => void; avatar: string | null; cover: string | null; - instaPosts: Array; newMomentsAvailable: boolean; updateMoments: (value: boolean) => void; + socialAccounts: Record; } const NO_USER: UserType = { userId: '', @@ -29,15 +31,23 @@ const NO_PROFILE: ProfileType = { website: '', name: '', }; + +// Not necessary, but safer, in case SocialAccountType object is undefined +const NO_SOCIAL_ACCOUNTS: Record = { + Instagram: {}, + Facebook: {}, + Twitter: {}, +}; + export const ProfileContext = createContext({ user: NO_USER, profile: NO_PROFILE, loadProfile: () => {}, avatar: null, cover: null, - instaPosts: [], newMomentsAvailable: true, updateMoments: () => {}, + socialAccounts: NO_SOCIAL_ACCOUNTS, }); /** @@ -48,9 +58,11 @@ const ProfileProvider: React.FC = ({children}) => { const [profile, setProfile] = useState(NO_PROFILE); const [avatar, setAvatar] = useState(null); const [cover, setCover] = useState(null); - const [instaPosts, setInstaPosts] = useState>([]); const [newMomentsAvailable, setNewMomentsAvailable] = useState(true); + const [socialAccounts, setSocialAccounts] = useState< + Record + >(NO_SOCIAL_ACCOUNTS); const {userId} = user; useEffect(() => { if (!userId) { @@ -67,13 +79,26 @@ const ProfileProvider: React.FC = ({children}) => { loadProfileInfo(token, userId, setProfile); loadAvatar(token, userId, setAvatar); loadCover(token, userId, setCover); - loadInstaPosts(token, userId, setInstaPosts); + 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(); - }, [userId]); + }, [socialAccounts, userId]); return ( { profile, avatar, cover, - instaPosts, newMomentsAvailable, + socialAccounts, loadProfile: (id, username) => { setUser({...user, userId: id, username}); }, -- cgit v1.2.3-70-g09d2