diff options
author | Ashm Walia <40498934+ashmgarv@users.noreply.github.com> | 2020-12-04 08:50:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-04 11:50:24 -0500 |
commit | 0fd892ad288f2e1eaaa4fdf5e1fd6f15dbd45860 (patch) | |
tree | d7d53d94c6c4026ac9b325508ebce4706d412ac4 /src/services/UserProfileService.ts | |
parent | f620102190629e0b6f180d3ce056d850b1db5aaa (diff) |
[TMA - 398 AND TMA-430] Replace Providers with Redux Store (#125)
* First
* WIP
* Thunk
* Some more comments
* sc
* recent searches and follounfollow
* Edit profile dummy
* Block / unblock and some cleanup
* Replace auth provider
* Sc
* Delete AP after rebase
* Discover users
* Cleanup
* More cleanup
* Replace profile provider
* Fixed build failure
* Fixed a bug reported
* Prevent app crash when backend server is down
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); } |