@@ -15,16 +15,25 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
15
15
import useSearchHighlightAndScroll from '@hooks/useSearchHighlightAndScroll' ;
16
16
import useThemeStyles from '@hooks/useThemeStyles' ;
17
17
import { turnOffMobileSelectionMode , turnOnMobileSelectionMode } from '@libs/actions/MobileSelectionMode' ;
18
- import * as SearchActions from '@libs/actions/Search' ;
19
- import * as DeviceCapabilities from '@libs/DeviceCapabilities' ;
18
+ import { createTransactionThread , search } from '@libs/actions/Search' ;
19
+ import { canUseTouchScreen } from '@libs/DeviceCapabilities' ;
20
20
import Log from '@libs/Log' ;
21
21
import memoize from '@libs/memoize' ;
22
22
import isSearchTopmostCentralPane from '@libs/Navigation/isSearchTopmostCentralPane' ;
23
23
import type { PlatformStackNavigationProp } from '@libs/Navigation/PlatformStackNavigation/types' ;
24
- import * as ReportUtils from '@libs/ReportUtils' ;
25
- import * as SearchQueryUtils from '@libs/SearchQueryUtils' ;
26
- import * as SearchUIUtils from '@libs/SearchUIUtils' ;
27
- import * as TransactionUtils from '@libs/TransactionUtils' ;
24
+ import { generateReportID } from '@libs/ReportUtils' ;
25
+ import { buildSearchQueryString } from '@libs/SearchQueryUtils' ;
26
+ import {
27
+ getListItem ,
28
+ getSections ,
29
+ getSortedSections ,
30
+ isReportActionListItemType ,
31
+ isReportListItemType ,
32
+ isSearchResultsEmpty as isSearchResultsEmptyUtil ,
33
+ isTransactionListItemType ,
34
+ shouldShowYear as shouldShowYearUtil ,
35
+ } from '@libs/SearchUIUtils' ;
36
+ import { isOnHold } from '@libs/TransactionUtils' ;
28
37
import Navigation from '@navigation/Navigation' ;
29
38
import type { AuthScreensParamList } from '@navigation/types' ;
30
39
import EmptySearchView from '@pages/Search/EmptySearchView' ;
@@ -57,7 +66,7 @@ function mapTransactionItemToSelectedEntry(item: TransactionListItemType): [stri
57
66
isSelected : true ,
58
67
canDelete : item . canDelete ,
59
68
canHold : item . canHold ,
60
- isHeld : TransactionUtils . isOnHold ( item ) ,
69
+ isHeld : isOnHold ( item ) ,
61
70
canUnhold : item . canUnhold ,
62
71
action : item . action ,
63
72
reportID : item . reportID ,
@@ -77,14 +86,14 @@ function mapToItemWithSelectionInfo(
77
86
canSelectMultiple : boolean ,
78
87
shouldAnimateInHighlight : boolean ,
79
88
) {
80
- if ( SearchUIUtils . isReportActionListItemType ( item ) ) {
89
+ if ( isReportActionListItemType ( item ) ) {
81
90
return {
82
91
...item ,
83
92
shouldAnimateInHighlight,
84
93
} ;
85
94
}
86
95
87
- return SearchUIUtils . isTransactionListItemType ( item )
96
+ return isTransactionListItemType ( item )
88
97
? mapToTransactionItemWithSelectionInfo ( item , selectedTransactions , canSelectMultiple , shouldAnimateInHighlight )
89
98
: {
90
99
...item ,
@@ -107,7 +116,7 @@ function prepareTransactionsList(item: TransactionListItemType, selectedTransact
107
116
isSelected : true ,
108
117
canDelete : item . canDelete ,
109
118
canHold : item . canHold ,
110
- isHeld : TransactionUtils . isOnHold ( item ) ,
119
+ isHeld : isOnHold ( item ) ,
111
120
canUnhold : item . canUnhold ,
112
121
action : item . action ,
113
122
reportID : item . reportID ,
@@ -127,8 +136,16 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
127
136
const navigation = useNavigation < PlatformStackNavigationProp < AuthScreensParamList > > ( ) ;
128
137
const isFocused = useIsFocused ( ) ;
129
138
const [ lastNonEmptySearchResults , setLastNonEmptySearchResults ] = useState < SearchResults | undefined > ( undefined ) ;
130
- const { setCurrentSearchHash, setSelectedTransactions, selectedTransactions, clearSelectedTransactions, setShouldShowStatusBarLoading, lastSearchType, setLastSearchType} =
131
- useSearchContext ( ) ;
139
+ const {
140
+ setCurrentSearchHash,
141
+ setSelectedTransactions,
142
+ selectedTransactions,
143
+ clearSelectedTransactions,
144
+ shouldTurnOffSelectionMode,
145
+ setShouldShowStatusBarLoading,
146
+ lastSearchType,
147
+ setLastSearchType,
148
+ } = useSearchContext ( ) ;
132
149
const { selectionMode} = useMobileSelectionMode ( false ) ;
133
150
const [ offset , setOffset ] = useState ( 0 ) ;
134
151
@@ -158,6 +175,13 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
158
175
setCurrentSearchHash ( hash ) ;
159
176
} , [ hash , clearSelectedTransactions , setCurrentSearchHash ] ) ;
160
177
178
+ useEffect ( ( ) => {
179
+ const selectedKeys = Object . keys ( selectedTransactions ) . filter ( ( key ) => selectedTransactions [ key ] ) ;
180
+ if ( selectedKeys . length === 0 && selectionMode ?. isEnabled && shouldTurnOffSelectionMode ) {
181
+ turnOffMobileSelectionMode ( ) ;
182
+ }
183
+ } , [ selectedTransactions , selectionMode ?. isEnabled , shouldTurnOffSelectionMode ] ) ;
184
+
161
185
useEffect ( ( ) => {
162
186
const selectedKeys = Object . keys ( selectedTransactions ) . filter ( ( key ) => selectedTransactions [ key ] ) ;
163
187
if ( ! isSmallScreenWidth ) {
@@ -176,12 +200,12 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
176
200
return ;
177
201
}
178
202
179
- SearchActions . search ( { queryJSON, offset} ) ;
203
+ search ( { queryJSON, offset} ) ;
180
204
} , [ isOffline , offset , queryJSON ] ) ;
181
205
182
206
const getItemHeight = useCallback (
183
207
( item : TransactionListItemType | ReportListItemType | ReportActionListItemType ) => {
184
- if ( SearchUIUtils . isTransactionListItemType ( item ) || SearchUIUtils . isReportActionListItemType ( item ) ) {
208
+ if ( isTransactionListItemType ( item ) || isReportActionListItemType ( item ) ) {
185
209
return isLargeScreenWidth ? variables . optionRowHeight + listItemPadding : transactionItemMobileHeight + listItemPadding ;
186
210
}
187
211
@@ -229,14 +253,14 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
229
253
230
254
const shouldShowLoadingState = ! isOffline && ! isDataLoaded ;
231
255
const shouldShowLoadingMoreItems = ! shouldShowLoadingState && searchResults ?. search ?. isLoading && searchResults ?. search ?. offset > 0 ;
232
- const isSearchResultsEmpty = ! searchResults ?. data || SearchUIUtils . isSearchResultsEmpty ( searchResults ) ;
256
+ const isSearchResultsEmpty = ! searchResults ?. data || isSearchResultsEmptyUtil ( searchResults ) ;
233
257
const prevIsSearchResultEmpty = usePrevious ( isSearchResultsEmpty ) ;
234
258
235
259
const data = useMemo ( ( ) => {
236
260
if ( searchResults === undefined ) {
237
261
return [ ] ;
238
262
}
239
- return SearchUIUtils . getSections ( type , status , searchResults . data , searchResults . search ) ;
263
+ return getSections ( type , status , searchResults . data , searchResults . search ) ;
240
264
} , [ searchResults , status , type ] ) ;
241
265
242
266
useEffect ( ( ) => {
@@ -260,7 +284,7 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
260
284
newTransactionList [ transaction . transactionID ] = {
261
285
action : transaction . action ,
262
286
canHold : transaction . canHold ,
263
- isHeld : TransactionUtils . isOnHold ( transaction ) ,
287
+ isHeld : isOnHold ( transaction ) ,
264
288
canUnhold : transaction . canUnhold ,
265
289
isSelected : selectedTransactions [ transaction . transactionID ] . isSelected ,
266
290
canDelete : transaction . canDelete ,
@@ -281,7 +305,7 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
281
305
newTransactionList [ transaction . transactionID ] = {
282
306
action : transaction . action ,
283
307
canHold : transaction . canHold ,
284
- isHeld : TransactionUtils . isOnHold ( transaction ) ,
308
+ isHeld : isOnHold ( transaction ) ,
285
309
canUnhold : transaction . canUnhold ,
286
310
isSelected : selectedTransactions [ transaction . transactionID ] . isSelected ,
287
311
canDelete : transaction . canDelete ,
@@ -328,8 +352,8 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
328
352
return < FullPageOfflineBlockingView > { null } </ FullPageOfflineBlockingView > ;
329
353
}
330
354
331
- const ListItem = SearchUIUtils . getListItem ( type , status ) ;
332
- const sortedData = SearchUIUtils . getSortedSections ( type , status , data , sortBy , sortOrder ) ;
355
+ const ListItem = getListItem ( type , status ) ;
356
+ const sortedData = getSortedSections ( type , status , data , sortBy , sortOrder ) ;
333
357
const isChat = type === CONST . SEARCH . DATA_TYPES . CHAT ;
334
358
const sortedSelectedData = sortedData . map ( ( item ) => {
335
359
const baseKey = isChat
@@ -364,10 +388,10 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
364
388
}
365
389
366
390
const toggleTransaction = ( item : TransactionListItemType | ReportListItemType | ReportActionListItemType ) => {
367
- if ( SearchUIUtils . isReportActionListItemType ( item ) ) {
391
+ if ( isReportActionListItemType ( item ) ) {
368
392
return ;
369
393
}
370
- if ( SearchUIUtils . isTransactionListItemType ( item ) ) {
394
+ if ( isTransactionListItemType ( item ) ) {
371
395
if ( ! item . keyForList ) {
372
396
return ;
373
397
}
@@ -398,21 +422,21 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
398
422
399
423
const openReport = ( item : TransactionListItemType | ReportListItemType | ReportActionListItemType ) => {
400
424
const isFromSelfDM = item . reportID === CONST . REPORT . UNREPORTED_REPORTID ;
401
- let reportID = SearchUIUtils . isTransactionListItemType ( item ) && ( ! item . isFromOneTransactionReport || isFromSelfDM ) ? item . transactionThreadReportID : item . reportID ;
425
+ let reportID = isTransactionListItemType ( item ) && ( ! item . isFromOneTransactionReport || isFromSelfDM ) ? item . transactionThreadReportID : item . reportID ;
402
426
403
427
if ( ! reportID ) {
404
428
return ;
405
429
}
406
430
407
431
// If we're trying to open a legacy transaction without a transaction thread, let's create the thread and navigate the user
408
- if ( SearchUIUtils . isTransactionListItemType ( item ) && reportID === '0' && item . moneyRequestReportActionID ) {
409
- reportID = ReportUtils . generateReportID ( ) ;
410
- SearchActions . createTransactionThread ( hash , item . transactionID , reportID , item . moneyRequestReportActionID ) ;
432
+ if ( isTransactionListItemType ( item ) && reportID === '0' && item . moneyRequestReportActionID ) {
433
+ reportID = generateReportID ( ) ;
434
+ createTransactionThread ( hash , item . transactionID , reportID , item . moneyRequestReportActionID ) ;
411
435
}
412
436
413
437
const backTo = Navigation . getActiveRoute ( ) ;
414
438
415
- if ( SearchUIUtils . isReportActionListItemType ( item ) ) {
439
+ if ( isReportActionListItemType ( item ) ) {
416
440
const reportActionID = item . reportActionID ;
417
441
Navigation . navigate ( ROUTES . SEARCH_REPORT . getRoute ( { reportID, reportActionID, backTo} ) ) ;
418
442
return ;
@@ -448,11 +472,11 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
448
472
} ;
449
473
450
474
const onSortPress = ( column : SearchColumnType , order : SortOrder ) => {
451
- const newQuery = SearchQueryUtils . buildSearchQueryString ( { ...queryJSON , sortBy : column , sortOrder : order } ) ;
475
+ const newQuery = buildSearchQueryString ( { ...queryJSON , sortBy : column , sortOrder : order } ) ;
452
476
navigation . setParams ( { q : newQuery } ) ;
453
477
} ;
454
478
455
- const shouldShowYear = SearchUIUtils . shouldShowYear ( searchResults ?. data ) ;
479
+ const shouldShowYear = shouldShowYearUtil ( searchResults ?. data ) ;
456
480
const shouldShowSorting = ! Array . isArray ( status ) && sortableSearchStatuses . includes ( status ) ;
457
481
458
482
return (
@@ -477,7 +501,7 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
477
501
)
478
502
}
479
503
isSelected = { ( item ) =>
480
- status !== CONST . SEARCH . STATUS . EXPENSE . ALL && SearchUIUtils . isReportListItemType ( item )
504
+ status !== CONST . SEARCH . STATUS . EXPENSE . ALL && isReportListItemType ( item )
481
505
? item . transactions . some ( ( transaction ) => selectedTransactions [ transaction . keyForList ] ?. isSelected )
482
506
: ! ! item . isSelected
483
507
}
@@ -501,7 +525,7 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
501
525
onSelectRow = { openReport }
502
526
getItemHeight = { getItemHeightMemoized }
503
527
shouldSingleExecuteRowSelect
504
- shouldPreventDefaultFocusOnSelectRow = { ! DeviceCapabilities . canUseTouchScreen ( ) }
528
+ shouldPreventDefaultFocusOnSelectRow = { ! canUseTouchScreen ( ) }
505
529
shouldPreventDefault = { false }
506
530
listHeaderWrapperStyle = { [ styles . ph8 , styles . pt3 ] }
507
531
containerStyle = { [ styles . pv0 , type === CONST . SEARCH . DATA_TYPES . CHAT && ! isSmallScreenWidth && styles . pt3 ] }
0 commit comments