import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import FontAwesome from 'react-fontawesome'
import PlaylistGrid from '../../components/PlaylistGrid'
import List from '../../components/List'
import DropdownField from '../../components/DropdownField'
import Header from '../../components/Header'
import * as helpers from '../../helpers'
import * as coreActions from '../../services/core/actions'
import * as uiActions from '../../services/ui/actions'
import * as mopidyActions from '../../services/mopidy/actions'
import * as spotifyActions from '../../services/spotify/actions'
class LibraryPlaylists extends React.Component{
constructor(props) {
super(props);
}
componentDidMount(){
if (!this.props.library_playlists){
if (this.props.spotify_connected){
this.props.coreActions.getLibraryPlaylists()
}
}
}
componentWillReceiveProps(newProps){
if (!this.props.spotify_connected && newProps.spotify_connected){
this.props.spotifyActions.getLibraryPlaylists()
}
if (!this.props.mopidy_connected && newProps.mopidy_connected){
this.props.mopidyActions.getLibraryPlaylists()
}
}
handleContextMenu(e,item){
var data = {
e: e,
context: 'playlist',
uris: [item.uri],
items: [item]
}
this.props.uiActions.showContextMenu(data)
}
setSort(value){
var reverse = false
if( this.props.sort == value ) reverse = !this.props.sort_reverse
var data = {
library_playlists_sort_reverse: reverse,
library_playlists_sort: value
}
this.props.uiActions.set(data)
}
renderView(){
if (!this.props.library_playlists || !this.props.playlists ){
return null
}
var playlists = []
for (var i = 0; i < this.props.library_playlists.length; i++){
var uri = this.props.library_playlists[i]
var owner_id = helpers.getFromUri('playlistowner',uri)
if (this.props.playlists.hasOwnProperty(uri)){
switch (this.props.filter){
case 'only_mine':
if (this.props.me_id && owner_id == this.props.me_id){
playlists.push(this.props.playlists[uri])
}
break
case 'only_others':
if (!this.props.me_id || owner_id != this.props.me_id){
playlists.push(this.props.playlists[uri])
}
break
default:
playlists.push(this.props.playlists[uri])
break
}
}
}
if( this.props.sort ){
playlists = helpers.sortItems(playlists, this.props.sort, this.props.sort_reverse)
}
if( this.props.view == 'list' ){
if (this.props.slim_mode){
var columns = [
{
label: 'Name',
name: 'name'
},
{
label: 'Tracks',
name: 'tracks_total'
}
]
} else {
var columns = [
{
label: 'Name',
name: 'name'
},
{
label: 'Owner',
name: 'owner'
},
{
label: 'Tracks',
name: 'tracks_total'
},
{
label: 'Editable',
name: 'can_edit'
},
{
label: 'Source',
name: 'source'
}
]
}
return (
this.handleContextMenu(e,item)}
rows={playlists}
columns={columns}
className="playlist-list"
link_prefix={global.baseURL+"playlist/"} />