From bba4474858b136e9296a83cb441f98e2dc67a18a Mon Sep 17 00:00:00 2001 From: A Lawliet Date: Thu, 22 Jun 2017 01:51:06 -0400 Subject: [PATCH] Search dropdown: clear search when closed --- .../Moderation/components/StorySearch.js | 4 +-- .../Moderation/containers/StorySearch.js | 26 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/client/coral-admin/src/routes/Moderation/components/StorySearch.js b/client/coral-admin/src/routes/Moderation/components/StorySearch.js index 5fe82fa97..b58940ea7 100644 --- a/client/coral-admin/src/routes/Moderation/components/StorySearch.js +++ b/client/coral-admin/src/routes/Moderation/components/StorySearch.js @@ -81,7 +81,7 @@ const StorySearch = (props) => { -
+
); }; @@ -89,7 +89,7 @@ const StorySearch = (props) => { StorySearch.propTypes = { search: PropTypes.func.isRequired, goToStory: PropTypes.func.isRequired, - closeSearch: PropTypes.func.isRequired, + clearAndCloseSearch: PropTypes.func.isRequired, moderation: PropTypes.object.isRequired, handleSearchChange: PropTypes.func.isRequired, assetId: PropTypes.string diff --git a/client/coral-admin/src/routes/Moderation/containers/StorySearch.js b/client/coral-admin/src/routes/Moderation/containers/StorySearch.js index f4ab6f23e..d9c3b2ef1 100644 --- a/client/coral-admin/src/routes/Moderation/containers/StorySearch.js +++ b/client/coral-admin/src/routes/Moderation/containers/StorySearch.js @@ -13,6 +13,21 @@ class StorySearchContainer extends React.Component { }; } + componentWillUnmount() { + this.props.storySearchChange(''); + } + + clearSearch = () => { + this.setState({searchValue: ''}, () => { + this.search(); + }); + } + + clearAndCloseSearch = () => { + this.clearSearch(); + this.props.closeSearch(); + } + handleSearchChange = (e) => { const {value} = e.target; this.setState({ @@ -23,7 +38,7 @@ class StorySearchContainer extends React.Component { handleEsc = (e) => { if (e.key === 'Escape') { e.preventDefault(); - this.props.closeSearch(); + this.clearAndCloseSearch(); } } @@ -40,15 +55,15 @@ class StorySearchContainer extends React.Component { } goToStory = (id) => { - const {router, closeSearch} = this.props; + const {router} = this.props; router.push(`/admin/moderate/all/${id}`); - closeSearch(); + this.clearAndCloseSearch(); } goToModerateAll = () => { - const {router, closeSearch} = this.props; + const {router} = this.props; router.push('/admin/moderate/all'); - closeSearch(); + this.clearAndCloseSearch(); } render () { @@ -61,6 +76,7 @@ class StorySearchContainer extends React.Component { handleEnter={this.handleEnter} searchValue={this.state.searchValue} handleSearchChange={this.handleSearchChange} + clearAndCloseSearch={this.clearAndCloseSearch} {...this.props} /> );