From 5ceecc591b8ebd263bce3934c7bb6a73433c2be4 Mon Sep 17 00:00:00 2001 From: hublot Date: Wed, 19 Apr 2023 07:58:57 +0800 Subject: [PATCH 1/3] Fix SearchPage update headerMessage in debounce.updateOptions --- src/pages/SearchPage.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/pages/SearchPage.js b/src/pages/SearchPage.js index 560ec388ef99..28af04e153c9 100755 --- a/src/pages/SearchPage.js +++ b/src/pages/SearchPage.js @@ -70,6 +70,7 @@ class SearchPage extends Component { this.state = { searchValue: '', + headerMessage: '', recentReports, personalDetails, userToInvite, @@ -134,7 +135,13 @@ class SearchPage extends Component { this.state.searchValue.trim(), this.props.betas, ); + const headerMessage = OptionsListUtils.getHeaderMessage( + (recentReports.length + personalDetails.length) !== 0, + Boolean(userToInvite), + this.state.searchValue, + ); this.setState({ + headerMessage, userToInvite, recentReports, personalDetails, @@ -164,11 +171,6 @@ class SearchPage extends Component { render() { const sections = this.getSections(); - const headerMessage = OptionsListUtils.getHeaderMessage( - (this.state.recentReports.length + this.state.personalDetails.length) !== 0, - Boolean(this.state.userToInvite), - this.state.searchValue, - ); return ( {({didScreenTransitionEnd, safeAreaPaddingBottomStyle}) => ( @@ -183,7 +185,7 @@ class SearchPage extends Component { value={this.state.searchValue} onSelectRow={this.selectReport} onChangeText={this.onChangeText} - headerMessage={headerMessage} + headerMessage={this.state.headerMessage} hideSectionHeaders showTitleTooltip shouldShowOptions={didScreenTransitionEnd} From 62a13261bc60186918b6565bf7f09429cc5dbb46 Mon Sep 17 00:00:00 2001 From: hublot Date: Wed, 19 Apr 2023 08:25:41 +0800 Subject: [PATCH 2/3] Fix Lint --- src/pages/SearchPage.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/SearchPage.js b/src/pages/SearchPage.js index 28af04e153c9..298c2f0b605c 100755 --- a/src/pages/SearchPage.js +++ b/src/pages/SearchPage.js @@ -138,6 +138,8 @@ class SearchPage extends Component { const headerMessage = OptionsListUtils.getHeaderMessage( (recentReports.length + personalDetails.length) !== 0, Boolean(userToInvite), + // Ignoring the ESLint checks, accessing `searchValue.trim` above works fine, so accessing searchValue will also work fine + // eslint-disable-next-line react/no-access-state-in-setstate this.state.searchValue, ); this.setState({ From e59e2d08a2f06e66f6eb743a42d9f50ee5c56ecf Mon Sep 17 00:00:00 2001 From: hublot Date: Wed, 19 Apr 2023 08:30:36 +0800 Subject: [PATCH 3/3] Modify Lint Check to prevState --- src/pages/SearchPage.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pages/SearchPage.js b/src/pages/SearchPage.js index 298c2f0b605c..457d915aa9b1 100755 --- a/src/pages/SearchPage.js +++ b/src/pages/SearchPage.js @@ -135,18 +135,18 @@ class SearchPage extends Component { this.state.searchValue.trim(), this.props.betas, ); - const headerMessage = OptionsListUtils.getHeaderMessage( - (recentReports.length + personalDetails.length) !== 0, - Boolean(userToInvite), - // Ignoring the ESLint checks, accessing `searchValue.trim` above works fine, so accessing searchValue will also work fine - // eslint-disable-next-line react/no-access-state-in-setstate - this.state.searchValue, - ); - this.setState({ - headerMessage, - userToInvite, - recentReports, - personalDetails, + this.setState((prevState) => { + const headerMessage = OptionsListUtils.getHeaderMessage( + (recentReports.length + personalDetails.length) !== 0, + Boolean(userToInvite), + prevState.searchValue, + ); + return ({ + headerMessage, + userToInvite, + recentReports, + personalDetails, + }); }); }