diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-07-03 19:34:23 +0200 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-07-03 20:13:51 +0200 |
commit | 15dc5ccd08ce323a48edaa53dfcec24b7151e3af (patch) | |
tree | 98ca0a20606f05eef12fc63f317baa520701769a /src/client/react/components/container | |
parent | 5451dc2f5a09fa06df32d1a1661623b475170566 (diff) |
client/Search: Refactor
Diffstat (limited to 'src/client/react/components/container')
-rw-r--r-- | src/client/react/components/container/Search.js | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/client/react/components/container/Search.js b/src/client/react/components/container/Search.js index 8308d67..b680fc6 100644 --- a/src/client/react/components/container/Search.js +++ b/src/client/react/components/container/Search.js @@ -18,24 +18,35 @@ * */ + import { connect } from 'react-redux'; import { withRouter } from 'react-router-dom'; import Search from '../presentational/Search'; -import { setUser } from '../../store/actions'; +import { setUser as setUserAction } from '../../store/actions'; +import { userFromLocation } from '../../lib/url'; +import users from '../../users'; -const mapStateToProps = state => ({ - results: state.search.results, - searchText: state.search.text, - selectedResult: state.search.selected, -}); +const mapStateToProps = (state, { location }) => { + const currentUser = userFromLocation(location); + const searchText = state.search.text; + const isExactMatch = currentUser != null && searchText === users.byId[currentUser].value; + + return { + currentUser, + isExactMatch, + selectedUser: state.search.selected, + results: state.search.results, + searchText: state.search.text, + }; +}; const mapDispatchToProps = dispatch => ({ - setUser: user => dispatch(setUser(user)), + setUser: user => dispatch(setUserAction(user)), onInputChange: searchText => dispatch({ type: 'SEARCH/INPUT_CHANGE', searchText, }), - changeSelectedResult: relativeChange => dispatch({ + changeSelectedUser: relativeChange => dispatch({ type: 'SEARCH/CHANGE_SELECTED_RESULT', relativeChange, }), |