2016-10-17 10:39:11 +13:00
|
|
|
|
2019-02-10 19:51:33 +13:00
|
|
|
import React from 'react';
|
2018-10-16 21:21:36 +13:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
|
import Header from '../../components/Header';
|
|
|
|
|
import ArtistGrid from '../../components/ArtistGrid';
|
|
|
|
|
import List from '../../components/List';
|
|
|
|
|
import DropdownField from '../../components/Fields/DropdownField';
|
|
|
|
|
import FilterField from '../../components/Fields/FilterField';
|
|
|
|
|
import LazyLoadListener from '../../components/LazyLoadListener';
|
|
|
|
|
import Icon from '../../components/Icon';
|
|
|
|
|
import * as uiActions from '../../services/ui/actions';
|
|
|
|
|
import * as mopidyActions from '../../services/mopidy/actions';
|
|
|
|
|
import * as spotifyActions from '../../services/spotify/actions';
|
|
|
|
|
import * as googleActions from '../../services/google/actions';
|
2020-03-03 16:39:37 +13:00
|
|
|
import {
|
|
|
|
|
uriSource,
|
|
|
|
|
} from '../../util/helpers';
|
|
|
|
|
import { sortItems, applyFilter } from '../../util/arrays';
|
2020-07-19 20:41:14 +12:00
|
|
|
import { I18n, i18n } from '../../locale';
|
2016-10-17 10:39:11 +13:00
|
|
|
|
2019-10-09 09:42:20 +13:00
|
|
|
class LibraryArtists extends React.Component {
|
2019-09-05 15:36:11 +12:00
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
filter: '',
|
|
|
|
|
limit: 50,
|
|
|
|
|
per_page: 50,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-15 13:50:39 +13:00
|
|
|
componentDidMount() {
|
2020-08-11 21:05:36 +12:00
|
|
|
const {
|
|
|
|
|
uiActions: {
|
|
|
|
|
setWindowTitle,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
2019-11-15 13:50:39 +13:00
|
|
|
// Restore any limit defined in our location state
|
2019-09-05 15:36:11 +12:00
|
|
|
const state = (this.props.location.state ? this.props.location.state : {});
|
|
|
|
|
if (state.limit) {
|
|
|
|
|
this.setState({
|
|
|
|
|
limit: state.limit,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 21:05:36 +12:00
|
|
|
setWindowTitle(i18n('library.artists.title'));
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-08-12 08:06:24 +12:00
|
|
|
this.getMopidyLibrary();
|
|
|
|
|
this.getGoogleLibrary();
|
|
|
|
|
this.getSpotifyLibrary();
|
|
|
|
|
}
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-08-12 08:06:24 +12:00
|
|
|
componentDidUpdate = ({ source: prevSource }) => {
|
|
|
|
|
const { source } = this.props;
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-08-12 08:06:24 +12:00
|
|
|
if (source !== prevSource) {
|
|
|
|
|
this.getMopidyLibrary();
|
|
|
|
|
this.getGoogleLibrary();
|
|
|
|
|
this.getSpotifyLibrary();
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-12 08:06:24 +12:00
|
|
|
getMopidyLibrary = () => {
|
2020-03-12 21:32:50 +13:00
|
|
|
const {
|
|
|
|
|
source,
|
|
|
|
|
mopidy_library_artists,
|
2020-08-12 08:06:24 +12:00
|
|
|
mopidyActions: {
|
|
|
|
|
getLibraryArtists,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
if (source !== 'local' && source !== 'all') return;
|
|
|
|
|
if (mopidy_library_artists) return;
|
|
|
|
|
|
|
|
|
|
getLibraryArtists();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getGoogleLibrary = () => {
|
|
|
|
|
const {
|
|
|
|
|
source,
|
|
|
|
|
google_available,
|
2020-03-12 21:32:50 +13:00
|
|
|
google_library_artists,
|
2020-08-12 08:06:24 +12:00
|
|
|
googleActions: {
|
|
|
|
|
getLibraryArtists,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
if (!google_available) return;
|
|
|
|
|
if (source !== 'google' && source !== 'all') return;
|
|
|
|
|
if (google_library_artists) return;
|
|
|
|
|
|
|
|
|
|
getLibraryArtists();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getSpotifyLibrary = () => {
|
|
|
|
|
const {
|
|
|
|
|
source,
|
|
|
|
|
spotify_available,
|
2020-03-12 21:32:50 +13:00
|
|
|
spotify_library_artists_status,
|
2020-08-12 08:06:24 +12:00
|
|
|
spotifyActions: {
|
|
|
|
|
getLibraryArtists,
|
|
|
|
|
},
|
2020-03-12 21:32:50 +13:00
|
|
|
} = this.props;
|
2020-05-12 20:32:48 +12:00
|
|
|
|
2020-08-12 08:06:24 +12:00
|
|
|
if (!spotify_available) return;
|
|
|
|
|
if (source !== 'spotify' && source !== 'all') return;
|
|
|
|
|
if (spotify_library_artists_status === 'finished') return;
|
|
|
|
|
if (spotify_library_artists_status === 'started') return;
|
|
|
|
|
|
|
|
|
|
getLibraryArtists();
|
|
|
|
|
};
|
2019-09-05 15:36:11 +12:00
|
|
|
|
|
|
|
|
handleContextMenu(e, item) {
|
|
|
|
|
const data = {
|
|
|
|
|
e,
|
|
|
|
|
context: 'artist',
|
|
|
|
|
uris: [item.uri],
|
|
|
|
|
items: [item],
|
|
|
|
|
};
|
|
|
|
|
this.props.uiActions.showContextMenu(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadMore() {
|
|
|
|
|
const new_limit = this.state.limit + this.state.per_page;
|
|
|
|
|
|
|
|
|
|
this.setState({ limit: new_limit });
|
|
|
|
|
|
|
|
|
|
// Set our pagination to location state
|
|
|
|
|
const state = (this.props.location && this.props.location.state ? this.props.location.state : {});
|
|
|
|
|
state.limit = new_limit;
|
|
|
|
|
this.props.history.replace({ state });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setSort(value) {
|
|
|
|
|
let reverse = false;
|
|
|
|
|
if (this.props.sort == value) reverse = !this.props.sort_reverse;
|
|
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
|
library_artists_sort_reverse: reverse,
|
|
|
|
|
library_artists_sort: value,
|
|
|
|
|
};
|
|
|
|
|
this.props.uiActions.set(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderView() {
|
|
|
|
|
let artists = [];
|
|
|
|
|
|
|
|
|
|
// Mopidy library items
|
|
|
|
|
if (this.props.mopidy_library_artists && (this.props.source == 'all' || this.props.source == 'local')) {
|
2019-10-09 09:42:20 +13:00
|
|
|
for (uri of this.props.mopidy_library_artists) {
|
2019-09-05 15:36:11 +12:00
|
|
|
// Construct item placeholder. This is used as Mopidy needs to
|
|
|
|
|
// lookup ref objects to get the full object which can take some time
|
2020-03-03 16:39:37 +13:00
|
|
|
var source = uriSource(uri);
|
2019-09-05 15:36:11 +12:00
|
|
|
var artist = {
|
|
|
|
|
uri,
|
|
|
|
|
source,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (this.props.artists.hasOwnProperty(uri)) {
|
|
|
|
|
artist = this.props.artists[uri];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
artists.push(artist);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Google library items
|
|
|
|
|
if (this.props.google_library_artists && (this.props.source == 'all' || this.props.source == 'google')) {
|
2019-10-09 09:42:20 +13:00
|
|
|
for (uri of this.props.google_library_artists) {
|
2019-09-05 15:36:11 +12:00
|
|
|
// Construct item placeholder. This is used as Mopidy needs to
|
|
|
|
|
// lookup ref objects to get the full object which can take some time
|
2020-03-03 16:39:37 +13:00
|
|
|
var source = uriSource(uri);
|
2019-09-05 15:36:11 +12:00
|
|
|
var artist = {
|
|
|
|
|
uri,
|
|
|
|
|
source,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (this.props.artists.hasOwnProperty(uri)) {
|
|
|
|
|
artist = this.props.artists[uri];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
artists.push(artist);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Spotify library items
|
|
|
|
|
if (this.props.spotify_library_artists && (this.props.source == 'all' || this.props.source == 'spotify')) {
|
|
|
|
|
for (let i = 0; i < this.props.spotify_library_artists.length; i++) {
|
|
|
|
|
var uri = this.props.spotify_library_artists[i];
|
|
|
|
|
if (this.props.artists.hasOwnProperty(uri)) {
|
|
|
|
|
artists.push(this.props.artists[uri]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.props.sort) {
|
2020-03-03 16:39:37 +13:00
|
|
|
artists = sortItems(artists, this.props.sort, this.props.sort_reverse);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.state.filter !== '') {
|
2020-03-03 16:39:37 +13:00
|
|
|
artists = applyFilter('name', this.state.filter, artists);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply our lazy-load-rendering
|
|
|
|
|
const total_artists = artists.length;
|
|
|
|
|
artists = artists.slice(0, this.state.limit);
|
|
|
|
|
|
|
|
|
|
if (this.props.view == 'list') {
|
|
|
|
|
return (
|
|
|
|
|
<section className="content-wrapper">
|
|
|
|
|
<List
|
|
|
|
|
handleContextMenu={(e, item) => this.handleContextMenu(e, item)}
|
|
|
|
|
rows={artists}
|
|
|
|
|
thumbnail
|
|
|
|
|
details={['followers']}
|
|
|
|
|
middle_column={['source']}
|
|
|
|
|
className="artists"
|
2019-10-09 09:42:20 +13:00
|
|
|
link_prefix="/artist/"
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
<LazyLoadListener
|
|
|
|
|
loadKey={total_artists > this.state.limit ? this.state.limit : total_artists}
|
|
|
|
|
showLoader={this.state.limit < total_artists}
|
2019-10-09 09:42:20 +13:00
|
|
|
loadMore={() => this.loadMore()}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<section className="content-wrapper">
|
|
|
|
|
<ArtistGrid
|
|
|
|
|
handleContextMenu={(e, item) => this.handleContextMenu(e, item)}
|
2019-10-09 09:42:20 +13:00
|
|
|
artists={artists}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
<LazyLoadListener
|
|
|
|
|
loadKey={total_artists > this.state.limit ? this.state.limit : total_artists}
|
|
|
|
|
showLoader={this.state.limit < total_artists}
|
2019-10-09 09:42:20 +13:00
|
|
|
loadMore={() => this.loadMore()}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
</section>
|
2019-10-09 09:42:20 +13:00
|
|
|
);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const source_options = [
|
|
|
|
|
{
|
|
|
|
|
value: 'all',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.all'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'local',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('services.mopidy.local'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2020-05-12 20:32:48 +12:00
|
|
|
if (this.props.spotify_available) {
|
2019-09-05 15:36:11 +12:00
|
|
|
source_options.push({
|
|
|
|
|
value: 'spotify',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('services.spotify.title'),
|
2019-09-05 15:36:11 +12:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 20:32:48 +12:00
|
|
|
if (this.props.google_available) {
|
2019-09-05 15:36:11 +12:00
|
|
|
source_options.push({
|
|
|
|
|
value: 'google',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('services.google.title'),
|
2019-09-05 15:36:11 +12:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const view_options = [
|
|
|
|
|
{
|
|
|
|
|
value: 'thumbnails',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.thumbnails'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'list',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.list'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const sort_options = [
|
|
|
|
|
{
|
|
|
|
|
value: null,
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.as_loaded'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'name',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.name'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'followers',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.followers'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'popularity',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.popularity'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const options = (
|
|
|
|
|
<span>
|
|
|
|
|
<FilterField
|
|
|
|
|
initialValue={this.state.filter}
|
2019-10-09 09:42:20 +13:00
|
|
|
handleChange={(value) => this.setState({ filter: value, limit: this.state.per_page })}
|
|
|
|
|
onSubmit={e => this.props.uiActions.hideContextMenu()}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
<DropdownField
|
2019-10-13 09:29:41 +13:00
|
|
|
icon="swap_vert"
|
2020-07-19 20:41:14 +12:00
|
|
|
name={i18n('fields.sort')}
|
2019-09-05 15:36:11 +12:00
|
|
|
value={this.props.sort}
|
2019-10-13 09:29:41 +13:00
|
|
|
valueAsLabel
|
2019-09-05 15:36:11 +12:00
|
|
|
options={sort_options}
|
|
|
|
|
selected_icon={this.props.sort ? (this.props.sort_reverse ? 'keyboard_arrow_up' : 'keyboard_arrow_down') : null}
|
2019-10-09 09:42:20 +13:00
|
|
|
handleChange={(value) => { this.setSort(value); this.props.uiActions.hideContextMenu(); }}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
<DropdownField
|
|
|
|
|
icon="visibility"
|
2020-07-19 20:41:14 +12:00
|
|
|
name={i18n('fields.view')}
|
2019-09-05 15:36:11 +12:00
|
|
|
value={this.props.view}
|
2019-10-13 09:29:41 +13:00
|
|
|
valueAsLabel
|
2019-09-05 15:36:11 +12:00
|
|
|
options={view_options}
|
2019-10-09 09:42:20 +13:00
|
|
|
handleChange={(value) => { this.props.uiActions.set({ library_artists_view: value }); this.props.uiActions.hideContextMenu(); }}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
<DropdownField
|
|
|
|
|
icon="cloud"
|
2020-07-19 20:41:14 +12:00
|
|
|
name={i18n('fields.source')}
|
2019-09-05 15:36:11 +12:00
|
|
|
value={this.props.source}
|
2019-10-13 09:29:41 +13:00
|
|
|
valueAsLabel
|
2019-09-05 15:36:11 +12:00
|
|
|
options={source_options}
|
2019-10-09 09:42:20 +13:00
|
|
|
handleChange={(value) => { this.props.uiActions.set({ library_artists_source: value }); this.props.uiActions.hideContextMenu(); }}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view library-artists-view">
|
|
|
|
|
<Header options={options} uiActions={this.props.uiActions}>
|
|
|
|
|
<Icon name="recent_actors" type="material" />
|
2020-07-19 20:41:14 +12:00
|
|
|
<I18n path="library.artists.title" />
|
2019-09-05 15:36:11 +12:00
|
|
|
</Header>
|
|
|
|
|
{this.renderView()}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
2020-08-12 08:06:24 +12:00
|
|
|
const mapStateToProps = (state) => ({
|
2019-09-05 15:36:11 +12:00
|
|
|
mopidy_uri_schemes: state.mopidy.uri_schemes,
|
|
|
|
|
mopidy_library_artists: state.mopidy.library_artists,
|
2020-05-12 20:32:48 +12:00
|
|
|
google_available: (state.mopidy.uri_schemes && state.mopidy.uri_schemes.includes('gmusic:')),
|
2019-09-05 15:36:11 +12:00
|
|
|
google_library_artists: state.google.library_artists,
|
2020-05-12 20:32:48 +12:00
|
|
|
spotify_available: state.spotify.access_token,
|
2019-09-05 15:36:11 +12:00
|
|
|
spotify_library_artists: state.spotify.library_artists,
|
|
|
|
|
spotify_library_artists_status: (state.ui.processes.SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR !== undefined ? state.ui.processes.SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR.status : null),
|
|
|
|
|
artists: state.core.artists,
|
|
|
|
|
source: (state.ui.library_artists_source ? state.ui.library_artists_source : 'all'),
|
|
|
|
|
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),
|
|
|
|
|
view: state.ui.library_artists_view,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch),
|
|
|
|
|
googleActions: bindActionCreators(googleActions, dispatch),
|
|
|
|
|
});
|
|
|
|
|
|
2019-10-09 09:42:20 +13:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LibraryArtists);
|