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 | |
| 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')
| -rw-r--r-- | src/services/UserFollowServices.ts | 18 | ||||
| -rw-r--r-- | src/services/UserProfileService.ts | 30 |
2 files changed, 41 insertions, 7 deletions
diff --git a/src/services/UserFollowServices.ts b/src/services/UserFollowServices.ts index 508c1387..105124bc 100644 --- a/src/services/UserFollowServices.ts +++ b/src/services/UserFollowServices.ts @@ -10,7 +10,11 @@ import { import {ProfilePreviewType} from 'src/types'; -export const loadFollowers = async (userId: string, token: string) => { +export const loadFollowers = async ( + userId: string, + token: string, + callback: Function, +) => { try { const response = await fetch(FOLLOWERS_ENDPOINT + `?user_id=${userId}`, { method: 'GET', @@ -20,17 +24,20 @@ export const loadFollowers = async (userId: string, token: string) => { }); if (response.status === 200) { const body = await response.json(); - return body; + callback(body); } else { throw new Error(await response.json()); } } catch (error) { console.log(error); } - return []; }; -export const loadFollowing = async (userId: string, token: string) => { +export const loadFollowing = async ( + userId: string, + token: string, + callback: Function, +) => { try { const response = await fetch(FOLLOWING_ENDPOINT + `?user_id=${userId}`, { method: 'GET', @@ -40,14 +47,13 @@ export const loadFollowing = async (userId: string, token: string) => { }); if (response.status === 200) { const body = await response.json(); - return body; + callback(body); } else { throw new Error(await response.json()); } } catch (error) { console.log(error); } - return []; }; export const followOrUnfollowUser = async ( 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'); |
