aboutsummaryrefslogtreecommitdiff
path: root/src/routes/authentication/AuthProvider.tsx
diff options
context:
space:
mode:
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});
},