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

173 lines
4.4 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);
}
2017-01-27 16:13:11 +13:00
handleContextMenu(e,uri){
e.preventDefault()
var data = { uris: [uri] }
this.props.uiActions.showContextMenu( e, data, 'artist', 'click' )
}
componentDidMount(){
if (!this.props.library_artists) 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',
width: 70,
2016-11-21 10:06:25 +13:00
name: 'name'
},
{
2016-11-21 16:26:47 +13:00
label: 'Followers',
width: 15,
2016-11-21 10:06:25 +13:00
name: 'followers.total'
},
{
label: 'Popularity',
width: 15,
name: 'popularity'
2016-11-21 10:06:25 +13:00
}
]
return (
<section className="list-wrapper">
2017-01-27 16:13:11 +13:00
<List
handleContextMenu={(e,uri) => this.handleContextMenu(e,uri)}
rows={artists}
columns={columns}
link_prefix={global.baseURL+"artist/"} show_source_icon={true} />
2016-11-21 10:06:25 +13:00
</section>
)
}else{
return (
<section className="grid-wrapper">
2017-01-27 16:13:11 +13:00
<ArtistGrid
handleContextMenu={(e,uri) => this.handleContextMenu(e,uri)}
artists={artists} />
2016-11-21 10:06:25 +13:00
</section>
)
}
}
render(){
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
}
]
2016-11-21 10:06:25 +13:00
var actions = (
2017-01-23 09:24:59 +13:00
<span>
<DropdownField icon="sort" name="Sort" value={ this.props.sort } options={sort_options} reverse={this.props.sort_reverse} handleChange={ value => this.setSort(value) } />
<DropdownField icon="eye" name="View" value={ this.props.view } options={view_options} handleChange={ value => this.props.uiActions.set({ library_artists_view: value }) } />
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">
2016-11-21 10:06:25 +13:00
<Header icon="mic" title="My artists" actions={actions} />
{ 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 {
artists: state.ui.artists,
2017-01-23 09:24:59 +13:00
sort: state.ui.library_artists_sort,
sort_reverse: state.ui.library_artists_sort_reverse,
library_artists: state.ui.library_artists,
library_artists_more: state.ui.library_artists_more,
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)