aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShravya Ramesh <shravs1208@gmail.com>2021-03-03 17:20:09 -0800
committerShravya Ramesh <shravs1208@gmail.com>2021-03-05 20:46:06 -0800
commit8fcc1b9c2d272bf36f2e9ffa24c7705a5e86b004 (patch)
treed7430d07181b8e461948a0ac9b0dc712d86311e1
parent26d70baab29919f999f0369277c7929e44f4d7b0 (diff)
Service to get users for discover page
-rw-r--r--src/services/ExploreService.ts27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/services/ExploreService.ts b/src/services/ExploreService.ts
index dc58bdd0..503782b1 100644
--- a/src/services/ExploreService.ts
+++ b/src/services/ExploreService.ts
@@ -1,6 +1,6 @@
import AsyncStorage from '@react-native-community/async-storage';
import {ALL_USERS_ENDPOINT, DISCOVER_ENDPOINT} from '../constants';
-import {EMPTY_EXPLORE_SECTIONS} from '../store/initialStates';
+import {EMPTY_PROFILE_PREVIEW_LIST} from '../store/initialStates';
import {ExploreSectionType, ProfilePreviewType} from '../types';
export const getAllTaggUsers = async (token: string) => {
@@ -40,7 +40,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 +58,26 @@ export const getAllExploreSections = async () => {
console.log('Unable to fetch explore data');
}
};
+
+export const getDiscoverUsers = async (id: number) => {
+ try {
+ const token = await AsyncStorage.getItem('token');
+ console.log('Auth: ', 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();
+ console.log('USERS: ', data);
+ return data.users;
+ } catch (error) {
+ console.log('Error fetching SP user data');
+ console.log(error);
+ return [];
+ }
+};