2016-10-17 10:39:11 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
2016-10-17 14:27:48 +13:00
|
|
|
import { Link } from 'react-router'
|
2016-10-17 10:39:11 +13:00
|
|
|
|
2016-10-21 23:27:50 +13:00
|
|
|
import PlaylistListItem from '../../components/PlaylistListItem'
|
2016-10-23 23:48:06 +13:00
|
|
|
import Header from '../../components/Header'
|
2016-10-21 23:27:50 +13:00
|
|
|
|
2016-10-21 09:56:07 +13:00
|
|
|
import * as mopidyActions from '../../services/mopidy/actions'
|
|
|
|
|
import * as spotifyActions from '../../services/spotify/actions'
|
2016-10-17 10:39:11 +13:00
|
|
|
|
2016-10-21 09:56:07 +13:00
|
|
|
class LibraryPlaylists extends React.Component{
|
2016-10-17 10:39:11 +13:00
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// on render
|
|
|
|
|
componentDidMount(){
|
2016-10-21 23:27:50 +13:00
|
|
|
if( this.props.mopidy.connected ) this.loadPlaylists();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps( nextProps ){
|
|
|
|
|
if( !this.props.mopidy.connected && nextProps.mopidy.connected ) this.loadPlaylists();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadPlaylists(){
|
2016-10-21 09:56:07 +13:00
|
|
|
this.props.spotifyActions.getLibraryPlaylists();
|
2016-10-21 23:27:50 +13:00
|
|
|
this.props.mopidyActions.getPlaylists();
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
2016-10-21 23:27:50 +13:00
|
|
|
compiledPlaylistSources(){
|
|
|
|
|
var playlists = [];
|
|
|
|
|
|
|
|
|
|
if( this.props.mopidy.playlists ){
|
|
|
|
|
Object.assign(playlists, this.props.mopidy.playlists)
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-21 09:56:07 +13:00
|
|
|
if( this.props.spotify.libraryPlaylists ){
|
2016-10-21 23:27:50 +13:00
|
|
|
Object.assign(playlists, this.props.spotify.libraryPlaylists.items)
|
2016-10-17 14:27:48 +13:00
|
|
|
}
|
2016-10-21 23:27:50 +13:00
|
|
|
|
|
|
|
|
return playlists;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderPlaylists(){
|
|
|
|
|
if( !this.compiledPlaylistSources() ) return null;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ul>
|
|
|
|
|
<li className="list-item header playlist">
|
|
|
|
|
<span className="col name">Name</span>
|
|
|
|
|
<span className="col owner">Owner</span>
|
|
|
|
|
<span className="col source">Source</span>
|
|
|
|
|
</li>
|
|
|
|
|
{
|
|
|
|
|
this.compiledPlaylistSources().map( (playlist, index) => {
|
|
|
|
|
return (
|
|
|
|
|
<PlaylistListItem key={index} item={playlist} />
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</ul>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
2016-10-23 23:48:06 +13:00
|
|
|
<Header
|
|
|
|
|
icon="playlist"
|
|
|
|
|
title="My playlists"
|
|
|
|
|
/>
|
2016-10-21 23:27:50 +13:00
|
|
|
{ this.renderPlaylists() }
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-21 09:56:07 +13:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LibraryPlaylists)
|