aboutsummaryrefslogtreecommitdiff
path: root/src/screens
diff options
context:
space:
mode:
authorankit-thanekar007 <ankit.thanekar007@gmail.com>2021-03-03 12:34:33 -0800
committerankit-thanekar007 <ankit.thanekar007@gmail.com>2021-03-03 12:44:59 -0800
commit95bc850b9db986b9f462f19d7801218027307d58 (patch)
treed6570947809050961b14237471ce416772ca97ff /src/screens
parentaf349a745bb00b5260f84909320d511ae9d0af2b (diff)
TMA-663-Search Integration
Diffstat (limited to 'src/screens')
-rw-r--r--src/screens/search/SearchScreen.tsx107
1 files changed, 43 insertions, 64 deletions
diff --git a/src/screens/search/SearchScreen.tsx b/src/screens/search/SearchScreen.tsx
index 39b0425d..a66a2cbc 100644
--- a/src/screens/search/SearchScreen.tsx
+++ b/src/screens/search/SearchScreen.tsx
@@ -16,21 +16,15 @@ import {
SearchBackground,
SearchBar,
SearchHeader,
- SearchResults,
- SearchResultsBackground,
SearchResultList,
+ SearchResultsBackground,
TabsGradient,
} from '../../components';
-import {
- SEARCH_ENDPOINT,
- SEARCH_V2_ENDPOINT,
- TAGG_LIGHT_BLUE,
-} from '../../constants';
+import {SEARCH_V2_ENDPOINT, TAGG_LIGHT_BLUE} from '../../constants';
import {loadRecentlySearched, resetScreenType} from '../../store/actions';
import {RootState} from '../../store/rootReducer';
import {ProfilePreviewType, ScreenType, UserType} from '../../types';
import {SCREEN_HEIGHT, SCREEN_WIDTH, StatusBarHeight} from '../../utils';
-import MockResults from './mock';
const NO_USER: UserType = {
userId: '',
username: '',
@@ -69,62 +63,45 @@ const SearchScreen: React.FC = () => {
setResults([]);
return;
}
- // const loadResults = async (q: string) => {
- // try {
- // const token = await AsyncStorage.getItem('token');
- // const response = await fetch(`${SEARCH_V2_ENDPOINT}?query=${q}`, {
- // method: 'GET',
- // headers: {
- // Authorization: 'Token ' + token,
- // },
- // });
- // const {status} = response;
- // if (status === 200) {
- // const searchResults = await response.json();
- // const sanitizedResult = [
- // {
- // title: 'categories',
- // data: searchResults.categories,
- // },
- // {
- // title: 'users',
- // data: searchResults.users,
- // },
- // ];
- // setResults(sanitizedResult);
- // } else {
- // const searchResults = MockResults();
- // const sanitizedResult = [
- // {
- // title: 'categories',
- // data: searchResults.categories,
- // },
- // {
- // title: 'users',
- // data: searchResults.users,
- // },
- // ];
- // setResults(sanitizedResult);
- // }
- // setResults([]);
- // } catch (error) {
- // console.log(error);
- // setResults([]);
- // }
- // };
- const searchResults = MockResults();
- const sanitizedResult = [
- {
- title: 'categories',
- data: searchResults.categories,
- },
- {
- title: 'users',
- data: searchResults.users,
- },
- ];
- setResults(sanitizedResult);
- // loadResults(query);
+ const loadResults = async (q: string) => {
+ try {
+ const token = await AsyncStorage.getItem('token');
+ const response = await fetch(`${SEARCH_V2_ENDPOINT}?query=${q}`, {
+ method: 'GET',
+ headers: {
+ Authorization: 'Token ' + token,
+ },
+ });
+ const {status} = response;
+ if (status === 200) {
+ const searchResults = await response.json();
+ const sanitizedResult = [
+ {
+ title: 'categories',
+ data: searchResults.categories,
+ },
+ {
+ title: 'users',
+ data: searchResults.users,
+ },
+ ];
+
+ if (
+ searchResults.categories.length !== 0 ||
+ searchResults.users.length !== 0
+ ) {
+ if (query.length > 3) {
+ setResults(sanitizedResult);
+ return;
+ }
+ }
+ }
+ } catch (error) {
+ console.log(error);
+ }
+ setResults([]);
+ };
+ loadResults(query);
}, [query]);
/**
@@ -200,6 +177,7 @@ const SearchScreen: React.FC = () => {
{...{top, searching}}
/>
<Explore />
+
<SearchResultsBackground {...{top}}>
{results && results.length === 0 ? (
<RecentSearches
@@ -218,6 +196,7 @@ const SearchScreen: React.FC = () => {
)}
</SearchResultsBackground>
</ScrollView>
+
<TabsGradient />
</SearchBackground>
);