From 91c47c22f2c71c524fd665f19186bb014c94ab31 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 4 Jun 2018 04:50:27 +0200 Subject: audioplayer you can toggle --- app/client/common/audioPlayer.component.js | 38 ------------------- .../common/audioPlayer/audioPlayer.actions.js | 15 ++++++++ .../common/audioPlayer/audioPlayer.component.js | 42 +++++++++++++++++++++ .../common/audioPlayer/audioPlayer.reducer.js | 44 ++++++++++++++++++++++ app/client/common/fileList.component.js | 6 +-- 5 files changed, 104 insertions(+), 41 deletions(-) delete mode 100644 app/client/common/audioPlayer.component.js create mode 100644 app/client/common/audioPlayer/audioPlayer.actions.js create mode 100644 app/client/common/audioPlayer/audioPlayer.component.js create mode 100644 app/client/common/audioPlayer/audioPlayer.reducer.js (limited to 'app/client/common') diff --git a/app/client/common/audioPlayer.component.js b/app/client/common/audioPlayer.component.js deleted file mode 100644 index f10a505..0000000 --- a/app/client/common/audioPlayer.component.js +++ /dev/null @@ -1,38 +0,0 @@ -import { h, Component } from 'preact' -import { connect } from 'react-redux' -import { bindActionCreators } from 'redux' -import * as liveActions from '../live/live.actions' - -const audio = document.createElement('audio') - -class AudioPlayer extends Component { - constructor(props){ - super(props) - this.handleClick = this.handleClick.bind(this) - } - handleClick(e){ - this.props.onClick && this.props.onClick() - } - render() { - const { player={} } = this.props - return ( -
- {this.props.title} - -
- ) - } -} - -const mapStateToProps = state => ({ - player: state.audioPlayer, -}) - -const mapDispatchToProps = (dispatch, ownProps) => ({ -}) - -export default connect(mapStateToProps, mapDispatchToProps)(AudioPlayer) diff --git a/app/client/common/audioPlayer/audioPlayer.actions.js b/app/client/common/audioPlayer/audioPlayer.actions.js new file mode 100644 index 0000000..3d3ea10 --- /dev/null +++ b/app/client/common/audioPlayer/audioPlayer.actions.js @@ -0,0 +1,15 @@ + +import types from '../../types' + +export const play = (file) => { + return { type: types.audioPlayer.play, file } +} +export const pause = () => { + return { type: types.audioPlayer.pause } +} +export const resume = () => { + return { type: types.audioPlayer.resume } +} +export const enqueue = (file) => { + return { type: types.audioPlayer.enqueue, file} +} \ No newline at end of file diff --git a/app/client/common/audioPlayer/audioPlayer.component.js b/app/client/common/audioPlayer/audioPlayer.component.js new file mode 100644 index 0000000..481a685 --- /dev/null +++ b/app/client/common/audioPlayer/audioPlayer.component.js @@ -0,0 +1,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 ( +
+ {this.props.title} + +
+ ) + } +} + +const mapStateToProps = state => ({ + audioPlayer: state.audioPlayer, +}) + +const mapDispatchToProps = (dispatch, ownProps) => ({ + actions: bindActionCreators(audioPlayerActions, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(AudioPlayer) diff --git a/app/client/common/audioPlayer/audioPlayer.reducer.js b/app/client/common/audioPlayer/audioPlayer.reducer.js new file mode 100644 index 0000000..e249325 --- /dev/null +++ b/app/client/common/audioPlayer/audioPlayer.reducer.js @@ -0,0 +1,44 @@ +import types from '../../types' + +const audioPlayerInitialState = { + loading: false, + error: null, + status: '', + current: null, + index: -1, + playlist: [], +} + +const audio = document.createElement('audio') + +const audioPlayerReducer = (state = audioPlayerInitialState, action) => { + switch(action.type) { + case types.audioPlayer.play: + if (! action.file.url) { + return state + } + audio.src = action.file.url + audio.play() + return { + ...state, + playing: true, + current: action.file, + } + case types.audioPlayer.pause: + audio.pause() + return { + ...state, + playing: false, + } + case types.audioPlayer.resume: + audio.play() + return { + ...state, + playing: true, + } + default: + return state + } +} + +export default audioPlayerReducer diff --git a/app/client/common/fileList.component.js b/app/client/common/fileList.component.js index f596c8d..d060e01 100644 --- a/app/client/common/fileList.component.js +++ b/app/client/common/fileList.component.js @@ -27,7 +27,7 @@ export const FileList = props => { fields={fieldSet(fields)} className={rowClassName} linkFiles - onClick + onClick={onClick} /> }) if (! (files && files.length)) { @@ -79,8 +79,8 @@ export const FileRow = props => { {file.persisted === false ? {file.name || file.url} : (linkFiles && file.url) - ? {file.name || file.url} - : onClick(file)}>{file.name || file.url} + ? onClick && onClick(file, e)} href={file.url}>{file.name || file.url} + : onClick && onClick(file, e)}>{file.name || file.url} } } -- cgit v1.2.3-70-g09d2