diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-02-04 11:36:44 +0100 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-02-04 11:36:44 +0100 |
commit | c325916e381d6ac13fcc840b2d4baa87913a3184 (patch) | |
tree | 398b7c274f6d41db28d331d5925d12acf8701ca6 /src/client/react/components | |
parent | 77f5b8fbe87ce992c46ee5513eaa25c7a7f129ec (diff) |
Reimplement isExactMatch to compair against the url user.
Diffstat (limited to 'src/client/react/components')
-rw-r--r-- | src/client/react/components/container/Results.js | 11 | ||||
-rw-r--r-- | src/client/react/components/container/Search.js | 12 |
2 files changed, 16 insertions, 7 deletions
diff --git a/src/client/react/components/container/Results.js b/src/client/react/components/container/Results.js index 68a090b..f65c0c8 100644 --- a/src/client/react/components/container/Results.js +++ b/src/client/react/components/container/Results.js @@ -4,13 +4,14 @@ import classnames from 'classnames'; import { connect } from 'react-redux'; import { withRouter } from 'react-router-dom'; +import users from '../../users'; import { setUser } from '../../actions/search'; import { userFromMatch } from '../../lib/url'; import Result from '../presentational/Result'; const Results = ({ results, - isExactMatch, + searchText, selectedResult, match, history, @@ -18,6 +19,10 @@ const Results = ({ }) => { const user = userFromMatch(match); + const isExactMatch = + user != null && + searchText === users.byId[user].value; + return ( <div className={classnames('search__results', { @@ -50,7 +55,7 @@ const Results = ({ Results.propTypes = { results: PropTypes.arrayOf(PropTypes.string).isRequired, - isExactMatch: PropTypes.bool.isRequired, + searchText: PropTypes.string.isRequired, selectedResult: PropTypes.string, // react-router @@ -67,7 +72,7 @@ Results.defaultProps = { const mapStateToProps = state => ({ results: state.search.results, - isExactMatch: state.search.isExactMatch, + searchText: state.search.searchText, selectedResult: state.search.selectedResult, }); diff --git a/src/client/react/components/container/Search.js b/src/client/react/components/container/Search.js index b42699f..32996e3 100644 --- a/src/client/react/components/container/Search.js +++ b/src/client/react/components/container/Search.js @@ -82,9 +82,8 @@ class Search extends React.Component { render() { const { - selectedResult, - isExactMatch, searchText, + match, dispatch, } = this.props; @@ -92,13 +91,19 @@ class Search extends React.Component { hasFocus, } = this.state; + const urlUser = userFromMatch(match); + + const isExactMatch = + urlUser != null && + searchText === users.byId[urlUser].value; + return ( <div className="search"> <div className={classnames('search-overflow', { 'search--has-focus': hasFocus })}> <div className="search__input-wrapper"> <div className="search__icon-wrapper"> <IconFromUserType - userType={isExactMatch ? users.byId[selectedResult].type : null} + userType={isExactMatch ? users.byId[urlUser].type : null} defaultIcon={<SearchIcon />} /> </div> @@ -123,7 +128,6 @@ class Search extends React.Component { Search.propTypes = { results: PropTypes.arrayOf(PropTypes.string).isRequired, selectedResult: PropTypes.string, - isExactMatch: PropTypes.bool.isRequired, searchText: PropTypes.string.isRequired, // react-router |