@@ -9,6 +9,7 @@ import * as SearchUtils from '@libs/SearchUtils';
9
9
import Navigation from '@navigation/Navigation' ;
10
10
import EmptySearchView from '@pages/Search/EmptySearchView' ;
11
11
import useCustomBackHandler from '@pages/Search/useCustomBackHandler' ;
12
+ import CONST from '@src/CONST' ;
12
13
import ONYXKEYS from '@src/ONYXKEYS' ;
13
14
import ROUTES from '@src/ROUTES' ;
14
15
import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
@@ -35,14 +36,15 @@ function Search({query, policyIDs}: SearchProps) {
35
36
return ;
36
37
}
37
38
38
- SearchActions . search ( hash , query , policyIDs ) ;
39
+ SearchActions . search ( hash , query , 0 , policyIDs ) ;
39
40
// eslint-disable-next-line react-hooks/exhaustive-deps
40
41
} , [ hash , isOffline ] ) ;
41
42
42
- const isLoading = ( ! isOffline && isLoadingOnyxValue ( searchResultsMeta ) ) || searchResults ?. data === undefined ;
43
- const shouldShowEmptyState = ! isLoading && isEmptyObject ( searchResults ?. data ) ;
43
+ const isLoadingInitialItems = ( ! isOffline && isLoadingOnyxValue ( searchResultsMeta ) ) || searchResults ?. data === undefined ;
44
+ const isLoadingMoreItems = ! isLoadingInitialItems && searchResults ?. search ?. isLoading ;
45
+ const shouldShowEmptyState = ! isLoadingInitialItems && isEmptyObject ( searchResults ?. data ) ;
44
46
45
- if ( isLoading ) {
47
+ if ( isLoadingInitialItems ) {
46
48
return < TableListItemSkeleton shouldAnimate /> ;
47
49
}
48
50
@@ -58,6 +60,14 @@ function Search({query, policyIDs}: SearchProps) {
58
60
Navigation . navigate ( ROUTES . SEARCH_REPORT . getRoute ( query , reportID ) ) ;
59
61
} ;
60
62
63
+ const fetchMoreResults = ( ) => {
64
+ if ( ! searchResults ?. search ?. hasMoreResults || isLoadingInitialItems || isLoadingMoreItems ) {
65
+ return ;
66
+ }
67
+ const currentOffset = searchResults ?. search ?. offset ?? 0 ;
68
+ SearchActions . search ( hash , query , currentOffset + CONST . SEARCH_RESULTS_PAGE_SIZE ) ;
69
+ } ;
70
+
61
71
const type = SearchUtils . getSearchType ( searchResults ?. search ) ;
62
72
63
73
if ( type === undefined ) {
@@ -80,6 +90,16 @@ function Search({query, policyIDs}: SearchProps) {
80
90
listHeaderWrapperStyle = { [ styles . ph9 , styles . pv3 , styles . pb5 ] }
81
91
containerStyle = { [ styles . pv0 ] }
82
92
showScrollIndicator = { false }
93
+ onEndReachedThreshold = { 0.75 }
94
+ onEndReached = { fetchMoreResults }
95
+ listFooterContent = {
96
+ isLoadingMoreItems ? (
97
+ < TableListItemSkeleton
98
+ shouldAnimate
99
+ fixedNumItems = { 5 }
100
+ />
101
+ ) : undefined
102
+ }
83
103
/>
84
104
) ;
85
105
}
0 commit comments