Skip to content

Commit

Permalink
Merge pull request #22095 from Thanos30/fix/massive-lag-on-task-assig…
Browse files Browse the repository at this point in the history
…nee-selection
  • Loading branch information
francoisl authored Jul 6, 2023
2 parents 40c494f + 158bdd9 commit 0e21bc5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
22 changes: 11 additions & 11 deletions src/pages/tasks/TaskAssigneeSelectorModal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable es/no-optional-chaining */
import React, {useState, useEffect, useMemo} from 'react';
import React, {useState, useEffect, useMemo, useCallback} from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import OptionsSelector from '../../components/OptionsSelector';
Expand Down Expand Up @@ -75,16 +76,7 @@ function TaskAssigneeSelectorModal(props) {
const [filteredUserToInvite, setFilteredUserToInvite] = useState(null);
const [filteredCurrentUserOption, setFilteredCurrentUserOption] = useState(null);

useEffect(() => {
const results = OptionsListUtils.getNewChatOptions(props.reports, props.personalDetails, props.betas, '', [], CONST.EXPENSIFY_EMAILS, false);

setFilteredRecentReports(results.recentReports);
setFilteredPersonalDetails(results.personalDetails);
setFilteredUserToInvite(results.userToInvite);
setFilteredCurrentUserOption(results.currentUserOption);
}, [props]);

useEffect(() => {
const updateOptions = useCallback(() => {
const {recentReports, personalDetails, userToInvite, currentUserOption} = OptionsListUtils.getNewChatOptions(
props.reports,
props.personalDetails,
Expand All @@ -103,6 +95,14 @@ function TaskAssigneeSelectorModal(props) {
setFilteredCurrentUserOption(currentUserOption);
}, [props, searchValue]);

useEffect(() => {
const debouncedSearch = _.debounce(updateOptions, 200);
debouncedSearch();
return () => {
debouncedSearch.cancel();
};
}, [updateOptions]);

const onChangeText = (newSearchTerm = '') => {
setSearchValue(newSearchTerm);
};
Expand Down
22 changes: 10 additions & 12 deletions src/pages/tasks/TaskShareDestinationSelectorModal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable es/no-optional-chaining */
import React, {useState, useEffect, useMemo} from 'react';
import React, {useState, useEffect, useMemo, useCallback} from 'react';
import _ from 'underscore';
import {View} from 'react-native';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -48,7 +48,6 @@ function TaskShareDestinationSelectorModal(props) {
const [filteredPersonalDetails, setFilteredPersonalDetails] = useState([]);
const [filteredUserToInvite, setFilteredUserToInvite] = useState(null);

// Filter out all the reports where user is not allowed to create task
const filteredReports = useMemo(() => {
const reports = {};
_.keys(props.reports).forEach((reportKey) => {
Expand All @@ -59,16 +58,7 @@ function TaskShareDestinationSelectorModal(props) {
});
return reports;
}, [props.reports]);

useEffect(() => {
const results = OptionsListUtils.getShareDestinationOptions(filteredReports, props.personalDetails, props.betas, '', [], CONST.EXPENSIFY_EMAILS, true);

setFilteredUserToInvite(results.userToInvite);
setFilteredRecentReports(results.recentReports);
setFilteredPersonalDetails(results.personalDetails);
}, [props, filteredReports]);

useEffect(() => {
const updateOptions = useCallback(() => {
const {recentReports, personalDetails, userToInvite} = OptionsListUtils.getShareDestinationOptions(
filteredReports,
props.personalDetails,
Expand All @@ -86,6 +76,14 @@ function TaskShareDestinationSelectorModal(props) {
setFilteredPersonalDetails(personalDetails);
}, [props, searchValue, filteredReports]);

useEffect(() => {
const debouncedSearch = _.debounce(updateOptions, 150);
debouncedSearch();
return () => {
debouncedSearch.cancel();
};
}, [updateOptions]);

const onChangeText = (newSearchTerm = '') => {
setSearchValue(newSearchTerm);
};
Expand Down

0 comments on commit 0e21bc5

Please sign in to comment.