Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debounce search page and reduce number of tooltips created #3669

Merged
merged 1 commit into from
Jun 18, 2021
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
45 changes: 27 additions & 18 deletions src/pages/SearchPage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'underscore';
import React, {Component} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -64,6 +65,9 @@ class SearchPage extends Component {
Timing.start(CONST.TIMING.SEARCH_RENDER);

this.selectReport = this.selectReport.bind(this);
this.onChangeText = this.onChangeText.bind(this);
this.debouncedUpdateOptions = _.debounce(this.updateOptions.bind(this), 300);

const {
recentReports,
personalDetails,
Expand All @@ -87,6 +91,10 @@ class SearchPage extends Component {
Timing.end(CONST.TIMING.SEARCH_RENDER);
}

onChangeText(searchValue = '') {
this.setState({searchValue}, this.debouncedUpdateOptions);
}

/**
* Returns the sections needed for the OptionsSelector
*
Expand All @@ -112,6 +120,24 @@ class SearchPage extends Component {
return sections;
}

updateOptions() {
const {
recentReports,
personalDetails,
userToInvite,
} = getSearchOptions(
this.props.reports,
this.props.personalDetails,
this.state.searchValue,
this.props.betas,
);
this.setState({
userToInvite,
recentReports,
personalDetails,
});
}

/**
* Reset the search value and redirect to the selected report
*
Expand Down Expand Up @@ -158,24 +184,7 @@ class SearchPage extends Component {
sections={sections}
value={this.state.searchValue}
onSelectRow={this.selectReport}
onChangeText={(searchValue = '') => {
const {
recentReports,
personalDetails,
userToInvite,
} = getSearchOptions(
this.props.reports,
this.props.personalDetails,
searchValue,
this.props.betas,
);
this.setState({
searchValue,
userToInvite,
recentReports,
personalDetails,
});
}}
onChangeText={this.onChangeText}
headerMessage={headerMessage}
hideSectionHeaders
hideAdditionalOptionStates
Expand Down
5 changes: 4 additions & 1 deletion src/pages/home/sidebar/OptionRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ const OptionRow = ({
const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor;
const isMultipleParticipant = lodashGet(option, 'participantsList.length', 0) > 1;
const displayNamesWithTooltips = _.map(
option.participantsList,

// We only create tooltips for the first 10 users or so since some reports have hundreds of users causing
// performance to degrade.
option.participantsList.slice(0, 10),
({displayName, firstName, login}) => {
const displayNameTrimmed = Str.isSMSLogin(login) ? toLocalPhone(displayName) : displayName;

Expand Down