diff options
author | Ivan Chen <ivan@tagg.id> | 2021-03-26 15:33:37 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-03-26 15:33:37 -0400 |
commit | 9be7248ba54eeb2ad4d19edd4c01ee736b58bfcd (patch) | |
tree | 6f66b86bbe9adaffb7d866b22a89e0e3f78f26a3 /src/utils | |
parent | 883a6c51d4c3e442df5e6c0f3dc6fada2f370f8e (diff) | |
parent | 99de9c8402f470ead242a81510dc2764ae7d9e66 (diff) |
Merge branch 'master' into tma728-select-school-onboarding
# Conflicts:
# src/services/UserProfileService.ts
# src/types/types.ts
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/friends.ts | 4 | ||||
-rw-r--r-- | src/utils/users.ts | 24 |
2 files changed, 18 insertions, 10 deletions
diff --git a/src/utils/friends.ts b/src/utils/friends.ts index 55d65170..5b0ded8f 100644 --- a/src/utils/friends.ts +++ b/src/utils/friends.ts @@ -1,7 +1,7 @@ // Handles click on friend/requested/unfriend button import {RootState} from '../store/rootReducer'; -import {ProfilePreviewType, ProfileType, ScreenType, UserType} from '../types'; +import {ProfilePreviewType, ProfileInfoType, ScreenType, UserType} from '../types'; import {AppDispatch} from '../store/configureStore'; import { addFriend, @@ -25,7 +25,7 @@ import {getUserAsProfilePreviewType} from './users'; export const handleFriendUnfriend = async ( screenType: ScreenType, user: UserType, - profile: ProfileType, + profile: ProfileInfoType, dispatch: AppDispatch, state: RootState, loggedInUser: UserType, 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; }; - |