Fixing spotify library artists/albums/tracks
This commit is contained in:
@ -480,7 +480,7 @@ export function getArtists( uris ){
|
||||
.then( response => {
|
||||
dispatch({
|
||||
type: 'SPOTIFY_ARTISTS_LOADED',
|
||||
data: response.artists
|
||||
data: response
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -496,7 +496,7 @@ export function getLibraryArtists(){
|
||||
.then( response => {
|
||||
dispatch({
|
||||
type: 'SPOTIFY_LIBRARY_ARTISTS_LOADED',
|
||||
data: response.artists
|
||||
data: response
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -58,32 +58,70 @@ export default function reducer(spotify = {}, action){
|
||||
return Object.assign({}, spotify, { me: action.data });
|
||||
|
||||
case 'SPOTIFY_ARTISTS_LOADED':
|
||||
return Object.assign({}, spotify, { artists: action.data });
|
||||
if( !action.data ) return Object.assign({}, spotify)
|
||||
return Object.assign({}, spotify, {
|
||||
artists: action.data.artists.items,
|
||||
artists_more: action.data.artists.next
|
||||
});
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED':
|
||||
return Object.assign({}, spotify, { library_artists: action.data });
|
||||
if( !action.data ) return Object.assign({}, spotify)
|
||||
return Object.assign({}, spotify, {
|
||||
library_artists: action.data.artists.items,
|
||||
library_artists_more: action.data.artists.next
|
||||
});
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED_MORE':
|
||||
return Object.assign({}, spotify, { library_artists: {
|
||||
href: action.data.artists.href,
|
||||
next: action.data.artists.next,
|
||||
previous: action.data.artists.previous,
|
||||
items: [ ...spotify.library_artists.items, ...action.data.artists.items ]
|
||||
}});
|
||||
return Object.assign({}, spotify, {
|
||||
library_artists: [ ...spotify.library_artists, ...action.data.artists.items ],
|
||||
library_artists_more: action.data.artists.next
|
||||
});
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED':
|
||||
return Object.assign({}, spotify, { library_albums: action.data });
|
||||
if( !action.data ) return Object.assign({}, spotify)
|
||||
return Object.assign({}, spotify, {
|
||||
library_albums: action.data.items,
|
||||
library_albums_more: action.data.next
|
||||
});
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED_MORE':
|
||||
return Object.assign({}, spotify, { library_albums: {
|
||||
href: action.data.href,
|
||||
next: action.data.next,
|
||||
previous: action.data.previous,
|
||||
items: [ ...spotify.library_albums.items, ...action.data.items ]
|
||||
}});
|
||||
return Object.assign({}, spotify, {
|
||||
library_albums: [...spotify.library_albums, ...action.data.items ],
|
||||
library_albums_more: action.data.next
|
||||
});
|
||||
|
||||
case 'SPOTIFY_LIBRARY_TRACKS_LOADED':
|
||||
return Object.assign({}, spotify, { library_tracks: action.data });
|
||||
if( !action.data ) return Object.assign({}, spotify)
|
||||
var tracks = Object.assign([], action.data.items)
|
||||
for( var i = 0; i < tracks.length; i++ ){
|
||||
tracks[i] = Object.assign(
|
||||
{},
|
||||
tracks[i].track,
|
||||
{
|
||||
added_at: tracks[i].added_at
|
||||
}
|
||||
)
|
||||
}
|
||||
return Object.assign({}, spotify, {
|
||||
library_tracks: tracks,
|
||||
library_tracks_more: action.data.next
|
||||
});
|
||||
|
||||
case 'SPOTIFY_LIBRARY_TRACKS_LOADED_MORE':
|
||||
var tracks = Object.assign([], action.data.items)
|
||||
for( var i = 0; i < tracks.length; i++ ){
|
||||
tracks[i] = Object.assign(
|
||||
{},
|
||||
tracks[i].track,
|
||||
{
|
||||
added_at: tracks[i].added_at
|
||||
}
|
||||
)
|
||||
}
|
||||
return Object.assign({}, spotify, {
|
||||
library_tracks: tracks,
|
||||
library_tracks_more: action.data.next
|
||||
});
|
||||
|
||||
case 'SPOTIFY_FEATURED_PLAYLISTS_LOADED':
|
||||
return Object.assign({}, spotify, { featured_playlists: action.data });
|
||||
|
||||
@ -22,8 +22,8 @@ class LibraryAlbums extends React.Component{
|
||||
}
|
||||
|
||||
loadMore(){
|
||||
if( !this.props.spotify.library_albums || !this.props.spotify.library_albums.next ) return
|
||||
this.props.spotifyActions.getURL( this.props.spotify.library_albums.next, 'SPOTIFY_LIBRARY_ALBUMS_LOADED_MORE' );
|
||||
if( !this.props.spotify.library_albums_more ) return
|
||||
this.props.spotifyActions.getURL( this.props.spotify.library_albums_more, 'SPOTIFY_LIBRARY_ALBUMS_LOADED_MORE' );
|
||||
}
|
||||
|
||||
render(){
|
||||
@ -34,7 +34,7 @@ class LibraryAlbums extends React.Component{
|
||||
title="My albums"
|
||||
/>
|
||||
<section className="grid-wrapper">
|
||||
{ this.props.spotify.library_albums ? <AlbumGrid albums={this.props.spotify.library_albums.items} /> : null }
|
||||
{ this.props.spotify.library_albums ? <AlbumGrid albums={this.props.spotify.library_albums} /> : null }
|
||||
</section>
|
||||
<LazyLoadListener loadMore={ () => this.loadMore() }/>
|
||||
</div>
|
||||
|
||||
@ -23,19 +23,16 @@ class LibraryArtists extends React.Component{
|
||||
}
|
||||
|
||||
loadMore(){
|
||||
if( !this.props.spotify.library_artists || !this.props.spotify.library_artists.next ) return
|
||||
this.props.spotifyActions.getURL( this.props.spotify.library_artists.next, 'SPOTIFY_LIBRARY_ARTISTS_LOADED_MORE' );
|
||||
if( !this.props.spotify.library_artists_more ) return
|
||||
this.props.spotifyActions.getURL( this.props.spotify.library_artists_more, 'SPOTIFY_LIBRARY_ARTISTS_LOADED_MORE' );
|
||||
}
|
||||
|
||||
render(){
|
||||
return (
|
||||
<div className="view library-artists-view">
|
||||
<Header
|
||||
icon="mic"
|
||||
title="My artists"
|
||||
/>
|
||||
<Header icon="mic" title="My artists" />
|
||||
<section className="grid-wrapper">
|
||||
{ this.props.spotify.library_artists ? <ArtistGrid artists={this.props.spotify.library_artists.items} /> : null }
|
||||
{ this.props.spotify.library_artists ? <ArtistGrid artists={this.props.spotify.library_artists} /> : null }
|
||||
</section>
|
||||
<LazyLoadListener loadMore={ () => this.loadMore() }/>
|
||||
</div>
|
||||
|
||||
@ -6,6 +6,7 @@ import { Link } from 'react-router'
|
||||
|
||||
import TrackList from '../../components/TrackList'
|
||||
import Header from '../../components/Header'
|
||||
import LazyLoadListener from '../../components/LazyLoadListener'
|
||||
|
||||
import * as mopidyActions from '../../services/mopidy/actions'
|
||||
import * as spotifyActions from '../../services/spotify/actions'
|
||||
@ -21,13 +22,19 @@ class LibraryTracks extends React.Component{
|
||||
this.props.spotifyActions.getLibraryTracks();
|
||||
}
|
||||
|
||||
loadMore(){
|
||||
if( !this.props.spotify.library_tracks_more ) return
|
||||
this.props.spotifyActions.getURL( this.props.spotify.library_tracks_more, 'SPOTIFY_LIBRARY_TRACKS_LOADED_MORE' );
|
||||
}
|
||||
|
||||
render(){
|
||||
return (
|
||||
<div className="view library-tracks-view">
|
||||
<Header icon="music" title="My tracks" />
|
||||
<section className="list-wrapper">
|
||||
{ this.props.spotify.library_tracks ? <TrackList tracks={this.props.spotify.library_tracks.items} /> : null }
|
||||
{ this.props.spotify.library_tracks ? <TrackList tracks={this.props.spotify.library_tracks} /> : null }
|
||||
</section>
|
||||
<LazyLoadListener loadMore={ () => this.loadMore() }/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user