From acb79a563015d9b54ce3b0bbd40ba7c4fd2d5e59 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 9 Jan 2017 20:24:28 -0500 Subject: [PATCH 1/3] Rename buildings to buildingList in store --- src/containers/BuildingList/index.js | 8 ++++---- src/reducer.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/containers/BuildingList/index.js b/src/containers/BuildingList/index.js index d8d33cfc..a0ead7cf 100644 --- a/src/containers/BuildingList/index.js +++ b/src/containers/BuildingList/index.js @@ -53,14 +53,14 @@ class BuildingList extends Component { - + ); } } BuildingList.propTypes = { - buildings: PropTypes.arrayOf(PropTypes.shape({ + buildingList: PropTypes.arrayOf(PropTypes.shape({ address: PropTypes.string, bbl: PropTypes.number, blocpower_id: PropTypes.number, @@ -74,8 +74,8 @@ function mapDispatchToProps(dispatch) { return bindActionCreators({ fetchBuildings }, dispatch); } -function mapStateToProps({ buildings }) { - return { buildings }; +function mapStateToProps({ buildingList }) { + return { buildingList }; } export default connect(mapStateToProps, mapDispatchToProps)(BuildingList); diff --git a/src/reducer.js b/src/reducer.js index 6ff138c5..af7f5c9b 100644 --- a/src/reducer.js +++ b/src/reducer.js @@ -6,7 +6,7 @@ import BuildingDetailReducer from './containers/BuildingDetail/reducer'; const rootReducer = combineReducers({ routing: routerReducer, - buildings: BuildingListReducer, + buildingList: BuildingListReducer, buildingDetail: BuildingDetailReducer, }); -- GitLab From abe77a6a5d4d97f7ae9e0819df996d29494c464a Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 9 Jan 2017 20:33:19 -0500 Subject: [PATCH 2/3] Refactor buildingList state into object --- src/containers/BuildingList/index.js | 20 ++++++++++++-------- src/containers/BuildingList/reducer.js | 4 ++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/containers/BuildingList/index.js b/src/containers/BuildingList/index.js index a0ead7cf..e638d7e9 100644 --- a/src/containers/BuildingList/index.js +++ b/src/containers/BuildingList/index.js @@ -53,20 +53,24 @@ class BuildingList extends Component { - + ); } } BuildingList.propTypes = { - buildingList: PropTypes.arrayOf(PropTypes.shape({ - address: PropTypes.string, - bbl: PropTypes.number, - blocpower_id: PropTypes.number, - borough: PropTypes.string, - zipcode: PropTypes.number, - })), + buildingList: PropTypes.shape({ + buildings: PropTypes.arrayOf( + PropTypes.shape({ + address: PropTypes.string, + bbl: PropTypes.number, + blocpower_id: PropTypes.number, + borough: PropTypes.string, + zipcode: PropTypes.number, + }) + ), + }), fetchBuildings: PropTypes.func, }; diff --git a/src/containers/BuildingList/reducer.js b/src/containers/BuildingList/reducer.js index 82c2717c..dac428f7 100644 --- a/src/containers/BuildingList/reducer.js +++ b/src/containers/BuildingList/reducer.js @@ -1,9 +1,9 @@ import { FETCH_BUILDINGS } from './constants'; -export default function (state = [], action) { +export default function (state = {}, action) { switch (action.type) { case FETCH_BUILDINGS: - return action.payload.data; + return { ...state, buildings: action.payload.data }; default: return state; -- GitLab From 5715b2929c33dc2233b7b4a390967b60f7988bfc Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Tue, 10 Jan 2017 11:32:02 -0500 Subject: [PATCH 3/3] Add search term to redux --- src/containers/BuildingList/actions.js | 13 +++++++++---- src/containers/BuildingList/constants.js | 3 +-- src/containers/BuildingList/index.js | 13 ++++++++----- src/containers/BuildingList/reducer.js | 4 +++- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/containers/BuildingList/actions.js b/src/containers/BuildingList/actions.js index 4803d06c..0768281f 100644 --- a/src/containers/BuildingList/actions.js +++ b/src/containers/BuildingList/actions.js @@ -1,5 +1,5 @@ import 'whatwg-fetch'; -import { FETCH_BUILDINGS } from './constants'; +import { FETCH_BUILDINGS, SEARCH_TERM } from './constants'; const ROOT_URL = `${process.env.REACT_APP_BUILDING_SERVICE}/building/`; const HEADERS = new Headers({ 'x-blocpower-app-key': process.env.REACT_APP_KEY }); @@ -21,6 +21,11 @@ function fetchBuildings(address) { }; } -/* eslint-disable import/prefer-default-export */ -export { fetchBuildings }; -/* eslint-enable */ +function searchTerm(address) { + return { + type: SEARCH_TERM, + payload: address, + }; +} + +export { fetchBuildings, searchTerm }; diff --git a/src/containers/BuildingList/constants.js b/src/containers/BuildingList/constants.js index 0cb538df..a445948a 100644 --- a/src/containers/BuildingList/constants.js +++ b/src/containers/BuildingList/constants.js @@ -1,3 +1,2 @@ -/* eslint-disable import/prefer-default-export */ export const FETCH_BUILDINGS = 'FETCH_BUILDINGS'; -/* eslint-enable */ +export const SEARCH_TERM = 'SEARCH_TERM'; diff --git a/src/containers/BuildingList/index.js b/src/containers/BuildingList/index.js index e638d7e9..3c61061e 100644 --- a/src/containers/BuildingList/index.js +++ b/src/containers/BuildingList/index.js @@ -2,17 +2,18 @@ import React, { Component, PropTypes } from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; -import { fetchBuildings } from './actions'; +import { fetchBuildings, searchTerm } from './actions'; import BuildingListTable from '../../components/BuildingListTable'; import './styles.css'; +// TODO remove this address +const INITIAL_TERM = '107 broadway'; class BuildingList extends Component { constructor(props) { super(props); - this.state = { term: '107 broadway' }; - + this.state = { term: INITIAL_TERM }; this.onInputChange = this.onInputChange.bind(this); this.onFormSubmit = this.onFormSubmit.bind(this); } @@ -27,11 +28,11 @@ class BuildingList extends Component { onFormSubmit(event) { event.preventDefault(); - this.getBuildings(); } getBuildings() { + this.props.searchTerm(this.state.term); this.props.fetchBuildings(this.state.term); } @@ -70,12 +71,14 @@ BuildingList.propTypes = { zipcode: PropTypes.number, }) ), + term: PropTypes.string, }), fetchBuildings: PropTypes.func, + searchTerm: PropTypes.func, }; function mapDispatchToProps(dispatch) { - return bindActionCreators({ fetchBuildings }, dispatch); + return bindActionCreators({ fetchBuildings, searchTerm }, dispatch); } function mapStateToProps({ buildingList }) { diff --git a/src/containers/BuildingList/reducer.js b/src/containers/BuildingList/reducer.js index dac428f7..6c804205 100644 --- a/src/containers/BuildingList/reducer.js +++ b/src/containers/BuildingList/reducer.js @@ -1,9 +1,11 @@ -import { FETCH_BUILDINGS } from './constants'; +import { FETCH_BUILDINGS, SEARCH_TERM } from './constants'; export default function (state = {}, action) { switch (action.type) { case FETCH_BUILDINGS: return { ...state, buildings: action.payload.data }; + case SEARCH_TERM: + return { ...state, term: action.payload }; default: return state; -- GitLab