@@ -34,6 +34,7 @@ import useOnyx from '@hooks/useOnyx';
3434import usePermissions from '@hooks/usePermissions' ;
3535import usePrevious from '@hooks/usePrevious' ;
3636import useResponsiveLayout from '@hooks/useResponsiveLayout' ;
37+ import useSearchShouldCalculateTotals from '@hooks/useSearchShouldCalculateTotals' ;
3738import useSelfDMReport from '@hooks/useSelfDMReport' ;
3839import useTheme from '@hooks/useTheme' ;
3940import useThemeStyles from '@hooks/useThemeStyles' ;
@@ -109,8 +110,17 @@ function SearchPage({route}: SearchPageProps) {
109110 const theme = useTheme ( ) ;
110111 const { isOffline} = useNetwork ( ) ;
111112 const { isDelegateAccessRestricted, showDelegateNoAccessModal} = useContext ( DelegateNoAccessContext ) ;
112- const { selectedTransactions, clearSelectedTransactions, selectedReports, lastSearchType, setLastSearchType, areAllMatchingItemsSelected, selectAllMatchingItems, currentSearchResults} =
113- useSearchContext ( ) ;
113+ const {
114+ selectedTransactions,
115+ clearSelectedTransactions,
116+ selectedReports,
117+ lastSearchType,
118+ setLastSearchType,
119+ areAllMatchingItemsSelected,
120+ selectAllMatchingItems,
121+ currentSearchKey,
122+ currentSearchResults,
123+ } = useSearchContext ( ) ;
114124 const currentUserPersonalDetails = useCurrentUserPersonalDetails ( ) ;
115125 const isMobileSelectionModeEnabled = useMobileSelectionMode ( clearSelectedTransactions ) ;
116126 const allTransactions = useAllTransactions ( ) ;
@@ -1187,7 +1197,8 @@ function SearchPage({route}: SearchPageProps) {
11871197 const { resetVideoPlayerData} = usePlaybackActionsContext ( ) ;
11881198
11891199 const metadata = searchResults ?. search ;
1190- const shouldShowFooter = ! ! metadata ?. count || selectedTransactionsKeys . length > 0 ;
1200+ const shouldAllowFooterTotals = useSearchShouldCalculateTotals ( currentSearchKey , queryJSON ?. hash , true ) ;
1201+ const shouldShowFooter = selectedTransactionsKeys . length > 0 || ( shouldAllowFooterTotals && ! ! metadata ?. count ) ;
11911202
11921203 // Handles video player cleanup:
11931204 // 1. On mount: Resets player if navigating from report screen
@@ -1229,7 +1240,11 @@ function SearchPage({route}: SearchPageProps) {
12291240 } , [ ] ) ;
12301241
12311242 const footerData = useMemo ( ( ) => {
1232- const shouldUseClientTotal = ! metadata ?. count || ( selectedTransactionsKeys . length > 0 && ! areAllMatchingItemsSelected ) ;
1243+ if ( ! shouldAllowFooterTotals && selectedTransactionsKeys . length === 0 ) {
1244+ return { count : undefined , total : undefined , currency : undefined } ;
1245+ }
1246+
1247+ const shouldUseClientTotal = selectedTransactionsKeys . length > 0 || ! metadata ?. count || ( selectedTransactionsKeys . length > 0 && ! areAllMatchingItemsSelected ) ;
12331248 const selectedTransactionItems = Object . values ( selectedTransactions ) ;
12341249 const currency = metadata ?. currency ?? selectedTransactionItems . at ( 0 ) ?. groupCurrency ;
12351250 const numberOfExpense = shouldUseClientTotal
@@ -1245,7 +1260,7 @@ function SearchPage({route}: SearchPageProps) {
12451260 const total = shouldUseClientTotal ? selectedTransactionItems . reduce ( ( acc , transaction ) => acc - ( transaction . groupAmount ?? 0 ) , 0 ) : metadata ?. total ;
12461261
12471262 return { count : numberOfExpense , total, currency} ;
1248- } , [ areAllMatchingItemsSelected , metadata ?. count , metadata ?. currency , metadata ?. total , selectedTransactions , selectedTransactionsKeys ] ) ;
1263+ } , [ areAllMatchingItemsSelected , metadata ?. count , metadata ?. currency , metadata ?. total , selectedTransactions , selectedTransactionsKeys , shouldAllowFooterTotals ] ) ;
12491264
12501265 const onSortPressedCallback = useCallback ( ( ) => {
12511266 setIsSorting ( true ) ;
@@ -1308,6 +1323,7 @@ function SearchPage({route}: SearchPageProps) {
13081323 currentSelectedReportID = { selectedTransactionReportIDs ?. at ( 0 ) ?? selectedReportIDs ?. at ( 0 ) }
13091324 confirmPayment = { onBulkPaySelected }
13101325 latestBankItems = { latestBankItems }
1326+ shouldShowFooter = { shouldShowFooter }
13111327 />
13121328 < DragAndDropConsumer onDrop = { initScanRequest } >
13131329 < DropZoneUI
0 commit comments