diff options
-rw-r--r-- | src/services/UserFriendsService.ts | 3 | ||||
-rw-r--r-- | src/services/UserProfileService.ts | 7 | ||||
-rw-r--r-- | src/store/actions/userX.ts | 2 | ||||
-rw-r--r-- | src/utils/users.ts | 8 |
4 files changed, 12 insertions, 8 deletions
diff --git a/src/services/UserFriendsService.ts b/src/services/UserFriendsService.ts index dbec1974..5ce9df29 100644 --- a/src/services/UserFriendsService.ts +++ b/src/services/UserFriendsService.ts @@ -16,12 +16,11 @@ export const loadFriends = async (userId: string, token: string) => { if (response.status === 200) { const body = await response.json(); return body; - } else { - throw new Error(await response.json()); } } catch (error) { console.log(error); } + return []; }; export const friendOrUnfriendUser = async ( diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index e733cb47..828cdbf7 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -107,8 +107,11 @@ const integratedSocialPostsEndpoints: {[social: string]: string} = { export const loadSocialPosts: ( userId: string, socialType: string, -) => Promise<SocialAccountType> = async (userId, socialType) => { - const token = await AsyncStorage.getItem('token'); + token?: string, +) => Promise<SocialAccountType> = async (userId, socialType, token) => { + if (!token) { + token = (await AsyncStorage.getItem('token')) ?? ''; + } const endpoint = integratedSocialPostsEndpoints[socialType]; const accountData: SocialAccountType = {}; accountData.posts = []; diff --git a/src/store/actions/userX.ts b/src/store/actions/userX.ts index 5d49cdf9..6302eb3c 100644 --- a/src/store/actions/userX.ts +++ b/src/store/actions/userX.ts @@ -88,7 +88,7 @@ export const loadUserX = ( }); } }); - loadAllSocialsForUser(userId).then((data) => + loadAllSocialsForUser(userId, token).then((data) => dispatch({ type: userXSocialsFetched.type, payload: {screenType, userId, data}, diff --git a/src/utils/users.ts b/src/utils/users.ts index d1f416e0..e11e8c78 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -103,12 +103,15 @@ 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); + const social = await loadSocialPosts(userId, socialType, token); socials = {...socials, [socialType]: social}; } return socials; @@ -165,4 +168,3 @@ export const defaultUserProfile = () => { const defaultImage = require('../assets/images/avatar-placeholder.png'); return defaultImage; }; - |