Skip to content
Merged
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
30 changes: 26 additions & 4 deletions src/hooks/useSearchSelector/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ function useSearchSelectorBase({
const [allPolicyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: passthroughPolicyTagListSelector});
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);

const onListEndReached = useDebounce(() => {
setMaxResults((previous) => previous + maxResultsPerPage);
}, CONST.TIMING.SEARCH_OPTION_LIST_DEBOUNCE_TIME);

const computedSearchTerm = getSearchValueForPhoneOrEmail(debouncedSearchTerm, countryCode);
const trimmedSearchInput = debouncedSearchTerm.trim();

Expand Down Expand Up @@ -336,6 +332,32 @@ function useSearchSelectorBase({
}
})();

const optionsCounters: Required<Record<keyof Options, (options: Options) => number>> = {
recentReports: (options) => options.recentReports?.length ?? 0,
personalDetails: (options) => options.personalDetails?.length ?? 0,
userToInvite: (options) => (options.userToInvite ? 1 : 0),
currentUserOption: (options) => (options.currentUserOption ? 1 : 0),
workspaceChats: (options) => options.workspaceChats?.length ?? 0,
selfDMChat: (options) => (options.selfDMChat ? 1 : 0),
};

const onListEndReached = useDebounce(() => {
if (!areOptionsInitialized) {
return;
}

let optionsCount = 0;
for (const optionsCounter of Object.values(optionsCounters)) {
optionsCount += optionsCounter(baseOptions);
}

if (optionsCount < maxResults) {
return;
}

setMaxResults((previous) => previous + maxResultsPerPage);
}, CONST.TIMING.SEARCH_OPTION_LIST_DEBOUNCE_TIME);

const isOptionSelected = (option: OptionData) => selectedOptions.some((selected) => doOptionsMatch(selected, option));

const searchOptions = {
Expand Down
Loading