diff --git a/src/containers/BuildingList/actions.js b/src/containers/BuildingList/actions.js
index 4803d06cc806edcf963ac17292d538635f87b1e5..0768281f8540058dca500bfc6b709130e1ad7e44 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 0cb538df646d5aab40bbd2b2c04bc40b3f43b325..a445948ac2d92cf49c138104843920453e7b5c3f 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 e32e7ae5e8f0a8b1965404d600a948154ea48bb9..a06bf3c16044b56d4f4ce03cdd850582d44ed8bf 100644
--- a/src/containers/BuildingList/index.js
+++ b/src/containers/BuildingList/index.js
@@ -2,17 +2,20 @@
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';
import { SearchSVG } from '../../components/bpl';
+// 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 +30,11 @@ class BuildingList extends Component {
onFormSubmit(event) {
event.preventDefault();
-
this.getBuildings();
}
getBuildings() {
+ this.props.searchTerm(this.state.term);
this.props.fetchBuildings(this.state.term);
}
@@ -99,29 +102,35 @@ class BuildingList extends Component {
-
+
);
}
}
BuildingList.propTypes = {
- buildings: 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,
+ })
+ ),
+ term: PropTypes.string,
+ }),
fetchBuildings: PropTypes.func,
+ searchTerm: PropTypes.func,
};
function mapDispatchToProps(dispatch) {
- return bindActionCreators({ fetchBuildings }, dispatch);
+ return bindActionCreators({ fetchBuildings, searchTerm }, dispatch);
}
-function mapStateToProps({ buildings }) {
- return { buildings };
+function mapStateToProps({ buildingList }) {
+ return { buildingList };
}
export default connect(mapStateToProps, mapDispatchToProps)(BuildingList);
diff --git a/src/containers/BuildingList/reducer.js b/src/containers/BuildingList/reducer.js
index 82c2717cf80d1494e41996842de6f2ce89fb2fee..6c804205b1a62101965efb48e8b8e2c9695de06d 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) {
+export default function (state = {}, action) {
switch (action.type) {
case FETCH_BUILDINGS:
- return action.payload.data;
+ return { ...state, buildings: action.payload.data };
+ case SEARCH_TERM:
+ return { ...state, term: action.payload };
default:
return state;
diff --git a/src/reducer.js b/src/reducer.js
index 6ff138c529117de29f82c5b06bfcc74a1829dfe0..af7f5c9bc2e0136f0d58a670692dad81c301be83 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,
});