Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions src/pages/home/YourSpendSection/useYourSpendData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {search} from '@libs/actions/Search';
import {getDisplayableExpensifyCards, getDisplayableThirdPartyCards, isPersonalCard, lastFourNumbersFromCardName} from '@libs/CardUtils';
import {arePaymentsEnabled, isPaidGroupPolicy} from '@libs/PolicyUtils';
import {buildSearchQueryJSON} from '@libs/SearchQueryUtils';
import {getSuggestedSearches, getSuggestedSearchesVisibility, TODO_SEARCH_KEYS} from '@libs/SearchUIUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Card, Policy, Report} from '@src/types/onyx';
Expand Down Expand Up @@ -130,7 +129,7 @@ function getYourSpendRowState({isApplicable, isOffline, searchResults}: GetYourS
}

function useYourSpendData(): UseYourSpendDataReturn {
const {accountID, email} = useCurrentUserPersonalDetails();
const {accountID} = useCurrentUserPersonalDetails();
const {isOffline} = useNetwork();
const isFocused = useIsFocused();

Expand Down Expand Up @@ -366,11 +365,6 @@ function useYourSpendData(): UseYourSpendDataReturn {
// (which changes the policyID filter), or the set of OUTSTANDING reports changes.
const applicabilityKey = `${isApprovalApplicable ? 1 : 0}${isPaymentApplicable ? 1 : 0}|${paidGroupPolicyIDs.join(',')}|${outstandingReportsSignature ?? ''}`;

// The `cardFeedsByPolicy` and `defaultExpensifyCard` params are not passed
// because they have no effect on the `TODO_SEARCH_KEYS` (and we are only interested in `TODO_SEARCH_KEYS`)
const {visibility: suggestedSearchesVisibility} = getSuggestedSearchesVisibility(email, {}, policies, undefined);
const suggestedSearches = getSuggestedSearches(accountID);

const fireSearches = useEffectEvent(() => {
if (isOffline) {
return;
Expand Down Expand Up @@ -412,33 +406,14 @@ function useYourSpendData(): UseYourSpendDataReturn {
shouldUpdateLastSearchParams: false,
});
}
for (const searchKey of TODO_SEARCH_KEYS) {
const isVisible = suggestedSearchesVisibility[searchKey];
if (!isVisible) {
continue;
}
const queryJSON = suggestedSearches[searchKey].searchQueryJSON;
if (!queryJSON) {
continue;
}
search({
queryJSON,
searchKey,
offset: 0,
isOffline,
isLoading: false,
shouldCalculateTotals: false,
shouldUpdateLastSearchParams: false,
});
}
});

useEffect(() => {
if (!isFocused) {
return;
}
fireSearches();
}, [isFocused, isOffline, displayableCardIDsKey, applicabilityKey, suggestedSearchesVisibility]);
}, [isFocused, isOffline, displayableCardIDsKey, applicabilityKey]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep fetching visible to-do searches

When a user has visible Submit/Approve/Pay/Export todos but those reports are not already hydrated locally, removing the to-do search requests leaves no replacement fetch path: useSearchPageSetup skips the Search API for to-do tabs when shouldUseLiveData is true, and SearchResultsProvider then renders from ONYXKEYS.DERIVED.TODOS, which is computed only from local report/transaction collections. In that fresh-login or cold-cache case the Home/For You counts and the to-do search tabs can stay empty until some unrelated flow loads the reports, so the effect still needs to request the visible to-do searches (or another fetch path must be added).

Useful? React with 👍 / 👎.


return {
approvalRowState,
Expand Down
Loading