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-11-01 08:57:28 +13:00
|
|
|
import LazyLoadListener from '../../components/LazyLoadListener'
|
2016-10-23 23:48:06 +13:00
|
|
|
import Header from '../../components/Header'
|
2016-10-25 21:36:33 +13:00
|
|
|
import ArtistGrid from '../../components/ArtistGrid'
|
2016-11-21 10:06:25 +13:00
|
|
|
import List from '../../components/List'
|
|
|
|
|
import DropdownField from '../../components/DropdownField'
|
2016-10-23 23:48:06 +13:00
|
|
|
|
2017-01-23 09:24:59 +13:00
|
|
|
import * as helpers from '../../helpers'
|
2016-11-21 10:06:25 +13:00
|
|
|
import * as uiActions from '../../services/ui/actions'
|
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
|
|
|
|
|
|
|
|
class LibraryArtists extends React.Component{
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-02 09:06:15 +13:00
|
|
|
handleContextMenu(e,item){
|
|
|
|
|
var data = {
|
|
|
|
|
e: e,
|
|
|
|
|
context: 'artist',
|
|
|
|
|
uris: [item.uri],
|
2017-03-12 16:19:06 +13:00
|
|
|
items: [item]
|
2017-02-02 09:06:15 +13:00
|
|
|
}
|
|
|
|
|
this.props.uiActions.showContextMenu(data)
|
2017-01-27 16:13:11 +13:00
|
|
|
}
|
|
|
|
|
|
2016-10-17 10:39:11 +13:00
|
|
|
componentDidMount(){
|
2017-03-10 09:04:42 +13:00
|
|
|
if (!this.props.library_artists_started){
|
|
|
|
|
this.props.spotifyActions.getLibraryArtists();
|
|
|
|
|
}
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-01 08:57:28 +13:00
|
|
|
loadMore(){
|
2017-01-14 22:32:39 +13:00
|
|
|
this.props.spotifyActions.getURL( this.props.library_artists_more, 'SPOTIFY_LIBRARY_ARTISTS_LOADED' );
|
2016-11-01 08:57:28 +13:00
|
|
|
}
|
|
|
|
|
|
2017-01-23 09:24:59 +13:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-14 22:32:39 +13:00
|
|
|
renderView(artists){
|
2016-11-21 10:06:25 +13:00
|
|
|
if( this.props.view == 'list' ){
|
|
|
|
|
var columns = [
|
|
|
|
|
{
|
2016-11-21 16:26:47 +13:00
|
|
|
label: 'Name',
|
2016-11-21 10:06:25 +13:00
|
|
|
name: 'name'
|
|
|
|
|
},
|
|
|
|
|
{
|
2016-11-21 16:26:47 +13:00
|
|
|
label: 'Followers',
|
2016-11-21 10:06:25 +13:00
|
|
|
name: 'followers.total'
|
2017-01-24 08:02:30 +13:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Popularity',
|
|
|
|
|
name: 'popularity'
|
2016-11-21 10:06:25 +13:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
return (
|
2017-06-18 05:47:36 +12:00
|
|
|
<section className="content-wrapper">
|
2017-01-27 16:13:11 +13:00
|
|
|
<List
|
2017-02-02 09:06:15 +13:00
|
|
|
handleContextMenu={(e,item) => this.handleContextMenu(e,item)}
|
2017-01-27 16:13:11 +13:00
|
|
|
rows={artists}
|
|
|
|
|
columns={columns}
|
2017-03-13 21:19:09 +13:00
|
|
|
className="artist-list"
|
2017-03-06 09:03:20 +13:00
|
|
|
link_prefix={global.baseURL+"artist/"} />
|
2016-11-21 10:06:25 +13:00
|
|
|
</section>
|
|
|
|
|
)
|
|
|
|
|
}else{
|
|
|
|
|
return (
|
2017-06-18 05:47:36 +12:00
|
|
|
<section className="content-wrapper">
|
2017-01-27 16:13:11 +13:00
|
|
|
<ArtistGrid
|
2017-02-02 09:06:15 +13:00
|
|
|
handleContextMenu={(e,item) => this.handleContextMenu(e,item)}
|
2017-01-27 16:13:11 +13:00
|
|
|
artists={artists} />
|
2016-11-21 10:06:25 +13:00
|
|
|
</section>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-17 10:39:11 +13:00
|
|
|
render(){
|
2017-05-22 04:19:44 +12:00
|
|
|
if (helpers.isLoading(this.props.load_queue,['spotify_me/following?type=artist'])){
|
|
|
|
|
return (
|
|
|
|
|
<div className="view library-albums-view">
|
|
|
|
|
<Header icon="cd" title="My albums" />
|
|
|
|
|
<div className="body-loader">
|
|
|
|
|
<div className="loader"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
2016-11-21 10:06:25 +13:00
|
|
|
|
2017-01-14 22:32:39 +13:00
|
|
|
var artists = []
|
|
|
|
|
if (this.props.library_artists && this.props.artists){
|
|
|
|
|
for (var i = 0; i < this.props.library_artists.length; i++){
|
|
|
|
|
var uri = this.props.library_artists[i]
|
|
|
|
|
if (this.props.artists.hasOwnProperty(uri)){
|
|
|
|
|
artists.push(this.props.artists[uri])
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-23 09:24:59 +13:00
|
|
|
|
|
|
|
|
if( this.props.sort ){
|
|
|
|
|
artists = helpers.sortItems(artists, this.props.sort, this.props.sort_reverse)
|
|
|
|
|
}
|
2017-01-14 22:32:39 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-21 10:06:25 +13:00
|
|
|
var view_options = [
|
|
|
|
|
{
|
2017-01-24 08:02:30 +13:00
|
|
|
label: 'Thumbnails',
|
|
|
|
|
value: 'thumbnails'
|
2016-11-21 10:06:25 +13:00
|
|
|
},
|
|
|
|
|
{
|
2017-01-24 08:02:30 +13:00
|
|
|
label: 'List',
|
|
|
|
|
value: 'list'
|
2016-11-21 10:06:25 +13:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
2017-01-23 09:24:59 +13:00
|
|
|
var sort_options = [
|
|
|
|
|
{
|
2017-01-24 08:02:30 +13:00
|
|
|
label: 'Name',
|
|
|
|
|
value: 'name'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Followers',
|
|
|
|
|
value: 'followers.total'
|
2017-01-23 09:24:59 +13:00
|
|
|
},
|
|
|
|
|
{
|
2017-01-24 08:02:30 +13:00
|
|
|
label: 'Popularity',
|
|
|
|
|
value: 'popularity'
|
2017-01-23 09:24:59 +13:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
2017-03-06 09:03:20 +13:00
|
|
|
var options = (
|
2017-01-23 09:24:59 +13:00
|
|
|
<span>
|
2017-03-06 09:03:20 +13:00
|
|
|
<DropdownField icon="sort" name="Sort" value={ this.props.sort } options={sort_options} reverse={this.props.sort_reverse} handleChange={value => {this.setSort(value); this.props.uiActions.hideContextMenu() }} />
|
|
|
|
|
<DropdownField icon="eye" name="View" value={ this.props.view } options={view_options} handleChange={value => {this.props.uiActions.set({ library_artists_view: value }); this.props.uiActions.hideContextMenu()}} />
|
2017-01-23 09:24:59 +13:00
|
|
|
</span>
|
2016-11-21 10:06:25 +13:00
|
|
|
)
|
|
|
|
|
|
2016-10-26 16:55:47 +13:00
|
|
|
return (
|
|
|
|
|
<div className="view library-artists-view">
|
2017-03-06 09:03:20 +13:00
|
|
|
<Header icon="mic" title="My artists" options={options} uiActions={this.props.uiActions} />
|
2017-01-14 22:32:39 +13:00
|
|
|
{ this.renderView(artists) }
|
2017-01-27 08:15:59 +13:00
|
|
|
<LazyLoadListener enabled={this.props.library_artists_more} loadMore={ () => this.loadMore() }/>
|
2016-10-26 16:55:47 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2016-11-19 13:06:08 +13:00
|
|
|
return {
|
2017-05-22 04:19:44 +12:00
|
|
|
load_queue: state.ui.load_queue,
|
2017-01-14 22:32:39 +13:00
|
|
|
artists: state.ui.artists,
|
2017-03-15 08:23:47 +13:00
|
|
|
sort: (state.ui.library_artists_sort ? state.ui.library_artists_sort : 'name'),
|
|
|
|
|
sort_reverse: (state.ui.library_artists_sort_reverse ? true : false),
|
2017-01-14 22:32:39 +13:00
|
|
|
library_artists: state.ui.library_artists,
|
2017-03-12 16:19:06 +13:00
|
|
|
library_artists_started: state.ui.library_artists_started,
|
2017-01-14 22:32:39 +13:00
|
|
|
library_artists_more: state.ui.library_artists_more,
|
2017-03-10 09:04:42 +13:00
|
|
|
library_artists_started: state.ui.library_artists_started,
|
2017-01-14 22:32:39 +13:00
|
|
|
view: state.ui.library_artists_view
|
2016-11-19 13:06:08 +13:00
|
|
|
}
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
2016-11-21 10:06:25 +13:00
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
2016-10-17 10:39:11 +13:00
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LibraryArtists)
|