Skip to content

Commit f74a8bd

Browse files
committed
fix: visual glitches
1 parent a67c81e commit f74a8bd

2 files changed

Lines changed: 31 additions & 25 deletions

File tree

src/components/Search/FilterDropdowns/UserSelectPopup.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
1414
import useWindowDimensions from '@hooks/useWindowDimensions';
1515
import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus';
1616
import {getParticipantsOption} from '@libs/OptionsListUtils';
17+
import {doesPersonalDetailMatchSearchTerm} from '@libs/OptionsListUtils/searchMatchUtils';
1718
import type {OptionData} from '@libs/ReportUtils';
1819
import CONST from '@src/CONST';
1920
import ONYXKEYS from '@src/ONYXKEYS';
@@ -103,9 +104,11 @@ function UserSelectPopup({value, label, closeOverlay, onChange, isSearchable}: U
103104
if (currentUserPersonalDetail) {
104105
currentUserOption = currentUserPersonalDetail;
105106
} else if (personalDetails?.[currentUserAccountID]) {
106-
currentUserOption = {
107-
...getParticipantsOption(personalDetails[currentUserAccountID], personalDetails),
108-
} as OptionData;
107+
const candidateOption = getParticipantsOption(personalDetails[currentUserAccountID], personalDetails) as OptionData;
108+
const trimmedSearchTerm = debouncedSearchTerm.trim().toLowerCase();
109+
if (!trimmedSearchTerm || doesPersonalDetailMatchSearchTerm(candidateOption, currentUserAccountID, trimmedSearchTerm)) {
110+
currentUserOption = candidateOption;
111+
}
109112
}
110113
}
111114

@@ -141,7 +144,7 @@ function UserSelectPopup({value, label, closeOverlay, onChange, isSearchable}: U
141144
keyForList: option.keyForList ?? option.login ?? '',
142145
}));
143146
return combinedOptionsWithKeyForList;
144-
}, [availableOptions.personalDetails, availableOptions.recentReports, selectedOptionsForDisplay, currentUserAccountID, personalDetails]);
147+
}, [availableOptions.personalDetails, availableOptions.recentReports, selectedOptionsForDisplay, currentUserAccountID, personalDetails, debouncedSearchTerm]);
145148

146149
const headerMessage = useMemo(() => {
147150
const noResultsFound = isEmpty(listData);

src/components/Search/SearchFiltersParticipantsSelector.tsx

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionS
1111
import useSearchSelector from '@hooks/useSearchSelector';
1212
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
1313
import {formatSectionsFromSearchTerm, getFilteredRecentAttendees, getParticipantsOption} from '@libs/OptionsListUtils';
14+
import {doesPersonalDetailMatchSearchTerm} from '@libs/OptionsListUtils/searchMatchUtils';
1415
import type {OptionData} from '@libs/ReportUtils';
1516
import {getDisplayNameForParticipant} from '@libs/ReportUtils';
1617
import Navigation from '@navigation/Navigation';
@@ -76,18 +77,19 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate,
7677
[personalDetails, recentAttendees, currentUserEmail, currentUserAccountID, shouldAllowNameOnlyOptions],
7778
);
7879

79-
const {searchTerm, setSearchTerm, availableOptions, selectedOptions, setSelectedOptions, toggleSelection, areOptionsInitialized, onListEndReached} = useSearchSelector({
80-
selectionMode: CONST.SEARCH_SELECTOR.SELECTION_MODE_MULTI,
81-
searchContext: CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_GENERAL,
82-
maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
83-
includeUserToInvite: true,
84-
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
85-
includeRecentReports: true,
86-
shouldInitialize: didScreenTransitionEnd,
87-
includeCurrentUser: true,
88-
recentAttendees: recentAttendeeLists,
89-
shouldAllowNameOnlyOptions,
90-
});
80+
const {searchTerm, debouncedSearchTerm, setSearchTerm, availableOptions, selectedOptions, setSelectedOptions, toggleSelection, areOptionsInitialized, onListEndReached} =
81+
useSearchSelector({
82+
selectionMode: CONST.SEARCH_SELECTOR.SELECTION_MODE_MULTI,
83+
searchContext: CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_GENERAL,
84+
maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
85+
includeUserToInvite: true,
86+
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
87+
includeRecentReports: true,
88+
shouldInitialize: didScreenTransitionEnd,
89+
includeCurrentUser: true,
90+
recentAttendees: recentAttendeeLists,
91+
shouldAllowNameOnlyOptions,
92+
});
9193

9294
const {sections, headerMessage} = useMemo(() => {
9395
const newSections = [];
@@ -104,7 +106,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate,
104106
}
105107

106108
const formattedResults = formatSectionsFromSearchTerm(
107-
searchTerm.trim().toLowerCase(),
109+
debouncedSearchTerm.trim().toLowerCase(),
108110
selectedOptions,
109111
chatOptions.recentReports,
110112
chatOptions.personalDetails,
@@ -116,7 +118,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate,
116118
undefined,
117119
reportAttributesDerived,
118120
);
119-
const selectedCurrentUser = formattedResults.section.data.find((option) => option.accountID === chatOptions.currentUserOption?.accountID);
121+
const selectedCurrentUser = formattedResults.section.data.find((option) => option.accountID === currentUserAccountID);
120122

121123
// If the current user is already selected, remove them from the recent reports and personal details
122124
if (selectedCurrentUser) {
@@ -128,12 +130,13 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate,
128130
// Falls back to creating from personal details to handle pagination edge cases
129131
if (!selectedCurrentUser) {
130132
let currentUserOptionToShow = chatOptions.currentUserOption;
131-
132-
// Fallback: create current user option from personalDetails if not in paginated results
133-
if (!currentUserOptionToShow && currentUserAccountID && personalDetails?.[currentUserAccountID]) {
134-
currentUserOptionToShow = {
135-
...getParticipantsOption(personalDetails[currentUserAccountID], personalDetails),
136-
} as OptionData;
133+
const currentUserDetails = currentUserAccountID ? personalDetails?.[currentUserAccountID] : undefined;
134+
if (!currentUserOptionToShow && currentUserAccountID && currentUserDetails) {
135+
const candidateOption = getParticipantsOption(currentUserDetails, personalDetails) as OptionData;
136+
const trimmedSearchTerm = debouncedSearchTerm.trim().toLowerCase();
137+
if (!trimmedSearchTerm || doesPersonalDetailMatchSearchTerm(candidateOption, currentUserAccountID, trimmedSearchTerm)) {
138+
currentUserOptionToShow = candidateOption;
139+
}
137140
}
138141

139142
if (currentUserOptionToShow) {
@@ -187,7 +190,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate,
187190
}, [
188191
areOptionsInitialized,
189192
availableOptions,
190-
searchTerm,
193+
debouncedSearchTerm,
191194
selectedOptions,
192195
privateIsArchivedMap,
193196
currentUserAccountID,

0 commit comments

Comments
 (0)