diff --git a/js/components/Balance.jsx b/js/components/Balance.jsx index 46c85f0f..4051e1fa 100644 --- a/js/components/Balance.jsx +++ b/js/components/Balance.jsx @@ -4,48 +4,34 @@ import {connect} from 'react-redux'; import {setBalance} from '../actionCreators'; import {SET_FOCUS, UNSET_FOCUS} from '../actionTypes'; -class Balance extends React.Component { - constructor(props) { - super(props); - this.setBalance = this.setBalance.bind(this); - this.showMarquee = this.showMarquee.bind(this); - this.hideMarquee = this.hideMarquee.bind(this); - } +const offsetFromBalance = (balance) => { + const percent = Math.abs(balance) / 100; + const sprite = Math.round(percent * 28); + const offset = (sprite - 1) * 15; + return offset; +}; - setBalance(e) { - this.props.dispatch(setBalance(e.target.value)); - } +const Balance = ({balance, handleChange, showMarquee, hideMarquee}) => ( + +); - showMarquee() { - this.props.dispatch({type: SET_FOCUS, input: 'balance'}); - } +const mapStateToProps = (state) => state.media; - hideMarquee() { - this.props.dispatch({type: UNSET_FOCUS}); - } +const mapDispatchToProps = (dispatch) => ({ + handleChange: (e) => dispatch(setBalance(e.target.value)), + showMarquee: () => dispatch({type: SET_FOCUS, input: 'balance'}), + hideMarquee: () => dispatch({type: UNSET_FOCUS}) +}); - render() { - const balance = Math.abs(this.props.balance) / 100; - const sprite = Math.round(balance * 28); - const offset = (sprite - 1) * 15; - - const style = { - backgroundPosition: `0 -${offset}px` - }; - - return ; - } -} - -module.exports = connect((state) => state.media)(Balance); +module.exports = connect(mapStateToProps, mapDispatchToProps)(Balance);