1
- import React from 'react' ;
1
+ import type { StackScreenProps } from '@react-navigation/stack' ;
2
+ import React , { useMemo } from 'react' ;
2
3
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView' ;
3
4
import ScreenWrapper from '@components/ScreenWrapper' ;
4
5
import Search from '@components/Search' ;
@@ -7,20 +8,42 @@ import useLocalize from '@hooks/useLocalize';
7
8
import useThemeStyles from '@hooks/useThemeStyles' ;
8
9
import useWindowDimensions from '@hooks/useWindowDimensions' ;
9
10
import Navigation from '@libs/Navigation/Navigation' ;
11
+ import type { CentralPaneNavigatorParamList } from '@libs/Navigation/types' ;
10
12
import TopBar from '@navigation/AppNavigator/createCustomBottomTabNavigator/TopBar' ;
11
13
import CONST from '@src/CONST' ;
12
14
import ROUTES from '@src/ROUTES' ;
15
+ import SCREENS from '@src/SCREENS' ;
13
16
import type { SearchQuery } from '@src/types/onyx/SearchResults' ;
14
17
import SearchFilters from './SearchFilters' ;
15
18
19
+ type SearchPageProps = StackScreenProps < CentralPaneNavigatorParamList , typeof SCREENS . SEARCH . CENTRAL_PANE > ;
20
+
21
+ const defaultSearchProps = {
22
+ query : '' as SearchQuery ,
23
+ policyIDs : undefined ,
24
+ sortBy : CONST . SEARCH_TABLE_COLUMNS . DATE ,
25
+ sortOrder : CONST . SORT_ORDER . DESC ,
26
+ } ;
16
27
function SearchPageBottomTab ( ) {
17
28
const { translate} = useLocalize ( ) ;
18
29
const { isSmallScreenWidth} = useWindowDimensions ( ) ;
19
30
const activeRoute = useActiveRoute ( ) ;
20
31
const styles = useThemeStyles ( ) ;
21
- const currentQuery = activeRoute ?. params && 'query' in activeRoute . params ? activeRoute ?. params ?. query : '' ;
22
- const policyIDs = activeRoute ?. params && 'policyIDs' in activeRoute . params ? ( activeRoute ?. params ?. policyIDs as string ) : undefined ;
23
- const query = currentQuery as SearchQuery ;
32
+
33
+ const {
34
+ query : rawQuery ,
35
+ policyIDs,
36
+ sortBy,
37
+ sortOrder,
38
+ } = useMemo ( ( ) => {
39
+ if ( activeRoute ?. name !== SCREENS . SEARCH . CENTRAL_PANE || ! activeRoute . params ) {
40
+ return defaultSearchProps ;
41
+ }
42
+ return { ...defaultSearchProps , ...activeRoute . params } as SearchPageProps [ 'route' ] [ 'params' ] ;
43
+ } , [ activeRoute ] ) ;
44
+
45
+ const query = rawQuery as SearchQuery ;
46
+
24
47
const isValidQuery = Object . values ( CONST . TAB_SEARCH ) . includes ( query ) ;
25
48
26
49
const handleOnBackButtonPress = ( ) => Navigation . goBack ( ROUTES . SEARCH . getRoute ( CONST . TAB_SEARCH . ALL ) ) ;
@@ -45,6 +68,8 @@ function SearchPageBottomTab() {
45
68
< Search
46
69
policyIDs = { policyIDs }
47
70
query = { query }
71
+ sortBy = { sortBy }
72
+ sortOrder = { sortOrder }
48
73
/>
49
74
) }
50
75
</ FullPageNotFoundView >
0 commit comments