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
11 changes: 3 additions & 8 deletions src/components/Search/FilterDropdowns/UserSelectPopup.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import isEmpty from 'lodash/isEmpty';
import React, {memo, useCallback, useEffect, useMemo, useState} from 'react';
import React, {memo, useCallback, useMemo, useState} from 'react';
import {View} from 'react-native';
import Button from '@components/Button';
import {usePersonalDetails} from '@components/OnyxProvider';
import {useOptionsList} from '@components/OptionListContextProvider';
import SelectionList from '@components/SelectionList';
import UserSelectionListItem from '@components/SelectionList/Search/UserSelectionListItem';
import useDebouncedState from '@hooks/useDebouncedState';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
Expand All @@ -16,7 +15,6 @@ import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus';
import type {Option, Section} from '@libs/OptionsListUtils';
import {filterAndOrderOptions, getValidOptions} from '@libs/OptionsListUtils';
import type {OptionData} from '@libs/ReportUtils';
import {searchInServer} from '@userActions/Report';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

Expand Down Expand Up @@ -45,7 +43,7 @@ function UserSelectPopup({value, closeOverlay, onChange}: UserSelectPopupProps)
const [accountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: (onyxSession) => onyxSession?.accountID});
const shouldFocusInputOnScreenFocus = canFocusInputOnScreenFocus();

const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState('');
const [searchTerm, setSearchTerm] = useState('');
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false, canBeMissing: true});
const [selectedOptions, setSelectedOptions] = useState<Option[]>(() => {
return value.reduce<OptionData[]>((acc, id) => {
Expand Down Expand Up @@ -83,6 +81,7 @@ function UserSelectPopup({value, closeOverlay, onChange}: UserSelectPopupProps)
const {personalDetails: filteredOptionsList, recentReports} = filterAndOrderOptions(optionsList, cleanSearchTerm, {
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
canInviteUser: false,
});

const personalDetailList = filteredOptionsList
Expand Down Expand Up @@ -154,10 +153,6 @@ function UserSelectPopup({value, closeOverlay, onChange}: UserSelectPopupProps)
closeOverlay();
}, [closeOverlay, onChange]);

useEffect(() => {
searchInServer(debouncedSearchTerm.trim());
}, [debouncedSearchTerm]);

const isLoadingNewOptions = !!isSearchingForReports;
const dataLength = sections.flatMap((section) => section.data).length;

Expand Down
9 changes: 2 additions & 7 deletions src/components/Search/SearchFiltersParticipantsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {usePersonalDetails} from '@components/OnyxProvider';
import {useOptionsList} from '@components/OptionListContextProvider';
import SelectionList from '@components/SelectionList';
import UserSelectionListItem from '@components/SelectionList/Search/UserSelectionListItem';
import useDebouncedState from '@hooks/useDebouncedState';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus';
Expand All @@ -13,7 +12,6 @@ import type {Option, Section} from '@libs/OptionsListUtils';
import type {OptionData} from '@libs/ReportUtils';
import {getDisplayNameForParticipant} from '@libs/ReportUtils';
import Navigation from '@navigation/Navigation';
import {searchInServer} from '@userActions/Report';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -47,7 +45,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:

const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {canBeMissing: false, initWithStoredValues: false});
const [selectedOptions, setSelectedOptions] = useState<OptionData[]>([]);
const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState('');
const [searchTerm, setSearchTerm] = useState('');
const cleanSearchTerm = useMemo(() => searchTerm.trim().toLowerCase(), [searchTerm]);

const defaultOptions = useMemo(() => {
Expand All @@ -72,6 +70,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
selectedOptions,
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
canInviteUser: false,
});
}, [defaultOptions, cleanSearchTerm, selectedOptions]);

Expand Down Expand Up @@ -156,10 +155,6 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps -- this should react only to changes in form data
}, [initialAccountIDs, personalDetails]);

useEffect(() => {
searchInServer(debouncedSearchTerm.trim());
}, [debouncedSearchTerm]);

const handleParticipantSelection = useCallback(
(option: Option) => {
const foundOptionIndex = selectedOptions.findIndex((selectedOption: Option) => {
Expand Down
Loading