Skip to content

Commit 6b3047f

Browse files
authored
Merge pull request Expensify#64995 from callstack-internal/perf-bottom-bar-switching-and-search
perf: bottom bar switching and search
2 parents 9092e8e + ff26b84 commit 6b3047f

5 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/components/AccountSwitcher.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) {
4545
const {isOffline} = useNetwork();
4646
const {shouldUseNarrowLayout} = useResponsiveLayout();
4747
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
48-
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false});
48+
const [accountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false, selector: (onyxSession) => onyxSession?.accountID});
4949
const buttonRef = useRef<HTMLDivElement>(null);
5050
const {windowHeight} = useWindowDimensions();
5151

@@ -230,7 +230,7 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) {
230230
style={[styles.textLabelSupporting, styles.mt1, styles.w100]}
231231
numberOfLines={1}
232232
>
233-
AccountID: {session?.accountID}
233+
AccountID: {accountID}
234234
</Text>
235235
)}
236236
</View>

src/components/Search/FilterDropdowns/DropdownButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function DropdownButton({label, value, viewportOffsetTop, PopoverComponent}: Dro
140140
height: CONST.POPOVER_DROPDOWN_MIN_HEIGHT,
141141
}}
142142
>
143-
{PopoverComponent({closeOverlay: toggleOverlay})}
143+
{isOverlayVisible && <PopoverComponent closeOverlay={toggleOverlay} />}
144144
</PopoverWithMeasuredContent>
145145
</>
146146
);

src/components/Search/FilterDropdowns/UserSelectPopup.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ function UserSelectPopup({value, closeOverlay, onChange}: UserSelectPopupProps)
4141
const personalDetails = usePersonalDetails();
4242
const {windowHeight} = useWindowDimensions();
4343
const {shouldUseNarrowLayout} = useResponsiveLayout();
44-
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true});
44+
const [accountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: (onyxSession) => onyxSession?.accountID});
4545

4646
const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState('');
4747
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false, canBeMissing: true});
4848
const [selectedOptions, setSelectedOptions] = useState<Option[]>(() => {
49-
return value.reduce<OptionData[]>((acc, accountID) => {
50-
const participant = personalDetails?.[accountID];
49+
return value.reduce<OptionData[]>((acc, id) => {
50+
const participant = personalDetails?.[id];
5151
if (!participant) {
5252
return acc;
5353
}
@@ -90,17 +90,17 @@ function UserSelectPopup({value, closeOverlay, onChange}: UserSelectPopupProps)
9090
}))
9191
.sort((a, b) => {
9292
// Put the current user at the top of the list
93-
if (a.accountID === session?.accountID) {
93+
if (a.accountID === accountID) {
9494
return -1;
9595
}
96-
if (b.accountID === session?.accountID) {
96+
if (b.accountID === accountID) {
9797
return 1;
9898
}
9999
return 0;
100100
});
101101

102102
return [...(personalDetailList ?? []), ...(recentReports ?? [])];
103-
}, [cleanSearchTerm, options.personalDetails, options.reports, selectedOptions, session?.accountID]);
103+
}, [cleanSearchTerm, options.personalDetails, options.reports, selectedOptions, accountID]);
104104

105105
const {sections, headerMessage} = useMemo(() => {
106106
const newSections: Section[] = [

src/components/Search/SearchPageHeader/SearchFiltersBar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions}: SearchFiltersBarPro
5959
const {shouldUseNarrowLayout} = useResponsiveLayout();
6060
const {selectedTransactions, setExportMode, isExportMode, shouldShowExportModeOption, shouldShowFiltersBarLoading} = useSearchContext();
6161

62-
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true});
62+
const [email] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: (onyxSession) => onyxSession?.email});
6363
const [userCardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true});
6464
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false});
6565
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
@@ -68,16 +68,16 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions}: SearchFiltersBarPro
6868
const [policyCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES, {canBeMissing: true});
6969
const [workspaceCardFeeds] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, {canBeMissing: true});
7070
const [selectionMode] = useOnyx(ONYXKEYS.MOBILE_SELECTION_MODE, {canBeMissing: true});
71-
const [currentSearchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`, {canBeMissing: true});
71+
const [searchResultsErrors] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`, {canBeMissing: true, selector: (data) => data?.errors});
7272

7373
const taxRates = getAllTaxRates();
7474
const allCards = useMemo(() => mergeCardListWithWorkspaceFeeds(workspaceCardFeeds ?? CONST.EMPTY_OBJECT, userCardList), [userCardList, workspaceCardFeeds]);
7575
const selectedTransactionsKeys = useMemo(() => Object.keys(selectedTransactions ?? {}), [selectedTransactions]);
7676

77-
const hasErrors = Object.keys(currentSearchResults?.errors ?? {}).length > 0 && !isOffline;
77+
const hasErrors = Object.keys(searchResultsErrors ?? {}).length > 0 && !isOffline;
7878
const shouldShowSelectedDropdown = headerButtonsOptions.length > 0 && (!shouldUseNarrowLayout || (!!selectionMode && selectionMode.isEnabled));
7979

80-
const typeOptions = useMemo(() => getTypeOptions(allPolicies, session?.email), [allPolicies, session?.email]);
80+
const typeOptions = useMemo(() => getTypeOptions(allPolicies, email), [allPolicies, email]);
8181

8282
const filterFormValues = useMemo(() => {
8383
return buildFilterFormValuesFromQuery(queryJSON, policyCategories, policyTagsLists, currencyList, personalDetails, allCards, reports, taxRates);

src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
9292
const {translate} = useLocalize();
9393
const [isLoading = false] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true});
9494
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: true});
95-
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false});
95+
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false, selector: (onyxSession) => ({email: onyxSession?.email, accountID: onyxSession?.accountID})});
9696
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, {canBeMissing: true});
9797
const [quickActionReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${quickAction?.chatReportID}`, {canBeMissing: true});
9898
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${quickActionReport?.reportID}`, {canBeMissing: true});

0 commit comments

Comments
 (0)