Merge branch 'master' into redirect-to-all

This commit is contained in:
Kiwi
2017-06-23 18:18:18 +07:00
committed by GitHub
2 changed files with 26 additions and 7 deletions
@@ -81,7 +81,7 @@ const StorySearch = (props) => {
</div>
</div>
</div>
<div className={styles.overlay} onClick={props.closeSearch} />
<div className={styles.overlay} onClick={props.clearAndCloseSearch} />
</div>
);
};
@@ -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
@@ -3,6 +3,7 @@ import {compose, gql} from 'react-apollo';
import StorySearch from '../components/StorySearch';
import {withRouter} from 'react-router';
import withQuery from 'coral-framework/hocs/withQuery';
import {isEmpty} from 'lodash';
class StorySearchContainer extends React.Component {
constructor(props) {
@@ -13,6 +14,23 @@ class StorySearchContainer extends React.Component {
};
}
componentWillUnmount() {
this.props.storySearchChange('');
}
clearSearch = () => {
this.setState({searchValue: ''}, () => {
this.search();
});
}
clearAndCloseSearch = () => {
if (!isEmpty(this.state.searchValue)) {
this.clearSearch();
}
this.props.closeSearch();
}
handleSearchChange = (e) => {
const {value} = e.target;
this.setState({
@@ -23,7 +41,7 @@ class StorySearchContainer extends React.Component {
handleEsc = (e) => {
if (e.key === 'Escape') {
e.preventDefault();
this.props.closeSearch();
this.clearAndCloseSearch();
}
}
@@ -40,15 +58,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 +79,7 @@ class StorySearchContainer extends React.Component {
handleEnter={this.handleEnter}
searchValue={this.state.searchValue}
handleSearchChange={this.handleSearchChange}
clearAndCloseSearch={this.clearAndCloseSearch}
{...this.props}
/>
);