diff options
| author | Ivan Chen <ivan@tagg.id> | 2021-03-26 16:04:52 -0400 |
|---|---|---|
| committer | Ivan Chen <ivan@tagg.id> | 2021-03-26 16:04:52 -0400 |
| commit | 37af16ccea748d2108505e21a8323244f2296441 (patch) | |
| tree | 3b1d03654abc37753e1d6ee744d4708e11df33bc /src/services | |
| parent | 8ce46790a8d12df6738d8ac17462ba57e2b0e6b9 (diff) | |
| parent | 99de9c8402f470ead242a81510dc2764ae7d9e66 (diff) | |
Merge branch 'master' into tma-722-cornell-fe
# Conflicts:
# src/constants/constants.ts
# src/services/ExploreService.ts
# src/services/UserProfileService.ts
# src/types/types.ts
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/ExploreService.ts | 37 | ||||
| -rw-r--r-- | src/services/UserFriendsService.ts | 3 | ||||
| -rw-r--r-- | src/services/UserProfileService.ts | 116 |
3 files changed, 48 insertions, 108 deletions
diff --git a/src/services/ExploreService.ts b/src/services/ExploreService.ts index df52b4e3..44df8056 100644 --- a/src/services/ExploreService.ts +++ b/src/services/ExploreService.ts @@ -4,12 +4,7 @@ import { DISCOVER_ENDPOINT, SEARCH_BUTTONS_ENDPOPINT, } from '../constants'; -import {EMPTY_PROFILE_PREVIEW_LIST} from '../store/initialStates'; -import { - ExploreSectionType, - ProfilePreviewType, - SearchCategoryType, -} from '../types'; +import {ProfilePreviewType, SearchCategoryType} from '../types'; export const getAllTaggUsers = async (token: string) => { try { @@ -38,36 +33,6 @@ export const getAllTaggUsers = async (token: string) => { } }; -export const getAllExploreSections = async () => { - try { - const token = await AsyncStorage.getItem('token'); - const response = await fetch(DISCOVER_ENDPOINT, { - method: 'GET', - headers: { - Authorization: 'Token ' + token, - }, - }); - if (response.status !== 200) { - return EMPTY_PROFILE_PREVIEW_LIST; - } - const data = await response.json(); - // TODO (if we return to original explore format): get keys from backend API - const exploreSections: Record<ExploreSectionType, ProfilePreviewType[]> = { - 'New to Tagg': data.categories.new_to_tagg, - 'People You May Know': data.categories.people_you_may_know, - 'Trending on Tagg': data.categories.trending_on_tagg, - "Brown '21": data.categories.brown_21, //TODO: Update for Cornell - "Brown '22": data.categories.brown_22, - "Brown '23": data.categories.brown_23, - "Brown '24": data.categories.brown_24, - }; - - return exploreSections; - } catch (error) { - console.log('Unable to fetch explore data'); - } -}; - export const getDiscoverUsers = async (categoryName: string) => { try { const token = await AsyncStorage.getItem('token'); diff --git a/src/services/UserFriendsService.ts b/src/services/UserFriendsService.ts index c36cdaa7..da39380f 100644 --- a/src/services/UserFriendsService.ts +++ b/src/services/UserFriendsService.ts @@ -24,12 +24,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 22492124..e00c0530 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -1,7 +1,6 @@ import AsyncStorage from '@react-native-community/async-storage'; import moment from 'moment'; import {Alert} from 'react-native'; -import RNFetchBlob from 'rn-fetch-blob'; import { GET_FB_POSTS_ENDPOINT, GET_IG_POSTS_ENDPOINT, @@ -10,10 +9,10 @@ import { PASSWORD_RESET_ENDPOINT, PROFILE_INFO_ENDPOINT, PROFILE_PHOTO_ENDPOINT, - PROFILE_PHOTO_THUMBNAIL_ENDPOINT, REGISTER_ENDPOINT, SEND_OTP_ENDPOINT, TAGG_CUSTOMER_SUPPORT, + USER_PROFILE_ENDPOINT, VERIFY_OTP_ENDPOINT, } from '../constants'; import { @@ -27,7 +26,7 @@ import { SUCCESS_PWD_RESET, SUCCESS_VERIFICATION_CODE_SENT, } from '../constants/strings'; -import {SocialAccountType} from '../types'; +import {ProfileInfoType, ProfileType, SocialAccountType} from '../types'; export const loadProfileInfo = async (token: string, userId: string) => { try { @@ -39,37 +38,11 @@ export const loadProfileInfo = async (token: string, userId: string) => { }); const status = response.status; if (status === 200) { - const info = await response.json(); - let { - name, - biography, - website, - birthday, - gender, - snapchat, - tiktok, - university, - university_class, - profile_completion_stage, - suggested_people_linked, - friendship_status, - friendship_requester_id, - } = info; - birthday = birthday && moment(birthday).format('YYYY-MM-DD'); + const data: ProfileInfoType = await response.json(); + const birthday = data.birthday; return { - name, - biography, - website, - birthday, - gender, - snapchat, - tiktok, - university, - university_class, - profile_completion_stage, - suggested_people_linked, - friendship_status, - friendship_requester_id, + ...data, + birthday: birthday && moment(birthday).format('YYYY-MM-DD'), }; } else { throw 'Unable to load profile data'; @@ -79,43 +52,22 @@ export const loadProfileInfo = async (token: string, userId: string) => { } }; -export const loadAvatar = async (userId: string, thumbnail: boolean) => { - try { - const token = await AsyncStorage.getItem('token'); - const url = thumbnail - ? PROFILE_PHOTO_THUMBNAIL_ENDPOINT - : PROFILE_PHOTO_ENDPOINT; - const response = await RNFetchBlob.config({ - fileCache: true, - appendExt: 'jpg', - }).fetch('GET', url + `${userId}/`, { - Authorization: 'Token ' + token, - }); - const status = response.info().status; - if (status === 200) { - return response.path(); - } else { - return ''; - } - } catch (error) { - console.log(error); - return ''; - } -}; - -export const loadCover = async (token: string, userId: string) => { +export const getProfilePic = async ( + token: string, + userId: string, + type: 'profile' | 'header', +) => { try { - let response = await RNFetchBlob.config({ - fileCache: true, - appendExt: 'jpg', - }).fetch('GET', HEADER_PHOTO_ENDPOINT + `${userId}/`, { - Authorization: 'Token ' + token, + const url = + type === 'profile' ? PROFILE_PHOTO_ENDPOINT : HEADER_PHOTO_ENDPOINT; + const response = await fetch(url + `${userId}/`, { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, }); - const status = response.info().status; - if (status === 200) { - return response.path(); - } else { - return ''; + if (response.status === 200) { + return (await response.json()).url; } } catch (error) { console.log(error); @@ -131,8 +83,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 = []; @@ -358,3 +313,24 @@ export const sendRegister = async ( return undefined; } }; + +export const fetchUserProfile = async (userId: string, token?: string) => { + try { + if (!token) { + token = (await AsyncStorage.getItem('token')) ?? ''; + } + const response = await fetch(USER_PROFILE_ENDPOINT + userId + '/', { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }); + if (response.status === 200) { + const data: ProfileType = await response.json(); + return data; + } + } catch (error) { + console.log(error); + return undefined; + } +}; |
