aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/search/SearchResultCell.tsx3
-rw-r--r--src/components/search/SearchResultList.tsx24
-rw-r--r--src/routes/main/MainStackNavigator.tsx1
-rw-r--r--src/screens/search/DiscoverUsers.tsx3
-rw-r--r--src/screens/search/SearchScreen.tsx12
-rw-r--r--src/services/ExploreService.ts8
6 files changed, 33 insertions, 18 deletions
diff --git a/src/components/search/SearchResultCell.tsx b/src/components/search/SearchResultCell.tsx
index e0351d96..5cba6d2f 100644
--- a/src/components/search/SearchResultCell.tsx
+++ b/src/components/search/SearchResultCell.tsx
@@ -23,11 +23,13 @@ import {
} from '../../utils/users';
interface SearchResults {
+ type: 'badges' | 'categories' | 'users';
profileData: ProfilePreviewType;
loggedInUser: UserType;
}
const SearchResultsCell: React.FC<SearchResults> = ({
+ type,
profileData: {
id,
name,
@@ -112,6 +114,7 @@ const SearchResultsCell: React.FC<SearchResults> = ({
const categoryObj: CategoryPreviewType = {name, category};
addCategoryToRecentlySearched(categoryObj);
navigation.navigate('DiscoverUsers', {
+ type,
searchCategory: {id, name},
});
};
diff --git a/src/components/search/SearchResultList.tsx b/src/components/search/SearchResultList.tsx
index 41c8c8b2..939bfa2b 100644
--- a/src/components/search/SearchResultList.tsx
+++ b/src/components/search/SearchResultList.tsx
@@ -25,14 +25,15 @@ const SearchResultList: React.FC<SearchResultsProps> = ({
results,
keyboardVisible,
}) => {
- const [showSection, setShowSection] = useState(true);
const [showEmptyView, setshowEmptyView] = useState(false);
const {user: loggedInUser} = useSelector((state: RootState) => state.user);
useEffect(() => {
if (results && results.length > 0) {
setshowEmptyView(
- results[0].data.length === 0 && results[1].data.length === 0,
+ results[0].data.length === 0 &&
+ results[1].data.length === 0 &&
+ results[2].data.length === 0,
);
}
}, [results]);
@@ -53,15 +54,18 @@ const SearchResultList: React.FC<SearchResultsProps> = ({
contentContainerStyle={{paddingBottom: SCREEN_HEIGHT * 0.1}}
sections={results}
keyExtractor={(item, index) => item.id + index}
- renderItem={({item}) => (
- <SearchResultsCell profileData={item} loggedInUser={loggedInUser} />
- )}
- renderSectionHeader={({section: {title, data}}) => {
- if (title === 'categories' && data.length === 0) {
- setShowSection(false);
- }
- return sectionHeader(title !== 'categories' && showSection);
+ renderItem={({section, item}) => {
+ return (
+ <SearchResultsCell
+ type={section.title}
+ profileData={item}
+ loggedInUser={loggedInUser}
+ />
+ );
}}
+ renderSectionHeader={({section: {data}}) =>
+ sectionHeader(data.length !== 0)
+ }
/>
)}
</View>
diff --git a/src/routes/main/MainStackNavigator.tsx b/src/routes/main/MainStackNavigator.tsx
index 8953cfe0..10b8ec3d 100644
--- a/src/routes/main/MainStackNavigator.tsx
+++ b/src/routes/main/MainStackNavigator.tsx
@@ -22,6 +22,7 @@ export type MainStackParams = {
screenType: ScreenType;
};
DiscoverUsers: {
+ type: 'badges' | 'categories' | 'users';
searchCategory: SearchCategoryType;
};
Profile: {
diff --git a/src/screens/search/DiscoverUsers.tsx b/src/screens/search/DiscoverUsers.tsx
index e570edce..ce7507fc 100644
--- a/src/screens/search/DiscoverUsers.tsx
+++ b/src/screens/search/DiscoverUsers.tsx
@@ -18,12 +18,13 @@ interface DiscoverUsersProps {
}
const DiscoverUsers: React.FC<DiscoverUsersProps> = ({route}) => {
+ const {type: category_type} = route.params;
const {id, name} = route.params.searchCategory;
const [users, setUsers] = useState<ProfilePreviewType[]>();
useEffect(() => {
const loadData = async () => {
- setUsers(await getDiscoverUsers(id));
+ setUsers(await getDiscoverUsers(id, category_type));
};
loadData();
}, []);
diff --git a/src/screens/search/SearchScreen.tsx b/src/screens/search/SearchScreen.tsx
index 835a5622..e80e09aa 100644
--- a/src/screens/search/SearchScreen.tsx
+++ b/src/screens/search/SearchScreen.tsx
@@ -74,16 +74,18 @@ const SearchScreen: React.FC = () => {
`${SEARCH_ENDPOINT}?query=${query}`,
);
if (query.length > 2) {
- const categories = searchResults?.categories;
- const users = searchResults?.users;
const sanitizedResult = [
{
+ title: 'badges',
+ data: searchResults?.badges,
+ },
+ {
title: 'categories',
- data: categories,
+ data: searchResults?.categories,
},
{
title: 'users',
- data: users,
+ data: searchResults?.users,
},
];
setResults(sanitizedResult);
@@ -209,7 +211,7 @@ const styles = StyleSheet.create({
height: SCREEN_HEIGHT,
},
contentContainer: {
- height: SCREEN_HEIGHT * 0.9,
+ height: SCREEN_HEIGHT,
paddingTop: '2%',
paddingBottom: SCREEN_HEIGHT / 3,
paddingHorizontal: '3%',
diff --git a/src/services/ExploreService.ts b/src/services/ExploreService.ts
index 56a2e3d1..9b0b4f71 100644
--- a/src/services/ExploreService.ts
+++ b/src/services/ExploreService.ts
@@ -68,10 +68,14 @@ export const getAllExploreSections = async () => {
}
};
-export const getDiscoverUsers = async (id: number) => {
+export const getDiscoverUsers = async (id: number, category_type: string) => {
try {
const token = await AsyncStorage.getItem('token');
- const response = await fetch(DISCOVER_ENDPOINT + `${id}/`, {
+ let url = DISCOVER_ENDPOINT + `${id}/`;
+ if (category_type === 'badges') {
+ url += '?type=badge';
+ }
+ const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: 'Token ' + token,