Skip to content

Commit 908240e

Browse files
authored
Merge pull request Expensify#64796 from callstack-internal/62335-recent-searches-second
Add loading skeleton to SearchRouter
2 parents 9297c81 + f7e3058 commit 908240e

2 files changed

Lines changed: 55 additions & 46 deletions

File tree

src/components/Search/SearchAutocompleteList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ function SearchAutocompleteList(
719719
// will fail because the list will be empty on first render so we only render after options are initialized.
720720
areOptionsInitialized && (
721721
<SelectionList<OptionData | SearchQueryItem>
722-
showLoadingPlaceholder={!areOptionsInitialized}
722+
showLoadingPlaceholder
723723
fixedNumItemsForLoader={4}
724724
loaderSpeed={CONST.TIMING.SKELETON_ANIMATION_SPEED}
725725
sections={sections}

src/components/Search/SearchRouter/SearchRouter.tsx

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import type {ValueOf} from 'type-fest';
77
import HeaderWithBackButton from '@components/HeaderWithBackButton';
88
import * as Expensicons from '@components/Icon/Expensicons';
99
import {usePersonalDetails} from '@components/OnyxListItemProvider';
10+
import {useOptionsList} from '@components/OptionListContextProvider';
11+
import OptionsListSkeletonView from '@components/OptionsListSkeletonView';
1012
import type {AnimatedTextInputRef} from '@components/RNTextInput';
1113
import type {GetAdditionalSectionsCallback} from '@components/Search/SearchAutocompleteList';
1214
import SearchAutocompleteList from '@components/Search/SearchAutocompleteList';
@@ -83,7 +85,10 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
8385
const {translate} = useLocalize();
8486
const styles = useThemeStyles();
8587
const [, recentSearchesMetadata] = useOnyx(ONYXKEYS.RECENT_SEARCHES, {canBeMissing: true});
88+
const {areOptionsInitialized} = useOptionsList();
8689
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false, canBeMissing: true});
90+
const isRecentSearchesDataLoaded = !isLoadingOnyxValue(recentSearchesMetadata);
91+
const shouldShowList = isRecentSearchesDataLoaded && areOptionsInitialized;
8792
const personalDetails = usePersonalDetails();
8893
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
8994
const [workspaceCardFeeds] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, {canBeMissing: true});
@@ -450,7 +455,6 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
450455
});
451456

452457
const modalWidth = shouldUseNarrowLayout ? styles.w100 : {width: variables.searchRouterPopoverWidth};
453-
const isRecentSearchesDataLoaded = !isLoadingOnyxValue(recentSearchesMetadata);
454458

455459
const focusTimeoutRef = useRef<NodeJS.Timeout | null>(null);
456460
/** We added a delay to focus on text input to allow navigation/modal animations to get completed, see issue https://github.com/Expensify/App/issues/65855 for more details */
@@ -482,51 +486,56 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
482486
shouldDisplayHelpButton={false}
483487
/>
484488
)}
485-
{isRecentSearchesDataLoaded && (
486-
<>
487-
<SearchInputSelectionWrapper
488-
value={textInputValue}
489-
isFullWidth={shouldUseNarrowLayout}
490-
onSearchQueryChange={onSearchQueryChange}
491-
onSubmit={() => {
492-
const focusedOption = listRef.current?.getFocusedOption();
493-
494-
if (!focusedOption) {
495-
submitSearch(textInputValue);
496-
return;
497-
}
489+
<SearchInputSelectionWrapper
490+
value={textInputValue}
491+
isFullWidth={shouldUseNarrowLayout}
492+
onSearchQueryChange={onSearchQueryChange}
493+
onSubmit={() => {
494+
const focusedOption = listRef.current?.getFocusedOption();
495+
496+
if (!focusedOption) {
497+
submitSearch(textInputValue);
498+
return;
499+
}
498500

499-
onListItemPress(focusedOption);
500-
}}
501-
caretHidden={shouldHideInputCaret}
502-
autocompleteListRef={listRef}
503-
shouldShowOfflineMessage
504-
wrapperStyle={{...styles.border, ...styles.alignItemsCenter}}
505-
outerWrapperStyle={[shouldUseNarrowLayout ? styles.mv3 : styles.mv2, shouldUseNarrowLayout ? styles.mh5 : styles.mh2]}
506-
wrapperFocusedStyle={styles.borderColorFocus}
507-
isSearchingForReports={isSearchingForReports}
508-
selection={selection}
509-
substitutionMap={autocompleteSubstitutions}
510-
ref={textInputRef}
511-
autoFocus={false}
512-
/>
513-
<SearchAutocompleteList
514-
autocompleteQueryValue={autocompleteQueryValue || textInputValue}
515-
handleSearch={searchInServer}
516-
searchQueryItem={searchQueryItem}
517-
getAdditionalSections={getAdditionalSections}
518-
onListItemPress={onListItemPress}
519-
setTextQuery={setTextAndUpdateSelection}
520-
updateAutocompleteSubstitutions={updateAutocompleteSubstitutions}
521-
onHighlightFirstItem={() => listRef.current?.updateAndScrollToFocusedIndex(1)}
522-
ref={listRef}
523-
textInputRef={textInputRef}
524-
personalDetails={personalDetails}
525-
reports={reports}
526-
allFeeds={allFeeds}
527-
allCards={allCards}
528-
/>
529-
</>
501+
onListItemPress(focusedOption);
502+
}}
503+
caretHidden={shouldHideInputCaret}
504+
autocompleteListRef={listRef}
505+
shouldShowOfflineMessage
506+
wrapperStyle={{...styles.border, ...styles.alignItemsCenter}}
507+
outerWrapperStyle={[shouldUseNarrowLayout ? styles.mv3 : styles.mv2, shouldUseNarrowLayout ? styles.mh5 : styles.mh2]}
508+
wrapperFocusedStyle={styles.borderColorFocus}
509+
isSearchingForReports={isSearchingForReports}
510+
selection={selection}
511+
substitutionMap={autocompleteSubstitutions}
512+
ref={textInputRef}
513+
autoFocus={false}
514+
/>
515+
{shouldShowList && (
516+
<SearchAutocompleteList
517+
autocompleteQueryValue={autocompleteQueryValue || textInputValue}
518+
handleSearch={searchInServer}
519+
searchQueryItem={searchQueryItem}
520+
getAdditionalSections={getAdditionalSections}
521+
onListItemPress={onListItemPress}
522+
setTextQuery={setTextAndUpdateSelection}
523+
updateAutocompleteSubstitutions={updateAutocompleteSubstitutions}
524+
onHighlightFirstItem={() => listRef.current?.updateAndScrollToFocusedIndex(1)}
525+
ref={listRef}
526+
textInputRef={textInputRef}
527+
personalDetails={personalDetails}
528+
reports={reports}
529+
allFeeds={allFeeds}
530+
allCards={allCards}
531+
/>
532+
)}
533+
{!shouldShowList && (
534+
<OptionsListSkeletonView
535+
fixedNumItems={4}
536+
shouldStyleAsTable
537+
speed={CONST.TIMING.SKELETON_ANIMATION_SPEED}
538+
/>
530539
)}
531540
</View>
532541
);

0 commit comments

Comments
 (0)