blob: 05c743b1a831c3c35685f329d6576a3253dfccd1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import { h, Component } from 'preact'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import * as audioPlayerActions from './audioPlayer.actions'
class AudioPlayer extends Component {
constructor(props){
super(props)
this.handleClick = this.handleClick.bind(this)
}
handleClick(e){
const { audioPlayer, actions } = this.props
if (audioPlayer.playing) {
actions.pause()
} else {
actions.resume()
}
}
render() {
const { audioPlayer } = this.props
return (
<div className='audioPlayer'>
<span>{this.props.title}</span>
<button
onClick={this.handleClick}
>
{audioPlayer.playing ? '▶' : '~'}
</button>
</div>
)
}
}
const mapStateToProps = state => ({
audioPlayer: state.audioPlayer,
})
const mapDispatchToProps = (dispatch, ownProps) => ({
actions: bindActionCreators(audioPlayerActions, dispatch),
})
export default connect(mapStateToProps, mapDispatchToProps)(AudioPlayer)
|