diff options
-rw-r--r-- | src/components/common/GradientBorderButton.tsx | 10 | ||||
-rw-r--r-- | src/components/search/SearchCategories.tsx | 25 | ||||
-rw-r--r-- | src/components/search/SearchResultCell.tsx | 3 | ||||
-rw-r--r-- | src/components/search/SearchResultList.tsx | 1 | ||||
-rw-r--r-- | src/routes/main/MainStackNavigator.tsx | 1 | ||||
-rw-r--r-- | src/routes/main/MainStackScreen.tsx | 3 | ||||
-rw-r--r-- | src/screens/search/DiscoverUsers.tsx | 34 | ||||
-rw-r--r-- | src/screens/search/SearchScreen.tsx | 22 | ||||
-rw-r--r-- | src/services/ExploreService.ts | 46 |
9 files changed, 83 insertions, 62 deletions
diff --git a/src/components/common/GradientBorderButton.tsx b/src/components/common/GradientBorderButton.tsx index 0402c44b..00ea7175 100644 --- a/src/components/common/GradientBorderButton.tsx +++ b/src/components/common/GradientBorderButton.tsx @@ -45,20 +45,20 @@ const styles = StyleSheet.create({ marginVertical: 15, }, gradientContainer: { - width: 159, - height: 38, + width: 175, + height: 40, }, label: { fontWeight: '500', - fontSize: normalize(15), + fontSize: normalize(14), }, maskBorder: { borderRadius: 20, }, textContainer: { position: 'absolute', - width: 159, - height: 38, + width: 175, + height: 40, justifyContent: 'center', alignItems: 'center', }, diff --git a/src/components/search/SearchCategories.tsx b/src/components/search/SearchCategories.tsx index f00debb5..a71befe6 100644 --- a/src/components/search/SearchCategories.tsx +++ b/src/components/search/SearchCategories.tsx @@ -2,16 +2,18 @@ import {useNavigation} from '@react-navigation/native'; import React, {useEffect, useState} from 'react'; import {StyleSheet, View} from 'react-native'; import {GradientBorderButton} from '..'; -import {getButtons} from '../../services/ExploreService'; +import {getSuggestedSearchBubbleSuggestions} from '../../services/ExploreService'; import {SearchCategoryType} from '../../types'; import {SCREEN_WIDTH} from '../../utils'; interface SearchCategoriesProps { darkStyle?: boolean; + defaultButtons?: SearchCategoryType[]; } const SearchCategories: React.FC<SearchCategoriesProps> = ({ darkStyle = false, + defaultButtons, }) => { const navigation = useNavigation(); const mtSearchCategory: (key: number) => SearchCategoryType = (key) => ({ @@ -20,18 +22,25 @@ const SearchCategories: React.FC<SearchCategoriesProps> = ({ category: '...', }); const [buttons, setButtons] = useState<SearchCategoryType[]>([ - mtSearchCategory(1), - mtSearchCategory(2), - mtSearchCategory(3), - mtSearchCategory(4), + mtSearchCategory(-1), + mtSearchCategory(-2), + mtSearchCategory(-3), + mtSearchCategory(-4), ]); + useEffect(() => { const loadButtons = async () => { - const localButtons = await getButtons(); + const localButtons = await getSuggestedSearchBubbleSuggestions(); setButtons([]); - setButtons(localButtons); + if (localButtons) { + setButtons(localButtons); + } }; - loadButtons(); + if (!defaultButtons) { + loadButtons(); + } else { + setButtons(defaultButtons); + } }, []); return ( diff --git a/src/components/search/SearchResultCell.tsx b/src/components/search/SearchResultCell.tsx index 5cba6d2f..e0351d96 100644 --- a/src/components/search/SearchResultCell.tsx +++ b/src/components/search/SearchResultCell.tsx @@ -23,13 +23,11 @@ import { } from '../../utils/users'; interface SearchResults { - type: 'badges' | 'categories' | 'users'; profileData: ProfilePreviewType; loggedInUser: UserType; } const SearchResultsCell: React.FC<SearchResults> = ({ - type, profileData: { id, name, @@ -114,7 +112,6 @@ 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 d8cf02d9..704e4192 100644 --- a/src/components/search/SearchResultList.tsx +++ b/src/components/search/SearchResultList.tsx @@ -57,7 +57,6 @@ const SearchResultList: React.FC<SearchResultsProps> = ({ renderItem={({section, item}) => { return ( <SearchResultsCell - type={section.title} profileData={item} loggedInUser={loggedInUser} /> diff --git a/src/routes/main/MainStackNavigator.tsx b/src/routes/main/MainStackNavigator.tsx index 10b8ec3d..8953cfe0 100644 --- a/src/routes/main/MainStackNavigator.tsx +++ b/src/routes/main/MainStackNavigator.tsx @@ -22,7 +22,6 @@ export type MainStackParams = { screenType: ScreenType; }; DiscoverUsers: { - type: 'badges' | 'categories' | 'users'; searchCategory: SearchCategoryType; }; Profile: { diff --git a/src/routes/main/MainStackScreen.tsx b/src/routes/main/MainStackScreen.tsx index 91f41fe4..cb232297 100644 --- a/src/routes/main/MainStackScreen.tsx +++ b/src/routes/main/MainStackScreen.tsx @@ -4,11 +4,9 @@ import {StackNavigationOptions} from '@react-navigation/stack'; import React, {useState} from 'react'; import {StyleSheet, Text} from 'react-native'; import {normalize} from 'react-native-elements'; -import MutualBadgeHolders from '../../screens/suggestedPeople/MutualBadgeHolders'; import BackIcon from '../../assets/icons/back-arrow.svg'; import { AnimatedTutorial, - BadgeSelection, CaptionScreen, CategorySelection, CreateCustomCategory, @@ -26,6 +24,7 @@ import { SuggestedPeopleScreen, SuggestedPeopleUploadPictureScreen, } from '../../screens'; +import MutualBadgeHolders from '../../screens/suggestedPeople/MutualBadgeHolders'; import {ScreenType} from '../../types'; import {AvatarHeaderHeight, SCREEN_WIDTH} from '../../utils'; import {MainStack, MainStackParams} from './MainStackNavigator'; diff --git a/src/screens/search/DiscoverUsers.tsx b/src/screens/search/DiscoverUsers.tsx index a9856909..d67e5448 100644 --- a/src/screens/search/DiscoverUsers.tsx +++ b/src/screens/search/DiscoverUsers.tsx @@ -29,8 +29,7 @@ interface DiscoverUsersProps { } const DiscoverUsers: React.FC<DiscoverUsersProps> = ({route}) => { - const {type: category_type} = route.params; - const {id, name} = route.params.searchCategory; + const {name} = route.params.searchCategory; const [categoryName, setCategoryName] = useState<string | undefined>(); const [users, setUsers] = useState<ProfilePreviewType[]>([]); const [shouldRefresh, setShouldRefresh] = useState(false); @@ -43,15 +42,15 @@ const DiscoverUsers: React.FC<DiscoverUsersProps> = ({route}) => { thumbnail_url: '', }); const dummyUsers = [ - mtUser(1), - mtUser(2), - mtUser(3), - mtUser(4), - mtUser(5), - mtUser(6), - mtUser(7), - mtUser(8), - mtUser(9), + mtUser(-1), + mtUser(-2), + mtUser(-3), + mtUser(-4), + mtUser(-5), + mtUser(-6), + mtUser(-7), + mtUser(-8), + mtUser(-9), ]; const [loading, setLoading] = useState(true); const navigation = useNavigation(); @@ -94,7 +93,13 @@ const DiscoverUsers: React.FC<DiscoverUsersProps> = ({route}) => { useEffect(() => { const loadData = async () => { setLoading(true); - setUsers(await getDiscoverUsers(id, category_type)); + if (!categoryName) { + return; + } + const fetched_users = await getDiscoverUsers(categoryName); + if (fetched_users) { + setUsers(fetched_users); + } setLoading(false); }; loadData(); @@ -122,10 +127,7 @@ const DiscoverUsers: React.FC<DiscoverUsersProps> = ({route}) => { ListFooterComponent={() => ( <> <Text style={styles.otherGroups}>Other Groups</Text> - <SearchCategories - darkStyle={true} - // callBack={(category) => setCategoryName(category)} - /> + <SearchCategories darkStyle={true} /> </> )} /> diff --git a/src/screens/search/SearchScreen.tsx b/src/screens/search/SearchScreen.tsx index 728510c5..f9a42d86 100644 --- a/src/screens/search/SearchScreen.tsx +++ b/src/screens/search/SearchScreen.tsx @@ -17,7 +17,12 @@ import {SEARCH_ENDPOINT, TAGG_LIGHT_BLUE} from '../../constants'; import {loadSearchResults} from '../../services'; import {resetScreenType} from '../../store/actions'; import {RootState} from '../../store/rootReducer'; -import {ProfilePreviewType, ScreenType, CategoryPreviewType} from '../../types'; +import { + ProfilePreviewType, + ScreenType, + CategoryPreviewType, + SearchCategoryType, +} from '../../types'; import {normalize, SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; /** @@ -37,6 +42,11 @@ const SearchScreen: React.FC = () => { >([]); const [searching, setSearching] = useState(false); const top = Animated.useValue(-SCREEN_HEIGHT); + const defaultButtons: SearchCategoryType[] = [21, 22, 23, 24].map((year) => ({ + id: -1, + name: `Brown '${year}`, + category: 'Brown', + })); const [keyboardVisible, setKeyboardVisible] = React.useState( 'keyboardVisible', ); @@ -57,8 +67,12 @@ const SearchScreen: React.FC = () => { * Main handler for changes in query. */ useEffect(() => { - if (!searching) return; - if (!query.length) loadRecentSearches(); + if (!searching) { + return; + } + if (!query.length) { + loadRecentSearches(); + } if (query.length < 3) { setResults(undefined); return; @@ -181,7 +195,7 @@ const SearchScreen: React.FC = () => { stickyHeaderIndices={[4]} contentContainerStyle={styles.contentContainer} showsVerticalScrollIndicator={false}> - <SearchCategories /> + <SearchCategories defaultButtons={defaultButtons} /> <SearchResultsBackground {...{top}}> {results === undefined && recents.length + recentCategories.length !== 0 ? ( diff --git a/src/services/ExploreService.ts b/src/services/ExploreService.ts index 9b0b4f71..07af91ad 100644 --- a/src/services/ExploreService.ts +++ b/src/services/ExploreService.ts @@ -68,13 +68,10 @@ export const getAllExploreSections = async () => { } }; -export const getDiscoverUsers = async (id: number, category_type: string) => { +export const getDiscoverUsers = async (categoryName: string) => { try { const token = await AsyncStorage.getItem('token'); - let url = DISCOVER_ENDPOINT + `${id}/`; - if (category_type === 'badges') { - url += '?type=badge'; - } + const url = `${DISCOVER_ENDPOINT}get_users/?category=${categoryName}`; const response = await fetch(url, { method: 'GET', headers: { @@ -82,31 +79,36 @@ export const getDiscoverUsers = async (id: number, category_type: string) => { }, }); if (response.status !== 200) { - return EMPTY_PROFILE_PREVIEW_LIST; + return undefined; } - const data = await response.json(); - const users: ProfilePreviewType[] = data.users; + const users: ProfilePreviewType[] = await response.json(); return users; } catch (error) { console.log('Error fetching SP user data'); console.log(error); - return []; + return undefined; } }; -export const getButtons = async () => { - const token = await AsyncStorage.getItem('token'); - const response = await fetch(SEARCH_BUTTONS_ENDPOPINT, { - method: 'GET', - headers: { - Authorization: 'Token ' + token, - }, - }); +export const getSuggestedSearchBubbleSuggestions = async () => { + try { + const token = await AsyncStorage.getItem('token'); + const response = await fetch(SEARCH_BUTTONS_ENDPOPINT, { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }); + + if (response.status !== 200) { + return undefined; + } - if (response.status !== 200) { - return []; + const data: SearchCategoryType[] = await response.json(); + return data; + } catch (error) { + console.log('Error fetching suggested search bubble suggestions'); + console.log(error); + return undefined; } - - const data: SearchCategoryType[] = await response.json(); - return data; }; |