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
5 changes: 3 additions & 2 deletions src/components/Navigation/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ type TopBarProps = {
shouldDisplaySearch?: boolean;
shouldDisplayHelpButton?: boolean;
cancelSearch?: () => void;
shouldShowLoadingBar?: boolean;
};

function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true, shouldDisplayHelpButton = true, cancelSearch}: TopBarProps) {
function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true, shouldDisplayHelpButton = true, cancelSearch, shouldShowLoadingBar = false}: TopBarProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const policy = usePolicy(activeWorkspaceID);
Expand Down Expand Up @@ -76,7 +77,7 @@ function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true,
{shouldDisplayHelpButton && <HelpButton />}
{displaySearch && <SearchButton />}
</View>
<LoadingBar shouldShow={isLoadingReportData ?? false} />
<LoadingBar shouldShow={(isLoadingReportData ?? false) || shouldShowLoadingBar} />
</View>
);
}
Expand Down
6 changes: 2 additions & 4 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
getSortedSections,
isReportActionListItemType,
isReportListItemType,
isSearchDataLoaded,
isSearchResultsEmpty as isSearchResultsEmptyUtil,
isTransactionListItemType,
shouldShowEmptyState,
Expand Down Expand Up @@ -201,10 +202,7 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS

// There's a race condition in Onyx which makes it return data from the previous Search, so in addition to checking that the data is loaded
// we also need to check that the searchResults matches the type and status of the current search
const isDataLoaded =
searchResults?.data !== undefined && searchResults?.search?.type === type && Array.isArray(status)
? searchResults?.search?.status === status.join(',')
: searchResults?.search?.status === status;
const isDataLoaded = isSearchDataLoaded(currentSearchResults, lastNonEmptySearchResults, queryJSON);

const shouldShowLoadingState = !isOffline && !isDataLoaded;
const shouldShowLoadingMoreItems = !shouldShowLoadingState && searchResults?.search?.isLoading && searchResults?.search?.offset > 0;
Expand Down
14 changes: 13 additions & 1 deletion src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Onyx from 'react-native-onyx';
import type {OnyxCollection} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import type {MenuItemWithLink} from '@components/MenuItemList';
import type {SearchColumnType, SearchStatus, SortOrder} from '@components/Search/types';
import type {SearchColumnType, SearchQueryJSON, SearchStatus, SortOrder} from '@components/Search/types';
import ChatListItem from '@components/SelectionList/ChatListItem';
import ReportListItem from '@components/SelectionList/Search/ReportListItem';
import TransactionListItem from '@components/SelectionList/Search/TransactionListItem';
Expand Down Expand Up @@ -800,6 +800,17 @@ function shouldShowEmptyState(isDataLoaded: boolean, dataLength: number, type: S
return !isDataLoaded || dataLength === 0 || !Object.values(CONST.SEARCH.DATA_TYPES).includes(type);
}

function isSearchDataLoaded(currentSearchResults: SearchResults | undefined, lastNonEmptySearchResults: SearchResults | undefined, queryJSON: SearchQueryJSON | undefined) {
const searchResults = currentSearchResults?.data ? currentSearchResults : lastNonEmptySearchResults;
const {status} = queryJSON ?? {};
const isDataLoaded =
searchResults?.data !== undefined && searchResults?.search?.type === queryJSON?.type && Array.isArray(status)
? searchResults?.search?.status === status.join(',')
: searchResults?.search?.status === status;

return isDataLoaded;
}

export {
getListItem,
getSections,
Expand All @@ -819,5 +830,6 @@ export {
createBaseSavedSearchMenuItem,
shouldShowEmptyState,
compareValues,
isSearchDataLoaded,
};
export type {SavedSearchMenuItem, SearchTypeMenuItem};
5 changes: 5 additions & 0 deletions src/pages/Search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavig
import type {SearchFullscreenNavigatorParamList} from '@libs/Navigation/types';
import {hasVBBA} from '@libs/PolicyUtils';
import {buildCannedSearchQuery, buildSearchQueryJSON, getPolicyIDFromSearchQuery} from '@libs/SearchQueryUtils';
import {isSearchDataLoaded} from '@libs/SearchUIUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -334,6 +335,9 @@ function SearchPage({route}: SearchPageProps) {
const isSearchNameModified = name === q;
const searchName = isSearchNameModified ? undefined : name;

const isDataLoaded = isSearchDataLoaded(currentSearchResults, lastNonEmptySearchResults, queryJSON);
const shouldShowLoadingState = !isOffline && !isDataLoaded;

// Handles video player cleanup:
// 1. On mount: Resets player if navigating from report screen
// 2. On unmount: Stops video when leaving this screen
Expand Down Expand Up @@ -421,6 +425,7 @@ function SearchPage({route}: SearchPageProps) {
<View style={styles.flex1}>
<HeaderGap />
<TopBar
shouldShowLoadingBar={shouldShowLoadingState}
activeWorkspaceID={policyID}
breadcrumbLabel={translate('common.reports')}
shouldDisplaySearch={false}
Expand Down
7 changes: 7 additions & 0 deletions src/pages/Search/SearchPageNarrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import SearchStatusBar from '@components/Search/SearchPageHeader/SearchStatusBar
import type {SearchQueryJSON} from '@components/Search/types';
import useHandleBackButton from '@hooks/useHandleBackButton';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePermissions from '@hooks/usePermissions';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useScrollEventEmitter from '@hooks/useScrollEventEmitter';
Expand All @@ -26,6 +27,7 @@ import useWindowDimensions from '@hooks/useWindowDimensions';
import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
import Navigation from '@libs/Navigation/Navigation';
import {buildCannedSearchQuery, isCannedSearchQuery, isCannedSearchQueryWithPolicyIDCheck} from '@libs/SearchQueryUtils';
import {isSearchDataLoaded} from '@libs/SearchUIUtils';
import variables from '@styles/variables';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -55,6 +57,7 @@ function SearchPageNarrow({queryJSON, policyID, searchName, headerButtonsOptions
const [searchRouterListVisible, setSearchRouterListVisible] = useState(false);
const {canUseLeftHandBar} = usePermissions();
const searchResults = currentSearchResults?.data ? currentSearchResults : lastNonEmptySearchResults;
const {isOffline} = useNetwork();

// Controls the visibility of the educational tooltip based on user scrolling.
// Hides the tooltip when the user is scrolling and displays it once scrolling stops.
Expand Down Expand Up @@ -134,6 +137,9 @@ function SearchPageNarrow({queryJSON, policyID, searchName, headerButtonsOptions
);
}

const isDataLoaded = isSearchDataLoaded(currentSearchResults, lastNonEmptySearchResults, queryJSON);
const shouldShowLoadingState = !isOffline && !isDataLoaded;

return (
<ScreenWrapper
testID={SearchPageNarrow.displayName}
Expand All @@ -148,6 +154,7 @@ function SearchPageNarrow({queryJSON, policyID, searchName, headerButtonsOptions
<View style={[StyleUtils.getSearchBottomTabHeaderStyles(), searchRouterListVisible && styles.flex1, styles.mh100]}>
<View style={[styles.zIndex10, styles.appBG]}>
<TopBar
shouldShowLoadingBar={shouldShowLoadingState}
activeWorkspaceID={policyID}
breadcrumbLabel={translate('common.reports')}
shouldDisplaySearch={false}
Expand Down