Created
June 11, 2017 20:51
-
-
Save ghoshabhi/ba0feafdb58535150335f6d847e4f562 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { connect } from 'react-redux'; | |
import { bindActionCreators } from 'redux'; | |
import PropTypes from 'prop-types'; | |
import * as FilterListActions from './actions'; | |
import FilterList from '../../components/FiltersList'; | |
class FilterListContainer extends Component { | |
constructor(props) { | |
super(props); | |
this.handleFilterChange = this.handleFilterChange.bind(this); | |
} | |
handleFilterChange(e) { | |
// console.log(`e: ${e.target.value}`); | |
const { actions, find, near } = this.props; | |
const obj = | |
find.find(o => o.name === e.target.value) || | |
near.find(o => o.name === e.target.value); | |
if (obj) { | |
obj.checked = !obj.checked; | |
if (obj.type === 'find') { | |
const newFindFilter = Object.assign(find, obj); | |
actions.setFindFilter(newFindFilter); | |
} else if (obj.type === 'near') { | |
const newNearFilter = Object.assign(near, obj); | |
actions.setNearFilter(newNearFilter); | |
} else { | |
actions.setError('Error!'); | |
} | |
} else { | |
actions.setError('Error 2!'); | |
} | |
actions.setUserFilter(e.target.value); | |
} | |
render() { | |
return ( | |
<div style={{ width: '300px' }}> | |
{/* {Object.keys(filterListsToRender).map(key => (*/} | |
<FilterList | |
filterTitle="find" | |
filters={this.props.find} | |
onFilterChange={this.handleFilterChange} | |
/> | |
<FilterList | |
filterTitle="near" | |
filters={this.props.near} | |
onFilterChange={this.handleFilterChange} | |
/> | |
{/* ))}*/} | |
</div> | |
); | |
} | |
} | |
FilterListContainer.propTypes = { | |
.... | |
}; | |
const mapStateToProps = state => ({ | |
selectedFilters: state.filterListContainer.selectedFilters, | |
find: state.filterListContainer.find, | |
near: state.filterListContainer.near, | |
}); | |
const mapDispatchToProps = dispatch => ({ | |
actions: bindActionCreators(FilterListActions, dispatch), | |
}); | |
export default connect(mapStateToProps, mapDispatchToProps)( | |
FilterListContainer, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment