From 4ce420528dd747021f7fa51483710388f5733724 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sun, 10 Dec 2017 01:01:36 +0100 Subject: Add Search container --- src/client/react/App.js | 9 ++------- src/client/react/actions.js | 5 +++++ src/client/react/components/container/Search.js | 20 ++++++++++++++++++++ src/client/react/components/presentational/Search.js | 6 +++--- src/client/react/reducers.js | 15 ++++++++++++++- 5 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 src/client/react/components/container/Search.js (limited to 'src/client') diff --git a/src/client/react/App.js b/src/client/react/App.js index b8bb301..d79826e 100644 --- a/src/client/react/App.js +++ b/src/client/react/App.js @@ -1,14 +1,9 @@ import React from 'react'; -import Search from './components/presentational/Search'; +import Search from './components/container/Search'; const App = () => (
- {}} - results={[ - { type: 's', name: '18561' }, - ]} - /> +
); diff --git a/src/client/react/actions.js b/src/client/react/actions.js index e69de29..a754943 100644 --- a/src/client/react/actions.js +++ b/src/client/react/actions.js @@ -0,0 +1,5 @@ +// eslint-disable-next-line import/prefer-default-export +export const type = typedValue => ({ + type: 'TYPE', + typedValue, +}); diff --git a/src/client/react/components/container/Search.js b/src/client/react/components/container/Search.js new file mode 100644 index 0000000..1b5a41d --- /dev/null +++ b/src/client/react/components/container/Search.js @@ -0,0 +1,20 @@ +import { connect } from 'react-redux'; +import { type } from '../../actions'; +import PresentationalSearch from '../presentational/Search'; + +const mapStateToProps = state => ({ + results: state.searchResults, +}); + +const mapDispatchToProps = dispatch => ({ + onType: (event) => { + dispatch(type(event.target.value)); + }, +}); + +const Search = connect( + mapStateToProps, + mapDispatchToProps, +)(PresentationalSearch); + +export default Search; diff --git a/src/client/react/components/presentational/Search.js b/src/client/react/components/presentational/Search.js index 0dde8a6..ce4a09d 100644 --- a/src/client/react/components/presentational/Search.js +++ b/src/client/react/components/presentational/Search.js @@ -1,10 +1,10 @@ import React from 'react'; import PropTypes from 'prop-types'; -const Search = ({ onInput, results }) => ( +const Search = ({ onType, results }) => (