Files
Iris/src/js/views/library/LibraryArtists.js

190 lines
5.0 KiB
JavaScript
Raw Normal View History

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-11-01 08:57:28 +13:00
import LazyLoadListener from '../../components/LazyLoadListener'
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'
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'
import * as mopidyActions from '../../services/mopidy/actions'
import * as spotifyActions from '../../services/spotify/actions'
class LibraryArtists extends React.Component{
constructor(props) {
super(props);
}
handleContextMenu(e,item){
var data = {
e: e,
context: 'artist',
uris: [item.uri],
items: [item]
}
this.props.uiActions.showContextMenu(data)
2017-01-27 16:13:11 +13:00
}
componentDidMount(){
if (!this.props.library_artists_started){
this.props.spotifyActions.getLibraryArtists();
}
}
2016-11-01 08:57:28 +13:00
loadMore(){
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)
}
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'
},
{
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
handleContextMenu={(e,item) => this.handleContextMenu(e,item)}
2017-01-27 16:13:11 +13:00
rows={artists}
columns={columns}
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
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>
)
}
}
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
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)
}
}
2016-11-21 10:06:25 +13:00
var view_options = [
{
label: 'Thumbnails',
value: 'thumbnails'
2016-11-21 10:06:25 +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 = [
{
label: 'Name',
value: 'name'
},
{
label: 'Followers',
value: 'followers.total'
2017-01-23 09:24:59 +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} />
{ 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>
);
}
}
/**
* Export our component
*
* We also integrate our global store, using connect()
**/
const mapStateToProps = (state, ownProps) => {
return {
2017-05-22 04:19:44 +12:00
load_queue: state.ui.load_queue,
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),
library_artists: state.ui.library_artists,
library_artists_started: state.ui.library_artists_started,
library_artists_more: state.ui.library_artists_more,
library_artists_started: state.ui.library_artists_started,
view: state.ui.library_artists_view
}
}
const mapDispatchToProps = (dispatch) => {
return {
2016-11-21 10:06:25 +13:00
uiActions: bindActionCreators(uiActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(LibraryArtists)