aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLeon Jiang <35908040+leonyjiang@users.noreply.github.com>2021-03-08 03:38:25 -0500
committerLeon Jiang <35908040+leonyjiang@users.noreply.github.com>2021-03-08 03:38:25 -0500
commit5ad6895e17afb110d4d85388b479d875597b01a5 (patch)
tree8ee63f18b4ba6fc287228167a7085486b77d835f /src
parent46a578b5cc9c3230448e8d9db0ba6ff75d5b8852 (diff)
Add handler for category search result selection
Diffstat (limited to 'src')
-rw-r--r--src/components/search/SearchResultCell.tsx29
1 files changed, 20 insertions, 9 deletions
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<SearchResults> = ({
return;
}
- await addUserToRecentlyViewed({
+ addUserToRecentlyViewed({
id,
first_name,
last_name,
@@ -99,6 +105,17 @@ const SearchResultsCell: React.FC<SearchResults> = ({
}
};
+ /*
+ * 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 (
<TouchableOpacity
@@ -129,13 +146,7 @@ const SearchResultsCell: React.FC<SearchResults> = ({
const categoryCell = () => {
return (
- <TouchableOpacity
- style={styles.cellContainer}
- onPress={() =>
- navigation.navigate('DiscoverUsers', {
- searchCategory: {id, name},
- })
- }>
+ <TouchableOpacity style={styles.cellContainer} onPress={onPressCategory}>
<View style={[styles.imageContainer, styles.categoryBackground]}>
<Image
resizeMode="contain"