Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ const ONYXKEYS = {
/** Set when we are loading fresh subscription/billing data from the server */
IS_LOADING_SUBSCRIPTION_DATA: 'isLoadingSubscriptionData',

/** Set when OpenSearchPage has been fetched for the first time */
IS_SEARCH_PAGE_DATA_LOADED: 'isSearchPageDataLoaded',

/** Is the app loaded? */
HAS_LOADED_APP: 'hasLoadedApp',

Expand Down Expand Up @@ -1359,6 +1362,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.IS_LOADING_SHARE_BANK_ACCOUNTS]: boolean;
[ONYXKEYS.IS_LOADING_POLICY_CODING_RULES_PREVIEW]: boolean;
[ONYXKEYS.IS_LOADING_SUBSCRIPTION_DATA]: boolean;
[ONYXKEYS.IS_SEARCH_PAGE_DATA_LOADED]: boolean;
[ONYXKEYS.IS_LOADING_REPORT_DATA]: boolean;
[ONYXKEYS.IS_TEST_TOOLS_MODAL_OPEN]: boolean;
[ONYXKEYS.IS_LOADING_APP]: boolean;
Expand Down
5 changes: 0 additions & 5 deletions src/hooks/useSearchTypeMenuSections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ const useSearchTypeMenuSections = (queryParams?: UseSearchTypeMenuSectionsParams
openCreateReportConfirmation();
}, [pendingReportCreation, openCreateReportConfirmation]);

const isSuggestedSearchDataReady = useMemo(() => {
return Object.values(allPolicies ?? {}).some((policy) => policy?.employeeList !== undefined && policy?.exporter !== undefined);
}, [allPolicies]);

const typeMenuSections = useMemo(
() =>
createTypeMenuSections({
Expand Down Expand Up @@ -149,7 +145,6 @@ const useSearchTypeMenuSections = (queryParams?: UseSearchTypeMenuSectionsParams

return {
typeMenuSections,
shouldShowSuggestedSearchSkeleton: !isSuggestedSearchDataReady && !isOffline,
activeItemIndex,
};
};
Expand Down
10 changes: 9 additions & 1 deletion src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,15 @@ function deleteSavedSearch(hash: number) {
}

function openSearchPage({includePartiallySetupBankAccounts}: OpenSearchPageParams) {
API.read(READ_COMMANDS.OPEN_SEARCH_PAGE, {includePartiallySetupBankAccounts});
const successData: Array<OnyxUpdate<typeof ONYXKEYS.IS_SEARCH_PAGE_DATA_LOADED>> = [
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.IS_SEARCH_PAGE_DATA_LOADED,
value: true,
},
];

API.read(READ_COMMANDS.OPEN_SEARCH_PAGE, {includePartiallySetupBankAccounts}, {successData});
}

// Tracks in-flight search requests by hash+offset to prevent duplicate API calls
Expand Down
12 changes: 9 additions & 3 deletions src/pages/Search/SearchTypeMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {SearchQueryJSON} from '@components/Search/types';
import Text from '@components/Text';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useSearchTypeMenuSections from '@hooks/useSearchTypeMenuSections';
import useSingleExecution from '@hooks/useSingleExecution';
Expand All @@ -21,6 +22,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import todosReportCountsSelector from '@src/selectors/Todos';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import SavedSearchList from './SavedSearchList';
import SearchTypeMenuItem from './SearchTypeMenuItem';
import SuggestedSearchSkeleton from './SuggestedSearchSkeleton';
Expand All @@ -33,9 +35,10 @@ function SearchTypeMenu({queryJSON}: SearchTypeMenuProps) {
const {hash, similarSearchHash} = queryJSON ?? {};

const styles = useThemeStyles();
const {singleExecution} = useSingleExecution();
const {isOffline} = useNetwork();
const {translate} = useLocalize();
const {typeMenuSections, shouldShowSuggestedSearchSkeleton, activeItemIndex} = useSearchTypeMenuSections({hash, similarSearchHash});
const {singleExecution} = useSingleExecution();
const {typeMenuSections, activeItemIndex} = useSearchTypeMenuSections({hash, similarSearchHash});
const expensifyIcons = useMemoizedLazyExpensifyIcons([
'Basket',
'CalendarSolid',
Expand All @@ -51,6 +54,7 @@ function SearchTypeMenu({queryJSON}: SearchTypeMenuProps) {
'Folder',
] as const);
const {clearSelectedTransactions} = useSearchActionsContext();
const [isSearchDataLoaded, isSearchDataLoadedResult] = useOnyx(ONYXKEYS.IS_SEARCH_PAGE_DATA_LOADED);
const [reportCounts = CONST.EMPTY_TODOS_REPORT_COUNTS] = useOnyx(ONYXKEYS.DERIVED.TODOS, {selector: todosReportCountsSelector});

const route = useRoute();
Expand Down Expand Up @@ -87,13 +91,15 @@ function SearchTypeMenu({queryJSON}: SearchTypeMenuProps) {
Navigation.navigate(ROUTES.SEARCH_ROOT.getRoute({query: searchQuery}));
});

const areSuggestedSearchesLoading = !isOffline && !isSearchDataLoaded && !isLoadingOnyxValue(isSearchDataLoadedResult);

return (
<ScrollView
onScroll={onScroll}
ref={scrollViewRef}
showsVerticalScrollIndicator={false}
>
{shouldShowSuggestedSearchSkeleton ? (
{areSuggestedSearchesLoading ? (
<View style={[styles.pb4, styles.mh3, styles.gap4]}>
<SuggestedSearchSkeleton />
</View>
Expand Down
114 changes: 0 additions & 114 deletions tests/unit/useSearchTypeMenuSectionsTest.ts

This file was deleted.

Loading