Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search filters #40929

Merged
merged 8 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3329,7 +3329,7 @@ const CONST = {
},
TAB_SEARCH: {
ALL: 'all',
SENT: 'sent',
SHARED: 'shared',
DRAFTS: 'drafts',
WAITING_ON_YOU: 'waitingOnYou',
FINISHED: 'finished',
Expand Down
2 changes: 2 additions & 0 deletions src/components/PopoverMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ function PopoverMenu({
shouldShowSubscriptRightAvatar={item.shouldShowSubscriptRightAvatar}
disabled={item.disabled}
onFocus={() => setFocusedIndex(menuIndex)}
success={item.success}
containerStyle={item.containerStyle}
/>
))}
</View>
Expand Down
29 changes: 10 additions & 19 deletions src/pages/Search/SearchFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import {View} from 'react-native';
import MenuItem from '@components/MenuItem';
import useActiveRoute from '@hooks/useActiveRoute';
import useLocalize from '@hooks/useLocalize';
import useSingleExecution from '@hooks/useSingleExecution';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
Expand All @@ -19,30 +20,20 @@ type SearchMenuFilterItem = {
route: Route;
};

const filterItems: SearchMenuFilterItem[] = [
{
title: 'All',
icon: Expensicons.All,
route: ROUTES.SEARCH.getRoute(CONST.TAB_SEARCH.ALL),
},
// More tabs prepared for final version but in v1 we support only "All"
// {
// title: 'Sent',
// icon: Expensicons.Send,
// route: ROUTES.SEARCH.getRoute(CONST.TAB_SEARCH.SENT),
// },
// {
// title: 'Drafts',
// icon: Expensicons.Pencil,
// route: ROUTES.SEARCH.getRoute(CONST.TAB_SEARCH.DRAFTS),
// },
];

function SearchFilters() {
const styles = useThemeStyles();
const {singleExecution} = useSingleExecution();
const activeRoute = useActiveRoute();
const {isSmallScreenWidth} = useWindowDimensions();
const {translate} = useLocalize();

const filterItems: SearchMenuFilterItem[] = [
{
title: translate('common.all'),
icon: Expensicons.All,
route: ROUTES.SEARCH.getRoute(CONST.TAB_SEARCH.ALL),
},
];

const currentQuery = activeRoute?.params && 'query' in activeRoute.params ? activeRoute?.params?.query : '';

Expand Down
15 changes: 10 additions & 5 deletions src/pages/Search/SearchFiltersNarrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,23 @@ function SearchFiltersNarrow({filterItems, activeItemLabel}: SearchFiltersNarrow
const openMenu = () => setIsPopoverVisible(true);
const closeMenu = () => setIsPopoverVisible(false);

const activeItem = filterItems.find((item) => item.title.toLowerCase() === activeItemLabel);
const popoverMenuItems = filterItems.map((item) => ({
const activeItemIndex = filterItems.findIndex((item) => item.title.toLowerCase() === activeItemLabel);
const popoverMenuItems = filterItems.map((item, index) => ({
text: item.title,
onSelected: singleExecution(() => Navigation.navigate(item.route)),
icon: item.icon,
iconFill: index === activeItemIndex ? theme.iconSuccessFill : theme.icon,
iconRight: Expensicons.Checkmark,
shouldShowRightIcon: index === activeItemIndex,
success: index === activeItemIndex,
containerStyle: index === activeItemIndex ? [{backgroundColor: theme.border}] : undefined,
}));

return (
<>
<PressableWithFeedback
accessible
accessibilityLabel={activeItem?.title ?? ''}
accessibilityLabel={popoverMenuItems[activeItemIndex]?.text ?? ''}
style={[styles.tabSelectorButton]}
wrapperStyle={[styles.flex1]}
ref={buttonRef}
Expand All @@ -50,10 +55,10 @@ function SearchFiltersNarrow({filterItems, activeItemLabel}: SearchFiltersNarrow
<Animated.View style={[styles.tabSelectorButton, StyleSheet.absoluteFill, styles.tabBackground(hovered, true, theme.border), styles.mh3]}>
<View style={[styles.flexRow]}>
<Icon
src={activeItem?.icon ?? Expensicons.All}
src={popoverMenuItems[activeItemIndex]?.icon ?? Expensicons.All}
fill={theme.icon}
/>
<Text style={[styles.searchFiltersButtonText]}>{activeItem?.title}</Text>
<Text style={[styles.mh1, styles.textStrong]}>{popoverMenuItems[activeItemIndex]?.text}</Text>
<Icon
src={Expensicons.DownArrow}
fill={theme.icon}
Expand Down
7 changes: 6 additions & 1 deletion src/pages/Search/SearchPageBottomTab.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import React from 'react';
import ScreenWrapper from '@components/ScreenWrapper';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import TopBar from '@navigation/AppNavigator/createCustomBottomTabNavigator/TopBar';
import SearchFilters from './SearchFilters';

// import EmptySearchView from './EmptySearchView';

function SearchPageBottomTab() {
const {translate} = useLocalize();
const styles = useThemeStyles();

return (
<ScreenWrapper testID={SearchPageBottomTab.displayName}>
<ScreenWrapper
testID={SearchPageBottomTab.displayName}
style={styles.pt0}
>
<TopBar
breadcrumbLabel={translate('common.search')}
shouldDisplaySearch={false}
Expand Down
6 changes: 0 additions & 6 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4874,12 +4874,6 @@ const styles = (theme: ThemeColors) =>
textLineThrough: {
textDecorationLine: 'line-through',
},

searchFiltersButtonText: {
marginLeft: 4,
marginRight: 4,
fontWeight: 'bold',
},
} satisfies Styles);

type ThemeStyles = ReturnType<typeof styles>;
Expand Down
Loading