aboutsummaryrefslogtreecommitdiff
path: root/src/services/SearchService.ts
blob: 672c1ec6cfeb462d1f4cf856b8224f2d448360e1 (plain)
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
import AsyncStorage from '@react-native-community/async-storage';
import {ProfilePreviewType} from '../types';

export const loadSearchResults = async (url: string) => {
  try {
    const token = await AsyncStorage.getItem('token');
    const response = await fetch(url, {
      method: 'GET',
      headers: {
        Authorization: 'Token ' + token,
      },
    });
    const {status} = response;
    if (status === 200) {
      const searchResults: {
        users: ProfilePreviewType[];
      } = await response.json();
      return searchResults;
    }
  } catch (error) {
    console.log(error);
    return undefined;
  }
  return undefined;
};