diff options
author | Ivan Chen <ivan@thetaggid.com> | 2021-01-27 19:32:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-27 19:32:21 -0500 |
commit | 19d2a861f260c02031d951f3d43bff8ac672146d (patch) | |
tree | 253abceb267dfb75ac9118995886ff152c1ba74b /src/services/ExploreService.ts | |
parent | 60d3d97ad6913369762877a9dbfdaac0473deb28 (diff) | |
parent | dc9556867dd44b706c43678d40802a335ff40658 (diff) |
Merge pull request #203 from IvanIFChen/tma577-profile-slowness
[TMA-577] Profile Slowness
Diffstat (limited to 'src/services/ExploreService.ts')
-rw-r--r-- | src/services/ExploreService.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/services/ExploreService.ts b/src/services/ExploreService.ts new file mode 100644 index 00000000..980258be --- /dev/null +++ b/src/services/ExploreService.ts @@ -0,0 +1,59 @@ +import AsyncStorage from '@react-native-community/async-storage'; +import {ALL_USERS_ENDPOINT, DISCOVER_ENDPOINT} from '../constants'; +import {EMPTY_EXPLORE_SECTIONS} from '../store/initialStates'; +import {ExploreSectionType, ProfilePreviewType} from '../types'; + +export const getAllTaggUsers = async (token: string) => { + try { + const response = await fetch(ALL_USERS_ENDPOINT, { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }); + const status = response.status; + if (status === 200) { + const response_data = await response.json(); + return response_data; + } else { + console.log( + 'Something went wrong! ðŸ˜', + 'Not able to retrieve tagg users list', + ); + } + } catch (error) { + console.log( + 'Something went wrong! ðŸ˜', + 'Not able to retrieve tagg users list', + error, + ); + } +}; + +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_EXPLORE_SECTIONS; + } + const data = await response.json(); + 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, + "Brown '22": data.categories.brown_22, + "Brown '23": data.categories.brown_23, + }; + + return exploreSections; + } catch (error) { + console.log('Unable to fetch explore data'); + } +}; |