diff options
author | Ashm Walia <40498934+ashmgarv@users.noreply.github.com> | 2020-10-27 17:36:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-27 20:36:03 -0400 |
commit | 62d6fe2bca4bdd1a48cfe54e4c0c3fe590c3b750 (patch) | |
tree | 3afb2c723a10a2649c298e226bc31e10cec92d5a /src/services/UserProfileService.ts | |
parent | 795ba089207571ec13226f2d07c149c8697763ce (diff) |
[HOT FIX] Refactor to make things clean and make the app work (#82)
* Refactored
* Final refactor with an issue
* It works
* Whoops
Diffstat (limited to 'src/services/UserProfileService.ts')
-rw-r--r-- | src/services/UserProfileService.ts | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index 31383f67..a2d53dbb 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -3,7 +3,7 @@ import AsyncStorage from '@react-native-community/async-storage'; import {Alert} from 'react-native'; import RNFetchBlob from 'rn-fetch-blob'; -import {SocialAccountType} from 'src/types'; +import {SocialAccountType, MomentType} from 'src/types'; import { AVATAR_PHOTO_ENDPOINT, COVER_PHOTO_ENDPOINT, @@ -11,6 +11,7 @@ import { GET_IG_POSTS_ENDPOINT, GET_TWITTER_POSTS_ENDPOINT, PROFILE_INFO_ENDPOINT, + MOMENTS_ENDPOINT, } from '../constants'; export const loadProfileInfo = async ( @@ -119,6 +120,33 @@ export const loadSocialPosts: ( return accountData; }; +export const loadMoments: ( + userId: string, + token: string, +) => Promise<MomentType[]> = async (userId, token) => { + let moments: MomentType[] = []; + try { + const response = await fetch(MOMENTS_ENDPOINT + '?user_id=' + userId, { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }); + const status = response.status; + if (status === 200) { + const data = await response.json(); + moments = data; + } else { + console.log('Could not load moments!'); + return []; + } + } catch (err) { + console.log(err); + return []; + } + return moments; +}; + export const loadRecentlySearchedUsers = async (callback: Function) => { try { const asyncCache = await AsyncStorage.getItem('@recently_searched_users'); |