-
Notifications
You must be signed in to change notification settings - Fork 3k
/
SearchFilters.tsx
88 lines (79 loc) · 2.88 KB
/
SearchFilters.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React from 'react';
import {View} from 'react-native';
import MenuItem from '@components/MenuItem';
import useLocalize from '@hooks/useLocalize';
import useSingleExecution from '@hooks/useSingleExecution';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import Navigation from '@libs/Navigation/Navigation';
import variables from '@styles/variables';
import * as Expensicons from '@src/components/Icon/Expensicons';
import CONST from '@src/CONST';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import type IconAsset from '@src/types/utils/IconAsset';
import SearchFiltersNarrow from './SearchFiltersNarrow';
type SearchFiltersProps = {
query: string;
};
type SearchMenuFilterItem = {
title: string;
query: string;
icon: IconAsset;
route: Route;
};
function SearchFilters({query}: SearchFiltersProps) {
const styles = useThemeStyles();
const {isSmallScreenWidth} = useWindowDimensions();
const {singleExecution} = useSingleExecution();
const {translate} = useLocalize();
const filterItems: SearchMenuFilterItem[] = [
{
title: translate('common.expenses'),
query: CONST.TAB_SEARCH.ALL,
icon: Expensicons.Receipt,
route: ROUTES.SEARCH.getRoute(CONST.TAB_SEARCH.ALL),
},
{
title: translate('common.shared'),
query: CONST.TAB_SEARCH.SHARED,
icon: Expensicons.Send,
route: ROUTES.SEARCH.getRoute(CONST.TAB_SEARCH.SHARED),
},
];
const activeItemIndex = filterItems.findIndex((item) => item.query === query);
if (isSmallScreenWidth) {
return (
<SearchFiltersNarrow
filterItems={filterItems}
activeItemIndex={activeItemIndex}
/>
);
}
return (
<View style={[styles.pb4, styles.mh3, styles.mt3]}>
{filterItems.map((item, index) => {
const onPress = singleExecution(() => Navigation.navigate(item.route));
return (
<MenuItem
key={item.title}
disabled={false}
interactive
title={item.title}
icon={item.icon}
iconWidth={variables.iconSizeNormal}
iconHeight={variables.iconSizeNormal}
wrapperStyle={styles.sectionMenuItem}
focused={index === activeItemIndex}
hoverAndPressStyle={styles.hoveredComponentBG}
onPress={onPress}
isPaneMenu
/>
);
})}
</View>
);
}
SearchFilters.displayName = 'SearchFilters';
export default SearchFilters;
export type {SearchMenuFilterItem};