diff options
author | Ivan Chen <ivan@tagg.id> | 2021-03-25 15:00:48 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-25 15:00:48 -0400 |
commit | 99de9c8402f470ead242a81510dc2764ae7d9e66 (patch) | |
tree | 7bf2feb0f1a57f1c695ddea51afb9e95abf03f0a /src/utils/users.ts | |
parent | 75c08439fe04666a63431bf56e4b2fa7fb05cbbe (diff) | |
parent | 54de628b27647099170bc6d5eea7110c8dd5e8f0 (diff) |
Merge pull request #323 from IvanIFChen/tma698-api-profile
[TMA-698] api/profile
Diffstat (limited to 'src/utils/users.ts')
-rw-r--r-- | src/utils/users.ts | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/utils/users.ts b/src/utils/users.ts index 82bcb309..d5e44b36 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -20,7 +20,7 @@ import {RootState} from './../store/rootReducer'; import { ProfilePreviewType, CategoryPreviewType, - ProfileType, + ProfileInfoType, ScreenType, UserType, } from './../types/types'; @@ -103,13 +103,22 @@ export const userXInStore = ( * Abstracted the code to laod all socials out. * @param userId userId for whom socials should be fetched */ -export const loadAllSocialsForUser = async (userId: string) => { +export const loadAllSocialsForUser = async (userId: string, token?: string) => { + if (!token) { + token = (await AsyncStorage.getItem('token')) ?? ''; + } let socials = NO_SOCIAL_ACCOUNTS; try { - let socialNeedsUpdate = INTEGRATED_SOCIAL_LIST; - for (let socialType of socialNeedsUpdate) { - const social = await loadSocialPosts(userId, socialType); - socials = {...socials, [socialType]: social}; + const fetchedSocials = await Promise.all( + INTEGRATED_SOCIAL_LIST.map((socialType) => + loadSocialPosts(userId, socialType, token).then((data) => ({ + key: socialType, + data, + })), + ), + ); + for (const fetchedSocial of fetchedSocials) { + socials = {...socials, [fetchedSocial.key]: fetchedSocial.data}; } return socials; } catch (error) { @@ -137,7 +146,7 @@ export const getTokenOrLogout = async (dispatch: Function): Promise<string> => { */ export const getUserAsProfilePreviewType = ( passedInUser: UserType, - passedInProfile: ProfileType, + passedInProfile: ProfileInfoType, ): ProfilePreviewType => { const fullName = passedInProfile.name.split(' '); return { @@ -165,4 +174,3 @@ export const defaultUserProfile = () => { const defaultImage = require('../assets/images/avatar-placeholder.png'); return defaultImage; }; - |