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 --- package.json | 1 + src/client/react/App.js | 9 +- src/client/react/actions.js | 5 + src/client/react/components/container/Search.js | 20 +++ .../react/components/presentational/Search.js | 6 +- src/client/react/reducers.js | 15 ++- webpack.config.js | 12 +- yarn.lock | 144 +++++++++++++++++++++ 8 files changed, 195 insertions(+), 17 deletions(-) create mode 100644 src/client/react/components/container/Search.js diff --git a/package.json b/package.json index 5b09abd..21f900a 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "babel-loader": "^7.1.2", "babel-preset-react": "^6.24.1", + "babel-preset-stage-2": "^6.24.1", "bluebird": "^3.4.6", "body-parser": "^1.16.0", "browser-request": "^0.3.3", 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 }) => (