import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import Link from '../components/Link';
import Icon from '../components/Icon';
import Parallax from '../components/Parallax';
import TrackList from '../components/TrackList';
import Dater from '../components/Dater';
import ArtistSentence from '../components/ArtistSentence';
import Thumbnail from '../components/Thumbnail';
import Header from '../components/Header';
import URILink from '../components/URILink';
import LazyLoadListener from '../components/LazyLoadListener';
import * as helpers from '../helpers';
import * as coreActions from '../services/core/actions';
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 Queue extends React.Component {
constructor(props){
super(props);
this.state = {
limit: 50,
per_page: 50
}
}
componentWillMount(){
// Before we mount, restore any limit defined in our location state
var state = (this.props.location.state ? this.props.location.state : {});
if (state.limit){
this.setState({
limit: state.limit
});
}
}
componentDidMount(){
this.props.uiActions.setWindowTitle("Now playing");
}
shouldComponentUpdate(nextProps) {
return (nextProps !== this.props);
}
componentWillReceiveProps(nextProps) {
const { added_from_uri } = nextProps;
if (added_from_uri && this.props.added_from_uri !== added_from_uri) {
const item_type = helpers.uriType(added_from_uri);
switch (item_type) {
case 'album':
this.props.coreActions.loadAlbum(added_from_uri);
break;
case 'artist':
this.props.coreActions.loadArtist(added_from_uri);
break;
case 'playlist':
this.props.coreActions.loadPlaylist(added_from_uri);
break;
}
}
}
loadMore(){
var new_limit = this.state.limit + this.state.per_page;
this.setState({limit: new_limit});
// Set our pagination to location state
var state = (this.props.location && this.props.location.state ? this.props.location.state : {});
state.limit = new_limit;
this.props.history.replace({state: state});
}
removeTracks(track_indexes){
var tlids = [];
for (var i = 0; i < track_indexes.length; i++){
var track = this.props.queue[track_indexes[i]];
if (track.tlid !== undefined){
tlids.push(track.tlid);
}
}
if (tlids.length > 0){
this.props.mopidyActions.removeTracks(tlids);
}
}
playTrack(track){
this.props.mopidyActions.changeTrack(track.tlid);
}
playTracks(tracks){
this.props.mopidyActions.changeTrack(tracks[0].tlid);
}
reorderTracks(indexes, index){
this.props.mopidyActions.reorderTracklist(indexes, index);
}
renderQueueStats(){
var total_time = 0
return (