2016-08-12 00:57:12 +02:00
|
|
|
// NPM imports
|
|
|
|
import React, { Component } from "react";
|
|
|
|
import { bindActionCreators } from "redux";
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
import Immutable from "immutable";
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
import * as actionCreators from "../actions";
|
|
|
|
|
|
|
|
// Components
|
|
|
|
import Playlist from "../components/Playlist";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Table of songs in the current playlist.
|
|
|
|
*/
|
|
|
|
class PlaylistPage extends Component {
|
|
|
|
render() {
|
2016-09-24 02:43:40 +02:00
|
|
|
const actions = this.props.actions;
|
|
|
|
const playAction = function (id) {
|
|
|
|
actions.jumpToSong(id);
|
|
|
|
actions.togglePlaying(true);
|
|
|
|
};
|
2016-08-12 00:57:12 +02:00
|
|
|
return (
|
2016-09-24 02:43:40 +02:00
|
|
|
<Playlist playAction={playAction} playNextAction={null} flushAction={actions.stopPlayback} songs={this.props.songsList} currentIndex={this.props.currentIndex} />
|
2016-08-12 00:57:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const mapStateToProps = (state) => {
|
|
|
|
let songsList = new Immutable.List();
|
|
|
|
if (state.webplayer.playlist.size > 0) {
|
|
|
|
songsList = state.webplayer.playlist.map(function (id) {
|
|
|
|
let song = state.entities.getIn(["entities", "song", id]);
|
|
|
|
// Add artist and album infos to song
|
|
|
|
const artist = state.entities.getIn(["entities", "artist", song.get("artist")]);
|
|
|
|
const album = state.entities.getIn(["entities", "album", song.get("album")]);
|
|
|
|
return (
|
|
|
|
song
|
|
|
|
.set("artist", new Immutable.Map({id: artist.get("id"), name: artist.get("name")}))
|
|
|
|
.set("album", new Immutable.Map({id: album.get("id"), name: album.get("name")}))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
songsList: songsList,
|
|
|
|
currentIndex: state.webplayer.currentIndex,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
actions: bindActionCreators(actionCreators, dispatch),
|
|
|
|
});
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(PlaylistPage);
|