aboutsummaryrefslogtreecommitdiff
path: root/src/components/search/SearchResultCell.tsx
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-03-08 16:27:08 -0500
committerGitHub <noreply@github.com>2021-03-08 16:27:08 -0500
commitd77f43663fbe409b011b5509bcbff3d07f8ded55 (patch)
tree6bef0a405a92185d08b0850d199ee507e8bfe90c /src/components/search/SearchResultCell.tsx
parent7e5f9c63360f8c4505bb414384e13f8c0f7576e4 (diff)
parent973c8a03681724f2e303fcd021301764bfc4717c (diff)
Merge pull request #286 from leonyjiang/tma660-recently-searched-categories
[TMA-660] Recently Searched Categories
Diffstat (limited to 'src/components/search/SearchResultCell.tsx')
-rw-r--r--src/components/search/SearchResultCell.tsx33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/components/search/SearchResultCell.tsx b/src/components/search/SearchResultCell.tsx
index 0f6f5b7d..e0351d96 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"
@@ -156,8 +167,8 @@ const SearchResultsCell: React.FC<SearchResults> = ({
const styles = StyleSheet.create({
cellContainer: {
flexDirection: 'row',
- marginHorizontal: SCREEN_WIDTH * 0.08,
- marginBottom: SCREEN_WIDTH * 0.08,
+ paddingHorizontal: 25,
+ paddingVertical: 15,
},
imageContainer: {
width: SCREEN_WIDTH * 0.112,