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/services/UserProfileService.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/services') 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, ) => { 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) => { -- cgit v1.2.3-70-g09d2