-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix Desktop - CMD + K is slow and laggy #3601 #3760
Changes from all commits
2d74cbc
bdc8dad
9b13f15
141592a
2a18f5c
4fe5bbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import _ from 'underscore'; | ||
import React, {Component} from 'react'; | ||
import {View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
|
@@ -65,34 +64,35 @@ 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); | ||
this.searchSections = this.searchSections.bind(this); | ||
this.getCustomHeaderMessage = this.getCustomHeaderMessage.bind(this); | ||
} | ||
|
||
componentDidMount() { | ||
Timing.end(CONST.TIMING.SEARCH_RENDER); | ||
} | ||
|
||
/** | ||
* Returns header message given searchValue | ||
* @param {String} searchValue | ||
* @returns {String} header messae | ||
*/ | ||
getCustomHeaderMessage(searchValue = '') { | ||
const { | ||
recentReports, | ||
personalDetails, | ||
userToInvite, | ||
} = getSearchOptions( | ||
props.reports, | ||
props.personalDetails, | ||
this.props.reports, | ||
this.props.personalDetails, | ||
'', | ||
props.betas, | ||
this.props.betas, | ||
); | ||
return getHeaderMessage( | ||
(recentReports.length + personalDetails.length) !== 0, | ||
Boolean(userToInvite), | ||
searchValue, | ||
); | ||
|
||
this.state = { | ||
searchValue: '', | ||
recentReports, | ||
personalDetails, | ||
userToInvite, | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
Timing.end(CONST.TIMING.SEARCH_RENDER); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The timing isn't getting ended so this will just be an infinite timer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I added it. Sorry for forgetting. |
||
} | ||
|
||
onChangeText(searchValue = '') { | ||
this.setState({searchValue}, this.debouncedUpdateOptions); | ||
} | ||
|
||
/** | ||
|
@@ -101,17 +101,37 @@ class SearchPage extends Component { | |
* @returns {Array} | ||
*/ | ||
getSections() { | ||
// getSections is same to searchSections given empty searchValue | ||
return this.searchSections(); | ||
} | ||
|
||
/** | ||
* Returns the sections needed for the OptionsSelector | ||
* @param {String} searchValue | ||
* @returns {Array} | ||
*/ | ||
searchSections(searchValue = '') { | ||
const { | ||
recentReports, | ||
personalDetails, | ||
userToInvite, | ||
} = getSearchOptions( | ||
this.props.reports, | ||
this.props.personalDetails, | ||
searchValue, | ||
this.props.betas, | ||
); | ||
const sections = [{ | ||
title: this.props.translate('common.recents'), | ||
data: this.state.recentReports.concat(this.state.personalDetails), | ||
data: recentReports.concat(personalDetails), | ||
shouldShow: true, | ||
indexOffset: 0, | ||
}]; | ||
|
||
if (this.state.userToInvite) { | ||
if (userToInvite) { | ||
sections.push(({ | ||
undefined, | ||
data: [this.state.userToInvite], | ||
data: [userToInvite], | ||
shouldShow: true, | ||
indexOffset: 0, | ||
})); | ||
|
@@ -120,24 +140,6 @@ 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 | ||
* | ||
|
@@ -149,11 +151,7 @@ class SearchPage extends Component { | |
} | ||
|
||
if (option.reportID) { | ||
this.setState({ | ||
searchValue: '', | ||
}, () => { | ||
Navigation.navigate(ROUTES.getReportRoute(option.reportID)); | ||
}); | ||
Navigation.navigate(ROUTES.getReportRoute(option.reportID)); | ||
} else { | ||
fetchOrCreateChatReport([ | ||
this.props.session.email, | ||
|
@@ -164,36 +162,32 @@ class SearchPage extends Component { | |
|
||
render() { | ||
const sections = this.getSections(); | ||
const headerMessage = getHeaderMessage( | ||
(this.state.recentReports.length + this.state.personalDetails.length) !== 0, | ||
Boolean(this.state.userToInvite), | ||
this.state.searchValue, | ||
); | ||
return ( | ||
<ScreenWrapper> | ||
{({didScreenTransitionEnd}) => ( | ||
<> | ||
<HeaderWithCloseButton | ||
title={this.props.translate('common.search')} | ||
onCloseButtonPress={() => Navigation.dismissModal(true)} | ||
/> | ||
<View style={[styles.flex1, styles.w100, styles.pRelative]}> | ||
<FullScreenLoadingIndicator visible={!didScreenTransitionEnd} /> | ||
{didScreenTransitionEnd && ( | ||
<OptionsSelector | ||
sections={sections} | ||
value={this.state.searchValue} | ||
onSelectRow={this.selectReport} | ||
onChangeText={this.onChangeText} | ||
headerMessage={headerMessage} | ||
hideSectionHeaders | ||
hideAdditionalOptionStates | ||
showTitleTooltip | ||
didScreenTransitionEnd && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I put |
||
<> | ||
<HeaderWithCloseButton | ||
title={this.props.translate('common.search')} | ||
onCloseButtonPress={() => Navigation.dismissModal(true)} | ||
/> | ||
)} | ||
</View> | ||
<KeyboardSpacer /> | ||
</> | ||
<View style={[styles.flex1, styles.w100, styles.pRelative]}> | ||
<FullScreenLoadingIndicator visible={!didScreenTransitionEnd} /> | ||
{didScreenTransitionEnd && ( | ||
<OptionsSelector | ||
sections={sections} | ||
onSelectRow={this.selectReport} | ||
searchSections={this.searchSections} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This prop needs to be passed to other pages where this component is used. Otherwise, Search will not work there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, do you mean to use this.props.sections? |
||
getCustomHeaderMessage={this.getCustomHeaderMessage} | ||
hideSectionHeaders | ||
hideAdditionalOptionStates | ||
showTitleTooltip | ||
/> | ||
)} | ||
</View> | ||
<KeyboardSpacer /> | ||
</> | ||
) | ||
)} | ||
</ScreenWrapper> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still want the Timing I believe, can we get this added back but maybe put where it belongs now?