mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-21 17:18:52 +00:00
Convert Time to mapDispatchToProps
This commit is contained in:
parent
7ecea310c7
commit
946537edf7
1 changed files with 19 additions and 23 deletions
|
|
@ -3,28 +3,24 @@ import {connect} from 'react-redux';
|
|||
|
||||
import {getTimeObj} from '../utils';
|
||||
|
||||
class Time extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.toggleTimeMode = this.toggleTimeMode.bind(this);
|
||||
}
|
||||
toggleTimeMode() {
|
||||
this.props.dispatch({type: 'TOGGLE_TIME_MODE'});
|
||||
}
|
||||
render() {
|
||||
const seconds = this.props.timeMode === 'ELAPSED' ?
|
||||
this.props.timeElapsed :
|
||||
this.props.length - this.props.timeElapsed;
|
||||
const Time = ({timeElapsed, length, timeMode, toggleTimeMode}) => {
|
||||
const seconds = timeMode === 'ELAPSED' ?
|
||||
timeElapsed :
|
||||
length - timeElapsed;
|
||||
|
||||
const timeObj = getTimeObj(seconds);
|
||||
return <div id='time' onClick={this.toggleTimeMode} className='countdown'>
|
||||
{this.props.timeMode === 'REMAINING' && <div id='minus-sign' />}
|
||||
<div id='minute-first-digit' className={`digit digit-${timeObj.minutesFirstDigit}`} />
|
||||
<div id='minute-second-digit' className={`digit digit-${timeObj.minutesSecondDigit}`} />
|
||||
<div id='second-first-digit' className={`digit digit-${timeObj.secondsFirstDigit}`} />
|
||||
<div id='second-second-digit' className={`digit digit-${timeObj.secondsSecondDigit}`} />
|
||||
</div>;
|
||||
}
|
||||
}
|
||||
const timeObj = getTimeObj(seconds);
|
||||
return <div id='time' onClick={toggleTimeMode} className='countdown'>
|
||||
{timeMode === 'REMAINING' && <div id='minus-sign' />}
|
||||
<div id='minute-first-digit' className={`digit digit-${timeObj.minutesFirstDigit}`} />
|
||||
<div id='minute-second-digit' className={`digit digit-${timeObj.minutesSecondDigit}`} />
|
||||
<div id='second-first-digit' className={`digit digit-${timeObj.secondsFirstDigit}`} />
|
||||
<div id='second-second-digit' className={`digit digit-${timeObj.secondsSecondDigit}`} />
|
||||
</div>;
|
||||
};
|
||||
|
||||
module.exports = connect((state) => state.media)(Time);
|
||||
const mapStateToProps = (state) => state.media;
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
toggleTimeMode: () => dispatch({type: 'TOGGLE_TIME_MODE'})
|
||||
});
|
||||
|
||||
module.exports = connect(mapStateToProps, mapDispatchToProps)(Time);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue