diff options
Diffstat (limited to 'src/services/UserProfileService.ts')
-rw-r--r-- | src/services/UserProfileService.ts | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index 4c3af06a..59f9649a 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -6,10 +6,12 @@ import { AVATAR_PHOTO_ENDPOINT, COVER_PHOTO_ENDPOINT, GET_IG_POSTS_ENDPOINT, + GET_TWITTER_POSTS_ENDPOINT, } from '../constants'; import AsyncStorage from '@react-native-community/async-storage'; import RNFetchBlob from 'rn-fetch-blob'; +import {SocialAccountType} from 'src/types'; export const loadProfileInfo = async ( token: string, @@ -83,32 +85,32 @@ export const loadCover = async ( } }; -export const loadInstaPosts = async ( +export const loadSocialPosts = async ( token: string, userId: string, - callback: Function, + socialType: string, + endpoint: string, + socialAccounts: Record<string, SocialAccountType>, ) => { try { - const response = await fetch(GET_IG_POSTS_ENDPOINT + `${userId}/`, { + const response = await fetch(endpoint + `${userId}/`, { method: 'GET', headers: { Authorization: 'Token ' + token, }, }); - const status = response.status; - if (status === 200) { - let ig_posts = await response.json(); - callback(ig_posts); + if (response.status === 200) { + const body = await response.json(); + socialAccounts[socialType].handle = body.handle; + socialAccounts[socialType].posts = body.posts; + socialAccounts[socialType].profile_pic = body.profile_pic; } else { - callback([]); + throw new Error(await response.json()); } } catch (error) { console.log(error); - Alert.alert( - 'Something went wrong! ðŸ˜', - "Would you believe me if I told you that I don't know what happened?", - ); } + return socialAccounts; }; export const loadRecentlySearchedUsers = async (callback: Function) => { |