diff options
author | George Rusu <56009869+grusu6928@users.noreply.github.com> | 2020-10-25 15:21:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-25 18:21:38 -0400 |
commit | 9da19cdcb6c7596d60afde6d0d559f06a24a0627 (patch) | |
tree | 8f11b6e0a5fcdc2eb983d498fa7b016d4daf44ba /src/services/UserProfileService.ts | |
parent | 44a25bfabd356f5eee5ec4f580452407a7e40246 (diff) |
[TMA-237] Added modal for user registration and redirect (#61)
* move async-storage
* removed lock files
* added lock files to gitignore
* added the wrong file to gitignore
* added modal for user registration and redirect
* api call to get list of linked socials for each user to display appropriate icon
* fixed indentation and linting
* refactored modal and browser sign-in
* now dynamically adding linked and unlinked taggs, added a bunch of TODOs for tomorrow
* added svg icons
* done? finished taggs bar UI and all the navigations including modal
* fixed some bugs and added more TODOs
* fixed some bugs and refactored posts fetching logic
* fixed taggs bar bug
* done, it will update everything correctly
* added comments
* added tiktok
Co-authored-by: hsalhab <husam_salhab@brown.edu>
Co-authored-by: george <grus6928@gmail.com>
Co-authored-by: Ivan Chen <ivan@thetaggid.com>
Diffstat (limited to 'src/services/UserProfileService.ts')
-rw-r--r-- | src/services/UserProfileService.ts | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index f5523be4..31383f67 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -1,16 +1,18 @@ //Abstracted common profile api calls out here +import AsyncStorage from '@react-native-community/async-storage'; import {Alert} from 'react-native'; +import RNFetchBlob from 'rn-fetch-blob'; +import {SocialAccountType} from 'src/types'; import { - PROFILE_INFO_ENDPOINT, AVATAR_PHOTO_ENDPOINT, COVER_PHOTO_ENDPOINT, + GET_FB_POSTS_ENDPOINT, + GET_IG_POSTS_ENDPOINT, + GET_TWITTER_POSTS_ENDPOINT, + PROFILE_INFO_ENDPOINT, } from '../constants'; -import AsyncStorage from '@react-native-community/async-storage'; -import RNFetchBlob from 'rn-fetch-blob'; -import {SocialAccountType} from 'src/types'; - export const loadProfileInfo = async ( token: string, userId: string, @@ -83,13 +85,19 @@ export const loadCover = async ( } }; -export const loadSocialPosts = async ( - token: string, +const integratedSocialPostsEndpoints: {[social: string]: string} = { + Facebook: GET_FB_POSTS_ENDPOINT, + Instagram: GET_IG_POSTS_ENDPOINT, + Twitter: GET_TWITTER_POSTS_ENDPOINT, +}; + +export const loadSocialPosts: ( userId: string, socialType: string, - endpoint: string, - socialAccounts: Record<string, SocialAccountType>, -) => { +) => Promise<SocialAccountType> = async (userId, socialType) => { + const token = await AsyncStorage.getItem('token'); + const endpoint = integratedSocialPostsEndpoints[socialType]; + const accountData: SocialAccountType = {}; try { const response = await fetch(endpoint + `${userId}/`, { method: 'GET', @@ -99,16 +107,16 @@ export const loadSocialPosts = async ( }); if (response.status === 200) { const body = await response.json(); - socialAccounts[socialType].handle = body.handle; - socialAccounts[socialType].posts = body.posts; - socialAccounts[socialType].profile_pic = body.profile_pic; + accountData.handle = body.handle; + accountData.posts = body.posts; + accountData.profile_pic = body.profile_pic; } else { - throw new Error(await response.json()); + throw 'Unable to fetch posts data from ' + socialType; } } catch (error) { - console.log(error); + console.warn(error); } - return socialAccounts; + return accountData; }; export const loadRecentlySearchedUsers = async (callback: Function) => { |