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-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'
|
2018-04-19 13:34:16 +12:00
|
|
|
import DropdownField from '../../components/Fields/DropdownField'
|
|
|
|
|
import FilterField from '../../components/Fields/FilterField'
|
2017-10-20 14:58:19 +13:00
|
|
|
import LazyLoadListener from '../../components/LazyLoadListener'
|
2018-05-15 21:30:57 +12:00
|
|
|
import Icon from '../../components/Icon'
|
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{
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
constructor(props){
|
2017-08-14 20:02:41 +12:00
|
|
|
super(props)
|
|
|
|
|
|
|
|
|
|
this.state = {
|
2017-10-20 14:58:19 +13:00
|
|
|
filter: '',
|
|
|
|
|
limit: 50,
|
|
|
|
|
per_page: 50
|
2017-08-14 20:02:41 +12:00
|
|
|
}
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
2017-08-12 23:01:55 +12:00
|
|
|
componentDidMount(){
|
2018-02-21 12:58:32 +13:00
|
|
|
if (!this.props.mopidy_library_artists && this.props.mopidy_connected && (this.props.source == 'all' || this.props.source == 'local')){
|
2018-02-20 16:54:49 +13:00
|
|
|
this.props.mopidyActions.getLibraryArtists();
|
2017-08-13 21:42:19 +12:00
|
|
|
}
|
|
|
|
|
|
2018-04-01 11:52:42 +12:00
|
|
|
if (this.props.mopidy_uri_schemes.includes('spotify:') && this.props.spotify_library_artists_status != 'finished' && (this.props.source == 'all' || this.props.source == 'spotify')){
|
2018-02-20 16:54:49 +13:00
|
|
|
this.props.spotifyActions.getLibraryArtists();
|
2017-08-12 23:01:55 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps(newProps){
|
2017-08-14 20:02:41 +12:00
|
|
|
if (newProps.mopidy_connected && (newProps.source == 'all' || newProps.source == 'local')){
|
2017-08-13 21:42:19 +12:00
|
|
|
|
|
|
|
|
// We've just connected
|
|
|
|
|
if (!this.props.mopidy_connected){
|
2018-02-20 16:54:49 +13:00
|
|
|
this.props.mopidyActions.getLibraryArtists();
|
2017-08-13 21:42:19 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter changed, but we haven't got this provider's library yet
|
2018-02-21 12:58:32 +13:00
|
|
|
if (this.props.source != 'all' && this.props.source != 'local' && !newProps.mopidy_library_artists){
|
2018-02-20 16:54:49 +13:00
|
|
|
this.props.mopidyActions.getLibraryArtists();
|
2017-08-13 21:42:19 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-01 11:52:42 +12:00
|
|
|
if (newProps.mopidy_uri_schemes.includes('spotify:') && (newProps.source == 'all' || newProps.source == 'spotify')){
|
2017-08-13 21:42:19 +12:00
|
|
|
|
|
|
|
|
// Filter changed, but we haven't got this provider's library yet
|
2018-06-26 08:51:11 +12:00
|
|
|
if (newProps.spotify_library_artists_status != 'finished' && newProps.spotify_library_artists_status != 'started'){
|
2018-02-20 16:54:49 +13:00
|
|
|
this.props.spotifyActions.getLibraryArtists();
|
2017-08-15 16:36:50 +12:00
|
|
|
}
|
2017-08-12 23:01:55 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2018-02-20 16:54:49 +13:00
|
|
|
loadMore(){
|
2018-02-21 12:58:32 +13:00
|
|
|
console.log('Load more');
|
2018-02-20 16:54:49 +13:00
|
|
|
this.setState({limit: this.state.limit + this.state.per_page});
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-23 09:24:59 +13:00
|
|
|
setSort(value){
|
|
|
|
|
var reverse = false
|
2017-10-10 13:05:28 +13:00
|
|
|
if (this.props.sort == value ) reverse = !this.props.sort_reverse
|
2017-01-23 09:24:59 +13:00
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
|
library_artists_sort_reverse: reverse,
|
|
|
|
|
library_artists_sort: value
|
|
|
|
|
}
|
2018-02-21 12:58:32 +13:00
|
|
|
this.props.uiActions.set(data);
|
2017-01-23 09:24:59 +13:00
|
|
|
}
|
|
|
|
|
|
2017-10-20 14:58:19 +13:00
|
|
|
renderView(){
|
2018-02-21 12:58:32 +13:00
|
|
|
var artists = [];
|
2017-08-12 23:01:55 +12:00
|
|
|
|
2017-08-13 21:42:19 +12:00
|
|
|
// Mopidy library items
|
2017-08-14 20:02:41 +12:00
|
|
|
if (this.props.mopidy_library_artists && (this.props.source == 'all' || this.props.source == 'local')){
|
2017-08-13 21:42:19 +12:00
|
|
|
for (var i = 0; i < this.props.mopidy_library_artists.length; i++){
|
|
|
|
|
|
|
|
|
|
// Construct item placeholder. This is used as Mopidy needs to
|
|
|
|
|
// lookup ref objects to get the full object which can take some time
|
|
|
|
|
var uri = this.props.mopidy_library_artists[i]
|
|
|
|
|
var source = helpers.uriSource(uri)
|
|
|
|
|
var artist = {
|
|
|
|
|
uri: uri,
|
|
|
|
|
source: source
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.props.artists.hasOwnProperty(uri)){
|
|
|
|
|
artist = this.props.artists[uri]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
artists.push(artist)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-12 23:01:55 +12:00
|
|
|
// Spotify library items
|
2017-08-14 20:02:41 +12:00
|
|
|
if (this.props.spotify_library_artists && (this.props.source == 'all' || this.props.source == 'spotify')){
|
2017-08-12 23:01:55 +12:00
|
|
|
for (var i = 0; i < this.props.spotify_library_artists.length; i++){
|
|
|
|
|
var uri = this.props.spotify_library_artists[i]
|
2017-01-14 22:32:39 +13:00
|
|
|
if (this.props.artists.hasOwnProperty(uri)){
|
|
|
|
|
artists.push(this.props.artists[uri])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-18 20:44:35 +12:00
|
|
|
if (this.props.sort){
|
|
|
|
|
artists = helpers.sortItems(artists, this.props.sort, this.props.sort_reverse);
|
|
|
|
|
}
|
2017-08-12 23:01:55 +12:00
|
|
|
|
2017-08-14 20:02:41 +12:00
|
|
|
if (this.state.filter !== ''){
|
|
|
|
|
artists = helpers.applyFilter('name', this.state.filter, artists)
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-20 14:58:19 +13:00
|
|
|
// Apply our lazy-load-rendering
|
|
|
|
|
var total_artists = artists.length;
|
|
|
|
|
artists = artists.slice(0, this.state.limit);
|
|
|
|
|
|
|
|
|
|
if (this.props.view == 'list'){
|
|
|
|
|
var columns = [
|
|
|
|
|
{
|
|
|
|
|
label: 'Name',
|
|
|
|
|
name: 'name'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Followers',
|
|
|
|
|
name: 'followers.total'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Popularity',
|
|
|
|
|
name: 'popularity'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
return (
|
|
|
|
|
<section className="content-wrapper">
|
|
|
|
|
<List
|
|
|
|
|
handleContextMenu={(e,item) => this.handleContextMenu(e,item)}
|
|
|
|
|
rows={artists}
|
|
|
|
|
columns={columns}
|
|
|
|
|
className="artist-list"
|
|
|
|
|
link_prefix={global.baseURL+"artist/"} />
|
2018-02-20 16:54:49 +13:00
|
|
|
<LazyLoadListener loading={this.state.limit < total_artists} loadMore={() => this.loadMore()} />
|
2017-10-20 14:58:19 +13:00
|
|
|
</section>
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
<section className="content-wrapper">
|
|
|
|
|
<ArtistGrid
|
|
|
|
|
handleContextMenu={(e,item) => this.handleContextMenu(e,item)}
|
|
|
|
|
artists={artists} />
|
2018-02-20 16:54:49 +13:00
|
|
|
<LazyLoadListener loading={this.state.limit < total_artists} loadMore={() => this.loadMore()} />
|
2017-10-20 14:58:19 +13:00
|
|
|
</section>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
2017-08-14 20:02:41 +12:00
|
|
|
var source_options = [
|
2017-08-13 21:42:19 +12:00
|
|
|
{
|
|
|
|
|
value: 'all',
|
|
|
|
|
label: 'All'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'local',
|
|
|
|
|
label: 'Local'
|
2018-02-06 19:54:55 +13:00
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (this.props.mopidy_uri_schemes.includes('spotify:')){
|
|
|
|
|
source_options.push({
|
2017-08-13 21:42:19 +12:00
|
|
|
value: 'spotify',
|
|
|
|
|
label: 'Spotify'
|
2018-02-06 19:54:55 +13:00
|
|
|
});
|
|
|
|
|
}
|
2017-08-13 21:42:19 +12: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
|
|
|
}
|
2018-02-06 19:54:55 +13:00
|
|
|
];
|
2016-11-21 10:06:25 +13:00
|
|
|
|
2017-01-23 09:24:59 +13:00
|
|
|
var sort_options = [
|
2018-06-18 20:44:35 +12:00
|
|
|
{
|
|
|
|
|
label: 'Default',
|
|
|
|
|
value: null
|
|
|
|
|
},
|
2017-01-23 09:24:59 +13:00
|
|
|
{
|
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
|
|
|
}
|
2018-02-06 19:54:55 +13:00
|
|
|
];
|
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-10-20 14:58:19 +13:00
|
|
|
<FilterField handleChange={value => this.setState({filter: value, limit: this.state.per_page})} />
|
2018-05-06 20:25:59 +12:00
|
|
|
<DropdownField
|
|
|
|
|
icon="sort"
|
|
|
|
|
name="Sort"
|
2018-05-16 16:50:46 +12:00
|
|
|
value={this.props.sort}
|
2018-05-06 20:25:59 +12:00
|
|
|
options={sort_options}
|
2018-06-18 20:44:35 +12:00
|
|
|
selected_icon={this.props.sort ? (this.props.sort_reverse ? 'keyboard_arrow_up' : 'keyboard_arrow_down') : null}
|
2018-05-06 20:25:59 +12:00
|
|
|
handleChange={value => {this.setSort(value); this.props.uiActions.hideContextMenu() }}
|
|
|
|
|
/>
|
|
|
|
|
<DropdownField
|
2018-05-16 16:50:46 +12:00
|
|
|
icon="visibility"
|
2018-05-06 20:25:59 +12:00
|
|
|
name="View"
|
2018-05-16 16:50:46 +12:00
|
|
|
value={this.props.view}
|
2018-05-06 20:25:59 +12:00
|
|
|
options={view_options}
|
|
|
|
|
handleChange={value => {this.props.uiActions.set({ library_artists_view: value }); this.props.uiActions.hideContextMenu()}}
|
|
|
|
|
/>
|
|
|
|
|
<DropdownField
|
2018-05-16 16:50:46 +12:00
|
|
|
icon="cloud"
|
2018-05-06 20:25:59 +12:00
|
|
|
name="Source"
|
|
|
|
|
value={this.props.source}
|
|
|
|
|
options={source_options}
|
|
|
|
|
handleChange={value => {this.props.uiActions.set({ library_artists_source: 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">
|
2018-05-15 21:30:57 +12:00
|
|
|
<Header options={options} uiActions={this.props.uiActions}>
|
|
|
|
|
<Icon name="recent_actors" type="material" />
|
|
|
|
|
My artists
|
|
|
|
|
</Header>
|
2017-10-20 14:58:19 +13:00
|
|
|
{this.renderView()}
|
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-08-13 21:42:19 +12:00
|
|
|
mopidy_connected: state.mopidy.connected,
|
2018-02-06 19:54:55 +13:00
|
|
|
mopidy_uri_schemes: state.mopidy.uri_schemes,
|
2017-08-13 21:42:19 +12:00
|
|
|
mopidy_library_artists: state.mopidy.library_artists,
|
2017-11-12 09:05:34 +13:00
|
|
|
mopidy_library_artists_status: (state.ui.processes.MOPIDY_LIBRARY_ARTISTS_PROCESSOR !== undefined ? state.ui.processes.MOPIDY_LIBRARY_ARTISTS_PROCESSOR.status : null),
|
2017-08-12 23:01:55 +12:00
|
|
|
spotify_library_artists: state.spotify.library_artists,
|
2017-11-12 09:05:34 +13:00
|
|
|
spotify_library_artists_status: (state.ui.processes.SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR !== undefined ? state.ui.processes.SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR.status : null),
|
2017-08-02 10:53:30 +12:00
|
|
|
artists: state.core.artists,
|
2017-08-14 20:02:41 +12:00
|
|
|
source: (state.ui.library_artists_source ? state.ui.library_artists_source : 'all'),
|
2018-06-18 20:44:35 +12:00
|
|
|
sort: (state.ui.library_artists_sort ? state.ui.library_artists_sort : null),
|
|
|
|
|
sort_reverse: (state.ui.library_artists_sort_reverse ? state.ui.library_artists_sort_reverse : false),
|
2017-08-14 20:02:41 +12: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)
|