From 5ad6895e17afb110d4d85388b479d875597b01a5 Mon Sep 17 00:00:00 2001 From: Leon Jiang <35908040+leonyjiang@users.noreply.github.com> Date: Mon, 8 Mar 2021 03:38:25 -0500 Subject: Add handler for category search result selection --- src/components/search/SearchResultCell.tsx | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/components/search/SearchResultCell.tsx b/src/components/search/SearchResultCell.tsx index 0f6f5b7d..8f7d922f 100644 --- a/src/components/search/SearchResultCell.tsx +++ b/src/components/search/SearchResultCell.tsx @@ -6,7 +6,12 @@ import {useDispatch, useStore} from 'react-redux'; import {ERROR_UNABLE_TO_VIEW_PROFILE} from '../../constants/strings'; import {loadImageFromURL} from '../../services'; import {RootState} from '../../store/rootReducer'; -import {ProfilePreviewType, ScreenType, UserType} from '../../types'; +import { + ProfilePreviewType, + ScreenType, + UserType, + CategoryPreviewType, +} from '../../types'; import {normalize, SCREEN_WIDTH} from '../../utils'; import { addUserToRecentlyViewed, @@ -14,6 +19,7 @@ import { defaultUserProfile, fetchUserX, userXInStore, + addCategoryToRecentlySearched, } from '../../utils/users'; interface SearchResults { @@ -66,7 +72,7 @@ const SearchResultsCell: React.FC = ({ return; } - await addUserToRecentlyViewed({ + addUserToRecentlyViewed({ id, first_name, last_name, @@ -99,6 +105,17 @@ const SearchResultsCell: React.FC = ({ } }; + /* + * Save selected category in recently-searched categories and navigate to its Discover screen. + */ + const onPressCategory = async () => { + const categoryObj: CategoryPreviewType = {name, category}; + addCategoryToRecentlySearched(categoryObj); + navigation.navigate('DiscoverUsers', { + searchCategory: {id, name}, + }); + }; + const userCell = () => { return ( = ({ const categoryCell = () => { return ( - - navigation.navigate('DiscoverUsers', { - searchCategory: {id, name}, - }) - }> +