constructor(props){
super(props);
this.state = {
flag: true,
audio: ''
}
}
componentDidMount() {
this.setState({audio: document.getElementById('audio-player')})
}
import React from 'react'
import { connect } from 'react-redux'
import { play, pause } from '../actions/Pauseplay.js'
class Player extends React.Component {
constructor(props){
super(props);
this.state = {
flag: true
}
}
handleClick = () => {
this.setState({flag: !this.state.flag})
}
render() {
let audio = new Audio('data/CrooksUK-AFewPeacefulDays.mp3')
if (this.props.status) {
audio.play()
}
if (this.props.status == false) {
audio.pause()
}
return (<div className = "player_icons">
<i className = "fa fa-step-backward fa-2x" aria-hidden = "true"></i>
<div onClick = {this.handleClick}>
{this.state.flag ? (<i className = "fa fa-play fa-2x" onClick = {this.props.play} aria-hidden = "true"></i>)
:(<i className = "fa fa-pause fa-2x" onClick = {this.props.pause} aria-hidden = "true"></i>)}
</div>
<i className = "fa fa-step-forward fa-2x" aria-hidden = "true"></i>
</div>
)
}
}
function mapStateToProps(state) {
return {
status: state.music.isPlaying
}
}
export default connect(mapStateToProps, { play, pause })(Player)
function mapStateToProps(state){
return {
user: state.user
}
}
export default connect(mapStateToProps)(Musicform)
import rootReducer from './rootReducer'
const store = createStore(rootReducer, composeWithDevTools(applyMiddleware(thunk)))
class App extends React.Component {
render() {
return <div>
<Menu />
<Main />
</div>
}
}
render(
<Provider store = {store}>
<BrowserRouter>
<App />
</BrowserRouter>
</Provider>,
window.document.getElementById('root'));
import { combineReducers } from 'redux'
import user from './reducers/user.js'
export default combineReducers({
user
});
import USER_LOGGED_IN from '../types/types.js'
export default function user(state = {}, action = {}) {
switch (action.type) {
case USER_LOGGED_IN:
return action.user;
default:
return state;
}
}