From 32bf3bf2cfa2f4499711225b2f1da5f3ed274832 Mon Sep 17 00:00:00 2001
From: Leon Jiang <35908040+leonyjiang@users.noreply.github.com>
Date: Mon, 8 Mar 2021 05:49:55 -0500
Subject: Add categories to recently-searched results

---
 src/components/search/SearchResults.tsx | 52 ++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 17 deletions(-)

(limited to 'src/components/search/SearchResults.tsx')

diff --git a/src/components/search/SearchResults.tsx b/src/components/search/SearchResults.tsx
index bf355220..798d3251 100644
--- a/src/components/search/SearchResults.tsx
+++ b/src/components/search/SearchResults.tsx
@@ -1,22 +1,33 @@
 import React from 'react';
-import {ProfilePreviewType, PreviewType, ScreenType} from '../../types';
+import {
+  ProfilePreviewType,
+  PreviewType,
+  ScreenType,
+  CategoryPreviewType,
+} from '../../types';
 import ProfilePreview from '../profile/ProfilePreview';
 import {StyleSheet, View} from 'react-native';
+import SearchResultsCell from './SearchResultCell';
+import {useSelector} from 'react-redux';
+import {RootState} from 'src/store/rootReducer';
 interface SearchResultsProps {
-  results: Array<ProfilePreviewType>;
+  results: ProfilePreviewType[];
   previewType: PreviewType;
   screenType: ScreenType;
+  categories: CategoryPreviewType[];
 }
 const SearchResults: React.FC<SearchResultsProps> = ({
   results,
   previewType,
   screenType,
+  categories,
 }) => {
   /**
    * Added the following swicth case to make Results on Search and Recents screen a list
    * Flex is love
    */
-  var containerStyle;
+  const {user: loggedInUser} = useSelector((state: RootState) => state.user);
+  let containerStyle;
   switch (previewType) {
     case 'Search':
       containerStyle = styles.containerSearch;
@@ -29,25 +40,32 @@ const SearchResults: React.FC<SearchResultsProps> = ({
   }
   return (
     <View style={containerStyle}>
-      {results &&
-        results.map((profilePreview) => (
-          <ProfilePreview
-            style={styles.result}
-            key={profilePreview.id}
-            {...{profilePreview}}
-            previewType={previewType}
-            screenType={screenType}
-          />
-        ))}
+      {categories.map((category: CategoryPreviewType) => (
+        <SearchResultsCell
+          key={category.name}
+          profileData={category}
+          {...{loggedInUser}}
+        />
+      ))}
+      {results.map((profile: ProfilePreviewType) => (
+        <SearchResultsCell
+          key={profile.id}
+          profileData={profile}
+          {...{loggedInUser}}
+        />
+      ))}
     </View>
   );
 };
 
 const styles = StyleSheet.create({
-  containerSearch: {flexDirection: 'column', flexWrap: 'wrap'},
-  container: {flexDirection: 'row', flexWrap: 'wrap'},
-  result: {
-    marginVertical: 10,
+  containerSearch: {
+    flexDirection: 'column',
+    flexWrap: 'wrap',
+  },
+  container: {
+    flexDirection: 'row',
+    flexWrap: 'wrap',
   },
 });
 
-- 
cgit v1.2.3-70-g09d2

