From 15dc5ccd08ce323a48edaa53dfcec24b7151e3af Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Tue, 3 Jul 2018 19:34:23 +0200 Subject: client/Search: Refactor --- src/client/react/components/container/Search.js | 27 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/client/react/components/container') 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, }), -- cgit v1.1