From 7e1e9a443a7e38fdbe21129c3d3c853f75bd3162 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 5 Mar 2021 16:58:21 -0800 Subject: getting buttons from backend for search page --- src/components/search/DiscoverUsers.tsx | 8 +------ src/components/search/SearchCategories.tsx | 36 +++++++++++++----------------- src/constants/api.ts | 1 + src/services/ExploreService.ts | 29 ++++++++++++++++++++++-- src/types/types.ts | 6 +++++ 5 files changed, 50 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/components/search/DiscoverUsers.tsx b/src/components/search/DiscoverUsers.tsx index ec0a8daa..93fcb02d 100644 --- a/src/components/search/DiscoverUsers.tsx +++ b/src/components/search/DiscoverUsers.tsx @@ -1,11 +1,5 @@ import React from 'react'; -import { - View, - Text, - TouchableOpacity, - StyleSheet, - TouchableOpacityProps, -} from 'react-native'; +import {View, Text, StyleSheet, TouchableOpacityProps} from 'react-native'; import {PreviewType, ProfilePreviewType, ScreenType} from '../../types'; import SearchResults from './SearchResults'; diff --git a/src/components/search/SearchCategories.tsx b/src/components/search/SearchCategories.tsx index 30de7e2c..b674c963 100644 --- a/src/components/search/SearchCategories.tsx +++ b/src/components/search/SearchCategories.tsx @@ -1,35 +1,29 @@ import {useNavigation} from '@react-navigation/native'; -import React from 'react'; +import React, {useEffect, useState} from 'react'; import {StyleSheet, Text, View} from 'react-native'; import {TouchableOpacity} from 'react-native-gesture-handler'; import LinearGradient from 'react-native-linear-gradient'; +import {getButtons} from '../../services/ExploreService'; +import {SearchCategoryType} from 'src/types'; import {TAGG_LIGHT_BLUE_2, TAGG_PURPLE} from '../../constants'; import {SCREEN_WIDTH} from '../../utils'; const SearchCategories: React.FC = () => { - const categories = [ - { - id: 4, - name: "Brown '21", - }, - { - id: 5, - name: "Brown '22", - }, - { - id: 6, - name: "Brown '23", - }, - { - id: 7, - name: "Brown '24", - }, - ]; + const [buttons, setButtons] = useState([]); + useEffect(() => { + const loadButtons = async () => { + const localButtons = await getButtons(); + console.log('localButtons: ', localButtons); + await setButtons(localButtons); + }; + loadButtons(); + }, []); + const navigation = useNavigation(); return ( - {categories && - categories.map((searchCategory) => ( + {buttons && + buttons.map((searchCategory) => ( { try { @@ -80,3 +88,20 @@ export const getDiscoverUsers = async (id: number) => { 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; +}; diff --git a/src/types/types.ts b/src/types/types.ts index 7cd11f7a..8adeb9c1 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -245,3 +245,9 @@ export type FriendshipType = { status: FriendshipStatusType; requester_id: string; }; + +export type SearchCategoryType = { + id: number; + name: string; + category: string; +} \ No newline at end of file -- cgit v1.2.3-70-g09d2