diff options
author | Ivan Chen <ivan@thetaggid.com> | 2021-03-06 01:13:43 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-06 01:13:43 -0500 |
commit | 3c38b38e0d3b2946a84c3d3bfd32cd223095e63d (patch) | |
tree | 0f7986f41f2b9d793779e479d33d877ce0f0f3c1 /src/services/ExploreService.ts | |
parent | cae6a7f3b8cc35c60f99e503d328c134959e13ec (diff) | |
parent | 51e36759249413a2acd52e1fecf4661f5253cb89 (diff) |
Merge pull request #283 from shravyaramesh/search-revamp-2
[TMA 661/662] Created new search screen
Diffstat (limited to 'src/services/ExploreService.ts')
-rw-r--r-- | src/services/ExploreService.ts | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/src/services/ExploreService.ts b/src/services/ExploreService.ts index dc58bdd0..33b79b4a 100644 --- a/src/services/ExploreService.ts +++ b/src/services/ExploreService.ts @@ -1,7 +1,15 @@ 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'; +import { + ALL_USERS_ENDPOINT, + DISCOVER_ENDPOINT, + SEARCH_BUTTONS_ENDPOPINT, +} from '../constants'; +import {EMPTY_PROFILE_PREVIEW_LIST} from '../store/initialStates'; +import { + ExploreSectionType, + ProfilePreviewType, + SearchCategoryType, +} from '../types'; export const getAllTaggUsers = async (token: string) => { try { @@ -40,7 +48,7 @@ export const getAllExploreSections = async () => { }, }); if (response.status !== 200) { - return EMPTY_EXPLORE_SECTIONS; + return EMPTY_PROFILE_PREVIEW_LIST; } const data = await response.json(); const exploreSections: Record<ExploreSectionType, ProfilePreviewType[]> = { @@ -58,3 +66,42 @@ export const getAllExploreSections = async () => { console.log('Unable to fetch explore data'); } }; + +export const getDiscoverUsers = async (id: number) => { + try { + const token = await AsyncStorage.getItem('token'); + const response = await fetch(DISCOVER_ENDPOINT + `${id}/`, { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }); + if (response.status !== 200) { + return EMPTY_PROFILE_PREVIEW_LIST; + } + const data = await response.json(); + const users: ProfilePreviewType[] = data.users; + return users; + } catch (error) { + console.log('Error fetching SP user data'); + console.log(error); + return []; + } +}; + +export const getButtons = async () => { + const token = await AsyncStorage.getItem('token'); + const response = await fetch(SEARCH_BUTTONS_ENDPOPINT, { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }); + + if (response.status !== 200) { + return []; + } + + const data: SearchCategoryType[] = await response.json(); + return data; +}; |