Files
Iris/src/js/views/QueueHistory.js

109 lines
2.8 KiB
JavaScript
Raw Normal View History

2017-02-10 09:06:41 +13:00
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { hashHistory } from 'react-router'
import { bindActionCreators } from 'redux'
import TrackList from '../components/TrackList'
import Header from '../components/Header'
2018-05-15 21:30:57 +12:00
import Icon from '../components/Icon'
2017-02-10 09:06:41 +13:00
import * as uiActions from '../services/ui/actions'
import * as pusherActions from '../services/pusher/actions'
import * as spotifyActions from '../services/spotify/actions'
import * as mopidyActions from '../services/mopidy/actions'
class QueueHistory extends React.Component{
2017-10-10 13:05:28 +13:00
constructor(props){
2017-02-10 09:06:41 +13:00
super(props);
}
componentDidMount(){
2018-06-28 08:12:03 +12:00
this.props.uiActions.setWindowTitle("Queue history");
2017-02-10 09:06:41 +13:00
this.loadHistory()
}
componentWillReceiveProps(nextProps){
2017-10-10 13:05:28 +13:00
if (!this.props.mopidy_connected && nextProps.mopidy_connected){
2017-02-10 09:06:41 +13:00
this.loadHistory(nextProps)
}
}
loadHistory(props = this.props){
if (props.mopidy_connected){
this.props.mopidyActions.getQueueHistory()
}
}
render(){
2017-03-06 09:03:20 +13:00
var options = (
2017-02-10 09:06:41 +13:00
<span>
2017-07-20 09:40:35 +12:00
<button className="no-hover" onClick={e => hashHistory.push(global.baseURL+'queue')}>
2018-05-16 16:50:46 +12:00
<Icon name="keyboard_backspace" />&nbsp;
2017-02-10 09:06:41 +13:00
Back
</button>
</span>
)
var tracks = [];
for (var i = 0; i < this.props.queue_history.length; i++){
var track = Object.assign({}, this.props.queue_history[i]);
// We have the track in the index, so merge the track objects
if (this.props.tracks[track.uri] !== undefined){
track = Object.assign(
{},
track,
this.props.tracks[track.uri]
);
}
tracks.push(track);
}
2017-02-10 09:06:41 +13:00
return (
<div className="view queue-history-view">
2018-05-15 21:30:57 +12:00
<Header options={options} uiActions={this.props.uiActions}>
<Icon name="play_arrow" type="material" />
Playback history
</Header>
<section className="content-wrapper">
2017-02-10 09:06:41 +13:00
<TrackList
className="queue-history-track-list"
2017-02-10 09:06:41 +13:00
context="history"
tracks={tracks}
2018-11-09 16:45:57 +13:00
show_source_icon={true}
/>
2017-02-10 09:06:41 +13:00
</section>
</div>
);
}
}
/**
* Export our component
*
* We also integrate our global store, using connect()
**/
const mapStateToProps = (state, ownProps) => {
return {
mopidy_connected: state.mopidy.connected,
tracks: (state.core.tracks ? state.core.tracks : {}),
2017-02-10 09:06:41 +13:00
queue_history: (state.mopidy.queue_history ? state.mopidy.queue_history : [])
}
}
const mapDispatchToProps = (dispatch) => {
return {
uiActions: bindActionCreators(uiActions, dispatch),
pusherActions: bindActionCreators(pusherActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(QueueHistory)