1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
import AsyncStorage from '@react-native-community/async-storage';
import {
ALL_USERS_ENDPOINT,
DISCOVER_ENDPOINT,
SEARCH_BUTTONS_ENDPOPINT,
} from '../constants';
import {ProfilePreviewType, SearchCategoryType} 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 getDiscoverUsers = async (categoryName: string) => {
try {
const token = await AsyncStorage.getItem('token');
const url = `${DISCOVER_ENDPOINT}get_users/?category=${categoryName}`;
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: 'Token ' + token,
},
});
if (response.status !== 200) {
return undefined;
}
const users: ProfilePreviewType[] = await response.json();
return users;
} catch (error) {
console.log('Error fetching SP user data');
console.log(error);
return undefined;
}
};
export const getSuggestedSearchBubbleSuggestions = async () => {
try {
const token = await AsyncStorage.getItem('token');
const response = await fetch(SEARCH_BUTTONS_ENDPOPINT, {
method: 'GET',
headers: {
Authorization: 'Token ' + token,
},
});
if (response.status !== 200) {
return undefined;
}
const data: SearchCategoryType[] = await response.json();
return data;
} catch (error) {
console.log('Error fetching suggested search bubble suggestions');
console.log(error);
return undefined;
}
};
|