diff options
Diffstat (limited to 'src/services/UserProfileService.ts')
-rw-r--r-- | src/services/UserProfileService.ts | 60 |
1 files changed, 10 insertions, 50 deletions
diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index 38e04221..e69e4103 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -12,14 +12,9 @@ import { GET_IG_POSTS_ENDPOINT, GET_TWITTER_POSTS_ENDPOINT, PROFILE_INFO_ENDPOINT, - MOMENTS_ENDPOINT, } from '../constants'; -export const loadProfileInfo = async ( - token: string, - userId: string, - callback: Function, -) => { +export const loadProfileInfo = async (token: string, userId: string) => { try { const response = await fetch(PROFILE_INFO_ENDPOINT + `${userId}/`, { method: 'GET', @@ -33,7 +28,7 @@ export const loadProfileInfo = async ( let {name, biography, website, birthday, gender} = info; // user should always have a birthday, but a safety check here birthday = birthday && moment(birthday).format('YYYY-MM-DD'); - callback({name, biography, website, birthday, gender}); + return {name, biography, website, birthday, gender}; } } catch (error) { Alert.alert( @@ -43,11 +38,7 @@ export const loadProfileInfo = async ( } }; -export const loadAvatar = async ( - token: string, - userId: string, - callback: Function, -) => { +export const loadAvatar = async (token: string, userId: string) => { try { const response = await RNFetchBlob.config({ fileCache: true, @@ -57,20 +48,16 @@ export const loadAvatar = async ( }); const status = response.info().status; if (status === 200) { - callback(response.path()); + return response.path(); } else { - callback(''); + return ''; } } catch (error) { console.log(error); } }; -export const loadCover = async ( - token: string, - userId: string, - callback: Function, -) => { +export const loadCover = async (token: string, userId: string) => { try { let response = await RNFetchBlob.config({ fileCache: true, @@ -80,9 +67,9 @@ export const loadCover = async ( }); const status = response.info().status; if (status === 200) { - callback(response.path()); + return response.path(); } else { - callback(''); + return ''; } } catch (error) { console.log(error); @@ -124,37 +111,10 @@ 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) => { +export const loadRecentlySearchedUsers = async () => { try { const asyncCache = await AsyncStorage.getItem('@recently_searched_users'); - asyncCache != null ? callback(JSON.parse(asyncCache)) : null; + return asyncCache != null ? JSON.parse(asyncCache) : null; } catch (e) { console.log(e); } |