diff options
| author | ankit-thanekar007 <ankit.thanekar007@gmail.com> | 2021-03-02 13:04:27 -0800 |
|---|---|---|
| committer | ankit-thanekar007 <ankit.thanekar007@gmail.com> | 2021-03-03 12:44:58 -0800 |
| commit | 7a5ae728ee96acdf6b52fefa6ebaf7640a8724a1 (patch) | |
| tree | 5eca9475afee1354801964879a1732cce993d0c8 /src/screens/search/SearchScreen.tsx | |
| parent | d73e99036e5b78a9b7dbcc43e9a87aa6f9c1faeb (diff) | |
TMA-663-Updated Search init
Diffstat (limited to 'src/screens/search/SearchScreen.tsx')
| -rw-r--r-- | src/screens/search/SearchScreen.tsx | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/src/screens/search/SearchScreen.tsx b/src/screens/search/SearchScreen.tsx index 84efa931..c3bd9fec 100644 --- a/src/screens/search/SearchScreen.tsx +++ b/src/screens/search/SearchScreen.tsx @@ -18,6 +18,7 @@ import { SearchHeader, SearchResults, SearchResultsBackground, + SearchResultList, TabsGradient, } from '../../components'; import {SEARCH_ENDPOINT, TAGG_LIGHT_BLUE} from '../../constants'; @@ -25,6 +26,7 @@ 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: '', @@ -38,7 +40,7 @@ const NO_USER: UserType = { const SearchScreen: React.FC = () => { const {recentSearches} = useSelector((state: RootState) => state.taggUsers); const [query, setQuery] = useState<string>(''); - const [results, setResults] = useState<Array<ProfilePreviewType>>([]); + const [results, setResults] = useState([]); const [recents, setRecents] = useState<Array<ProfilePreviewType>>( recentSearches ?? [], ); @@ -64,25 +66,37 @@ const SearchScreen: React.FC = () => { return; } const loadResults = async (q: string) => { - try { - const token = await AsyncStorage.getItem('token'); - const response = await fetch(`${SEARCH_ENDPOINT}?query=${q}`, { - method: 'GET', - headers: { - Authorization: 'Token ' + token, - }, - }); - const status = response.status; - if (status === 200) { - let searchResults = await response.json(); - setResults(searchResults); - return; - } - setResults([]); - } catch (error) { - console.log(error); - setResults([]); - } + // try { + // const token = await AsyncStorage.getItem('token'); + // const response = await fetch(`${SEARCH_ENDPOINT}?query=${q}`, { + // method: 'GET', + // headers: { + // Authorization: 'Token ' + token, + // }, + // }); + // const status = response.status; + // if (status === 200) { + // let searchResults = await response.json(); + // setResults(searchResults); + // return; + // } + // 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); }, [query]); @@ -161,7 +175,7 @@ const SearchScreen: React.FC = () => { /> <Explore /> <SearchResultsBackground {...{top}}> - {results.length === 0 && recents.length !== 0 ? ( + {results && Object.keys(results).length === 0 ? ( <RecentSearches sectionTitle="Recent" sectionButtonTitle="Clear all" @@ -170,7 +184,7 @@ const SearchScreen: React.FC = () => { screenType={ScreenType.Search} /> ) : ( - <SearchResults + <SearchResultList {...{results}} previewType={'Search'} screenType={ScreenType.Search} |
