Mopidy local artists

This commit is contained in:
James Barnsley
2017-08-13 21:42:19 +12:00
parent 0fabc8daa9
commit 2dd08fa489
4 changed files with 155 additions and 17 deletions

View File

@ -22,18 +22,40 @@ class LibraryArtists extends React.Component{
}
componentDidMount(){
if (!this.props.spotify_library_artists && this.props.spotify_connected){
this.props.spotifyActions.getLibraryArtists()
if (!this.props.mopidy_library_artists && this.props.mopidy_connected && (this.props.filter == 'all' || this.props.filter == 'local')){
this.props.mopidyActions.getLibraryartists()
}
if (!this.props.spotify_library_artists && this.props.spotify_connected && (this.props.filter == 'all' || this.props.filter == 'spotify')){
this.props.spotifyActions.getLibraryartists()
}
}
componentWillReceiveProps(newProps){
if (newProps.spotify_connected){
if (newProps.mopidy_connected && (newProps.filter == 'all' || newProps.filter == 'local')){
// We've just connected
if (!this.props.mopidy_connected){
this.props.mopidyActions.getLibraryArtists()
}
// Filter changed, but we haven't got this provider's library yet
if (this.props.filter != 'all' && this.props.filter != 'local' && !newProps.mopidy_library_artists){
this.props.mopidyActions.getLibraryArtists()
}
}
if (newProps.spotify_connected && (newProps.filter == 'all' || newProps.filter == 'spotify')){
// We've just connected
if (!this.props.spotify_connected){
this.props.spotifyActions.getLibraryArtists()
}
// Filter changed, but we haven't got this provider's library yet
if (this.props.filter != 'all' && this.props.filter != 'spotify' && !newProps.spotify_library_artists){
this.props.spotifyActions.getLibraryArtists()
}
}
}
@ -98,6 +120,27 @@ class LibraryArtists extends React.Component{
render(){
var artists = []
// Mopidy library items
if (this.props.mopidy_library_artists && (this.props.filter == 'all' || this.props.filter == 'local')){
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)
}
}
// Spotify library items
if (this.props.spotify_library_artists){
for (var i = 0; i < this.props.spotify_library_artists.length; i++){
@ -110,6 +153,21 @@ class LibraryArtists extends React.Component{
artists = helpers.sortItems(artists, this.props.sort, this.props.sort_reverse)
var filter_options = [
{
value: 'all',
label: 'All'
},
{
value: 'local',
label: 'Local'
},
{
value: 'spotify',
label: 'Spotify'
}
]
var view_options = [
{
label: 'Thumbnails',
@ -138,6 +196,7 @@ class LibraryArtists extends React.Component{
var options = (
<span>
<DropdownField icon="filter" name="Filter" value={this.props.filter} options={filter_options} handleChange={val => {this.props.uiActions.set({ library_artists_filter: val}); this.props.uiActions.hideContextMenu() }} />
<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()}} />
</span>
@ -147,7 +206,6 @@ class LibraryArtists extends React.Component{
<div className="view library-artists-view">
<Header icon="mic" title="My artists" options={options} uiActions={this.props.uiActions} />
{ this.renderView(artists) }
<LazyLoadListener enabled={this.props.library_artists_more} loadMore={ () => this.loadMore() }/>
</div>
);
}
@ -162,9 +220,12 @@ class LibraryArtists extends React.Component{
const mapStateToProps = (state, ownProps) => {
return {
mopidy_connected: state.mopidy.connected,
spotify_connected: state.spotify.connected,
mopidy_library_artists: state.mopidy.library_artists,
spotify_library_artists: state.spotify.library_artists,
artists: state.core.artists,
filter: (state.ui.library_artists_filter ? state.ui.library_artists_filter : 'all'),
sort: (state.ui.library_artists_sort ? state.ui.library_artists_sort : 'name'),
sort_reverse: (state.ui.library_artists_sort_reverse ? true : false),
view: state.core.library_artists_view