import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import LazyLoadListener from '../../components/LazyLoadListener'
import Header from '../../components/Header'
import ArtistGrid from '../../components/ArtistGrid'
import List from '../../components/List'
import DropdownField from '../../components/DropdownField'
import FilterField from '../../components/FilterField'
import * as helpers from '../../helpers'
import * as uiActions from '../../services/ui/actions'
import * as mopidyActions from '../../services/mopidy/actions'
import * as spotifyActions from '../../services/spotify/actions'
class LibraryArtists extends React.Component{
constructor(props){
super(props)
this.state = {
filter: ''
}
}
componentDidMount(){
if (this.props.mopidy_library_artists_status != 'finished' && this.props.mopidy_connected && (this.props.source == 'all' || this.props.source == 'local')){
this.props.mopidyActions.getLibraryArtists()
}
if (this.props.spotify_library_artists_status != 'finished' && this.props.spotify_connected && (this.props.source == 'all' || this.props.source == 'spotify')){
this.props.spotifyActions.getLibraryArtists()
}
}
componentWillReceiveProps(newProps){
if (newProps.mopidy_connected && (newProps.source == 'all' || newProps.source == 'local')){
// We've just connected
if (!this.props.mopidy_connected){
this.props.mopidyActions.getLibraryArtists()
}
// Filter changed, but we haven't got this provider's library yet
if (this.props.source != 'all' && this.props.source != 'local' && newProps.mopidy_library_artists_status != 'finished'){
this.props.mopidyActions.getLibraryArtists()
}
}
if (newProps.spotify_connected && (newProps.source == 'all' || newProps.source == 'spotify')){
// We've just connected
if (!this.props.spotify_connected){
this.props.spotifyActions.getLibraryArtists()
}
// Filter changed, but we haven't got this provider's library yet
if (this.props.source != 'all' && this.props.source != 'spotify' && newProps.spotify_library_artists_status != 'finished'){
this.props.spotifyActions.getLibraryArtists()
}
}
}
handleContextMenu(e,item){
var data = {
e: e,
context: 'artist',
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_artists_sort_reverse: reverse,
library_artists_sort: value
}
this.props.uiActions.set(data)
}
renderView(artists){
if (this.props.view == 'list'){
var columns = [
{
label: 'Name',
name: 'name'
},
{
label: 'Followers',
name: 'followers.total'
},
{
label: 'Popularity',
name: 'popularity'
}
]
return (
this.handleContextMenu(e,item)}
rows={artists}
columns={columns}
className="artist-list"
link_prefix={global.baseURL+"artist/"} />