-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
353 additions
and
229 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import debounce from 'lodash-es/debounce'; | ||
|
||
import BaseComponent from '../baseComponent/index'; | ||
|
||
const filterTitleStyle = { | ||
marginBottom: '8px', | ||
fontSize: '20px', | ||
fontWeight: 700 | ||
} | ||
|
||
const labelStyle = { | ||
marginRight: '16px' | ||
} | ||
|
||
const labelTitleStyle = { | ||
marginRight: '8px' | ||
} | ||
|
||
const inuputStyle ={ | ||
width: '6em' | ||
} | ||
|
||
class PriceFilter extends BaseComponent { | ||
constructor(props) { | ||
super(props); | ||
this.handleControlChange = debounce(this.handleControlChange.bind(this), 500) | ||
} | ||
|
||
handleControlChange(filterName, value) { | ||
this.props.onChangeFilter(filterName, value); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<div style={ filterTitleStyle }> | ||
<span>Цена</span> | ||
</div> | ||
<div> | ||
<label style={ labelStyle }> | ||
<span style={ labelTitleStyle }>От:</span> | ||
<input style={ inuputStyle } | ||
type="text" | ||
defaultValue={ this.props.minPrice } | ||
onChange={(event)=> this.handleControlChange('minPrice', parseInt(event.target.value, 10))}/> | ||
</label> | ||
|
||
<label style={ labelStyle }> | ||
<span style={ labelTitleStyle }>До:</span> | ||
<input style={ inuputStyle } | ||
type="text" | ||
defaultValue={ this.props.maxPrice } | ||
onChange={(event)=> this.handleControlChange('maxPrice', parseInt(event.target.value, 10))}/> | ||
</label> | ||
</div> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
PriceFilter.propTypes = { | ||
onChangeFilter: PropTypes.func, | ||
minPrice: PropTypes.number, | ||
maxPrice: PropTypes.number | ||
} | ||
export default PriceFilter |
File renamed without changes.
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
import { bindActionCreators } from 'redux' | ||
import { connect } from 'react-redux' | ||
|
||
import BaseComponent from '../../components/baseComponent/index'; | ||
import PriceFilter from '../../components/priceFilter/index'; | ||
import { productsSelector } from '../../store/selectors'; | ||
import { setFilter } from '../../store/actionCreators'; | ||
|
||
const filtersContainerStyle = { | ||
padding: '4px 16px' | ||
} | ||
|
||
class UserFilters extends BaseComponent { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.handleFilterChange = this.handleFilterChange.bind(this); | ||
this.state = { | ||
defaultFilters: { | ||
minPrice: this.props.products.reduce((accum, product) => { | ||
if (accum === 0 && product.price > 0) { | ||
return product.price; | ||
} | ||
|
||
return accum > product.price ? product.price : accum; | ||
}, 0), | ||
maxPrice: this.props.products.reduce((accum, product) => | ||
accum < product.price ? product.price : accum | ||
, 0) | ||
} | ||
} | ||
} | ||
|
||
handleFilterChange(filterName, value) { | ||
this.props.setFilter(filterName, value); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div style={ filtersContainerStyle }> | ||
<PriceFilter | ||
minPrice = { this.state.defaultFilters.minPrice } | ||
maxPrice = { this.state.defaultFilters.maxPrice } | ||
onChangeFilter={ this.handleFilterChange } | ||
/> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
const mapDispatchToProps = (dispatch) => { | ||
return { | ||
setFilter: bindActionCreators(setFilter, dispatch) | ||
} | ||
} | ||
|
||
const mapStateToProps = function(state) { | ||
return { | ||
products: productsSelector(state) | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(UserFilters); | ||
|
Oops, something went wrong.