aboutsummaryrefslogtreecommitdiff
path: root/src/routes/authentication/AuthProvider.tsx
diff options
context:
space:
mode:
authorJustin Shillingford <jgs272@cornell.edu>2020-08-14 16:39:26 -0400
committerGitHub <noreply@github.com>2020-08-14 16:39:26 -0400
commit59ea758ba64dd4e00f12b5ceb941d0ea5e273210 (patch)
tree6a698457be38c484bb9f93e3caf2f8e32bb7be8d /src/routes/authentication/AuthProvider.tsx
parent1979a2b55ebe560b9d20862bd835343516b40379 (diff)
[TMA-19] Social Media Post Container (#31)
* Basic mostly functional implementation Need to figure out why API is being called so much * Hey it works now! Without a million API calls! * Fixed bug where app would crash upon login Also updated property names to be more appropriate * Added post datetime and social icon * Updated error message * Fixed typecheck errors I don't know that these fixes are the best since I don't think they're generalizable * Formatted datetime in PostHeader
Diffstat (limited to 'src/routes/authentication/AuthProvider.tsx')
-rw-r--r--src/routes/authentication/AuthProvider.tsx24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/routes/authentication/AuthProvider.tsx b/src/routes/authentication/AuthProvider.tsx
index bd5706f3..e52d56bc 100644
--- a/src/routes/authentication/AuthProvider.tsx
+++ b/src/routes/authentication/AuthProvider.tsx
@@ -1,11 +1,12 @@
import React, {useEffect} from 'react';
import {createContext, useState} from 'react';
import RNFetchBlob from 'rn-fetch-blob';
-import {UserType, ProfileType} from '../../types';
+import {UserType, ProfileType, InstagramPostType} from '../../types';
import {
PROFILE_INFO_ENDPOINT,
AVATAR_PHOTO_ENDPOINT,
COVER_PHOTO_ENDPOINT,
+ GET_IG_POSTS_ENDPOINT,
} from '../../constants';
interface AuthContextProps {
@@ -15,6 +16,7 @@ interface AuthContextProps {
logout: () => void;
avatar: string | null;
cover: string | null;
+ instaPosts: Array<InstagramPostType>;
}
const NO_USER: UserType = {
userId: '',
@@ -32,6 +34,7 @@ export const AuthContext = createContext<AuthContextProps>({
logout: () => {},
avatar: null,
cover: null,
+ instaPosts: [],
});
/**
@@ -42,6 +45,7 @@ const AuthProvider: React.FC = ({children}) => {
const [profile, setProfile] = useState<ProfileType>(NO_PROFILE);
const [avatar, setAvatar] = useState<string | null>(null);
const [cover, setCover] = useState<string | null>(null);
+ const [instaPosts, setInstaPosts] = useState<Array<InstagramPostType>>([]);
const {userId} = user;
useEffect(() => {
@@ -95,9 +99,26 @@ const AuthProvider: React.FC = ({children}) => {
console.log(error);
}
};
+ const loadInstaPosts = async () => {
+ try {
+ const response = await fetch(GET_IG_POSTS_ENDPOINT + `${userId}/`, {
+ method: 'GET',
+ });
+ const status = response.status;
+ if (status === 200) {
+ let ig_posts = await response.json();
+ setInstaPosts(ig_posts);
+ } else {
+ setInstaPosts([]);
+ }
+ } catch (error) {
+ console.log(error);
+ }
+ };
loadProfileInfo();
loadAvatar();
loadCover();
+ loadInstaPosts();
}, [userId]);
return (
@@ -107,6 +128,7 @@ const AuthProvider: React.FC = ({children}) => {
profile,
avatar,
cover,
+ instaPosts,
login: (id, username) => {
setUser({...user, userId: id, username});
},