Categories using index now too
This commit is contained in:
@ -334,7 +334,7 @@ const MopidyMiddleware = (function(){
|
||||
|
||||
store.dispatch({
|
||||
type: 'PLAYLIST_LOADED',
|
||||
uri: playlist.uri,
|
||||
key: playlist.uri,
|
||||
playlist: playlist
|
||||
})
|
||||
})
|
||||
@ -357,11 +357,15 @@ const MopidyMiddleware = (function(){
|
||||
)
|
||||
|
||||
// tracks? get the full track objects
|
||||
if( playlist.tracks.length > 0 ) store.dispatch({ type: 'MOPIDY_RESOLVE_PLAYLIST_TRACKS', tracks: playlist.tracks, uri: response.uri })
|
||||
if( playlist.tracks.length > 0 ) store.dispatch({
|
||||
type: 'MOPIDY_RESOLVE_PLAYLIST_TRACKS',
|
||||
tracks: playlist.tracks,
|
||||
key: response.uri
|
||||
})
|
||||
|
||||
store.dispatch({
|
||||
type: 'PLAYLIST_LOADED',
|
||||
uri: playlist.uri,
|
||||
key: playlist.uri,
|
||||
playlist: playlist
|
||||
})
|
||||
})
|
||||
@ -397,7 +401,7 @@ const MopidyMiddleware = (function(){
|
||||
store.dispatch({
|
||||
type: 'PLAYLIST_TRACKS',
|
||||
tracks: tracks,
|
||||
uri: action.uri
|
||||
key: action.key
|
||||
})
|
||||
})
|
||||
break
|
||||
@ -423,7 +427,11 @@ const MopidyMiddleware = (function(){
|
||||
|
||||
instruct( socket, store, 'playlists.save', { playlist: playlist } )
|
||||
.then( response => {
|
||||
store.dispatch({ type: 'PLAYLIST_TRACKS_ADDED', uri: action.uri, tracks_uris: action.tracks_uris });
|
||||
store.dispatch({
|
||||
type: 'PLAYLIST_TRACKS_ADDED',
|
||||
key: action.uri,
|
||||
tracks_uris: action.tracks_uris
|
||||
});
|
||||
})
|
||||
});
|
||||
break
|
||||
@ -445,7 +453,11 @@ const MopidyMiddleware = (function(){
|
||||
}
|
||||
instruct( socket, store, 'playlists.save', { playlist: playlist } )
|
||||
.then( response => {
|
||||
store.dispatch({ type: 'PLAYLIST_TRACKS_REMOVED', uri: action.uri, tracks_indexes: action.tracks_indexes });
|
||||
store.dispatch({
|
||||
type: 'PLAYLIST_TRACKS_REMOVED',
|
||||
key: action.uri,
|
||||
tracks_indexes: action.tracks_indexes
|
||||
});
|
||||
})
|
||||
});
|
||||
break
|
||||
@ -458,7 +470,7 @@ const MopidyMiddleware = (function(){
|
||||
.then( response => {
|
||||
store.dispatch({
|
||||
type: 'PLAYLIST_UPDATED',
|
||||
uri: action.uri,
|
||||
key: action.uri,
|
||||
playlist: playlist
|
||||
})
|
||||
})
|
||||
@ -499,7 +511,11 @@ const MopidyMiddleware = (function(){
|
||||
instruct( socket, store, 'playlists.save', { playlist: playlist } )
|
||||
.then( response => {
|
||||
|
||||
store.dispatch({ type: 'MOPIDY_RESOLVE_PLAYLIST_TRACKS', tracks: playlist.tracks, uri: playlist.uri })
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_RESOLVE_PLAYLIST_TRACKS',
|
||||
tracks: playlist.tracks,
|
||||
key: playlist.uri
|
||||
})
|
||||
})
|
||||
});
|
||||
break
|
||||
@ -596,7 +612,7 @@ const MopidyMiddleware = (function(){
|
||||
|
||||
store.dispatch({
|
||||
type: 'ALBUM_LOADED',
|
||||
uri: album.uri,
|
||||
key: album.uri,
|
||||
album: album
|
||||
});
|
||||
})
|
||||
@ -659,7 +675,7 @@ const MopidyMiddleware = (function(){
|
||||
|
||||
store.dispatch({
|
||||
type: 'ARTIST_LOADED',
|
||||
uri: artist.uri,
|
||||
key: artist.uri,
|
||||
artist: artist
|
||||
});
|
||||
|
||||
@ -684,7 +700,10 @@ const MopidyMiddleware = (function(){
|
||||
store.dispatch({ type: 'MOPIDY_DIRECTORY_LOADED', data: false });
|
||||
instruct( socket, store, 'library.browse', action.data )
|
||||
.then( response => {
|
||||
store.dispatch({ type: 'MOPIDY_DIRECTORY_LOADED', data: response });
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_DIRECTORY_LOADED',
|
||||
data: response
|
||||
});
|
||||
})
|
||||
break;
|
||||
|
||||
|
||||
@ -292,14 +292,11 @@ export function getFeaturedPlaylists(){
|
||||
|
||||
export function getCategories(){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
dispatch({ type: 'SPOTIFY_CATEGORIES_LOADED', data: false });
|
||||
|
||||
sendRequest( dispatch, getState, 'browse/categories?limit=50&country='+getState().spotify.country+'&locale='+getState().spotify.locale )
|
||||
.then( response => {
|
||||
dispatch({
|
||||
type: 'SPOTIFY_CATEGORIES_LOADED',
|
||||
data: response.categories
|
||||
type: 'CATEGORIES_LOADED',
|
||||
categories: response.categories.items
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -308,49 +305,45 @@ export function getCategories(){
|
||||
export function getCategory( id ){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
dispatch({ type: 'SPOTIFY_CATEGORY_LOADED', data: false });
|
||||
// get the category
|
||||
sendRequest( dispatch, getState, 'browse/categories/'+id+'?country='+getState().spotify.country+'&locale='+getState().spotify.locale )
|
||||
.then( response => {
|
||||
var category = Object.assign({}, response)
|
||||
dispatch({
|
||||
type: 'CATEGORY_LOADED',
|
||||
key: 'category:'+id,
|
||||
category: Object.assign({}, response)
|
||||
});
|
||||
})
|
||||
|
||||
$.when(
|
||||
// and the category's playlists
|
||||
sendRequest( dispatch, getState, 'browse/categories/'+id+'/playlists?limit=50&country='+getState().spotify.country+'&locale='+getState().spotify.locale )
|
||||
.then( response => {
|
||||
|
||||
sendRequest( dispatch, getState, 'browse/categories/'+id+'?country='+getState().spotify.country+'&locale='+getState().spotify.locale ),
|
||||
sendRequest( dispatch, getState, 'browse/categories/'+id+'/playlists?limit=50&country='+getState().spotify.country+'&locale='+getState().spotify.locale )
|
||||
|
||||
).then( ( category_response, playlists_response ) => {
|
||||
|
||||
var playlists = []
|
||||
for (var i = 0; i < playlists_response.playlists.items.length; i++){
|
||||
playlists.push(Object.assign(
|
||||
{},
|
||||
playlists_response.playlists.items[i],
|
||||
{
|
||||
tracks: null,
|
||||
tracks_more: null,
|
||||
tracks_total: playlists_response.playlists.items[i].tracks.total
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: 'PLAYLISTS_LOADED',
|
||||
playlists: playlists
|
||||
});
|
||||
|
||||
var category = Object.assign(
|
||||
{},
|
||||
category_response,
|
||||
{
|
||||
items: false,
|
||||
playlists: helpers.asURIs(playlists_response.playlists.items),
|
||||
playlists_more: playlists_response.playlists.next,
|
||||
playlists_total: playlists_response.playlists.total
|
||||
var playlists = []
|
||||
for (var i = 0; i < response.playlists.items.length; i++){
|
||||
playlists.push(Object.assign(
|
||||
{},
|
||||
response.playlists.items[i],
|
||||
{
|
||||
tracks: null,
|
||||
tracks_more: null,
|
||||
tracks_total: response.playlists.items[i].tracks.total
|
||||
}
|
||||
))
|
||||
}
|
||||
)
|
||||
|
||||
dispatch({
|
||||
type: 'SPOTIFY_CATEGORY_LOADED',
|
||||
data: category
|
||||
});
|
||||
});
|
||||
dispatch({
|
||||
type: 'PLAYLISTS_LOADED',
|
||||
playlists: playlists
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED',
|
||||
key: 'category:'+id,
|
||||
data: response
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -366,13 +359,13 @@ export function getNewReleases(){
|
||||
}
|
||||
}
|
||||
|
||||
export function getURL( url, action_name, uri = false ){
|
||||
export function getURL( url, action_name, key = false ){
|
||||
return (dispatch, getState) => {
|
||||
sendRequest( dispatch, getState, url )
|
||||
.then( response => {
|
||||
dispatch({
|
||||
type: action_name,
|
||||
uri: uri,
|
||||
key: key,
|
||||
data: response
|
||||
});
|
||||
});
|
||||
@ -479,7 +472,7 @@ export function following(uri, method = 'GET'){
|
||||
if( typeof(is_following) === 'object' ) is_following = is_following[0]
|
||||
dispatch({
|
||||
type: 'SPOTIFY_'+asset_name.toUpperCase()+'_FOLLOWING_LOADED',
|
||||
uri: uri,
|
||||
key: uri,
|
||||
is_following: is_following
|
||||
});
|
||||
});
|
||||
@ -642,7 +635,7 @@ export function getArtist( uri ){
|
||||
).then( () => {
|
||||
dispatch({
|
||||
type: 'ARTIST_LOADED',
|
||||
uri: artist.uri,
|
||||
key: artist.uri,
|
||||
artist: artist
|
||||
});
|
||||
|
||||
@ -652,7 +645,7 @@ export function getArtist( uri ){
|
||||
dispatch({
|
||||
type: 'SPOTIFY_ARTIST_ALBUMS_LOADED',
|
||||
data: response,
|
||||
uri: uri
|
||||
key: uri
|
||||
});
|
||||
})
|
||||
});
|
||||
@ -718,7 +711,7 @@ export function getUser( uri ){
|
||||
.then( response => {
|
||||
dispatch({
|
||||
type: 'USER_LOADED',
|
||||
uri: response.uri,
|
||||
key: response.uri,
|
||||
user: response
|
||||
});
|
||||
})
|
||||
@ -746,7 +739,7 @@ export function getUser( uri ){
|
||||
|
||||
dispatch({
|
||||
type: 'SPOTIFY_USER_PLAYLISTS_LOADED',
|
||||
uri: uri,
|
||||
key: uri,
|
||||
data: response
|
||||
});
|
||||
})
|
||||
@ -800,7 +793,7 @@ export function getAlbum( uri ){
|
||||
|
||||
dispatch({
|
||||
type: 'ALBUM_LOADED',
|
||||
uri: album.uri,
|
||||
key: album.uri,
|
||||
album: album
|
||||
});
|
||||
|
||||
@ -848,7 +841,7 @@ export function toggleAlbumInLibrary( uri, method ){
|
||||
.then( response => {
|
||||
dispatch({
|
||||
type: 'SPOTIFY_ALBUM_FOLLOWING',
|
||||
uri: uri,
|
||||
key: uri,
|
||||
data: new_state
|
||||
});
|
||||
});
|
||||
@ -910,7 +903,7 @@ export function getPlaylist( uri ){
|
||||
|
||||
dispatch({
|
||||
type: 'PLAYLIST_LOADED',
|
||||
uri: playlist.uri,
|
||||
key: playlist.uri,
|
||||
playlist: playlist
|
||||
})
|
||||
})
|
||||
@ -950,7 +943,7 @@ export function toggleFollowingPlaylist( uri, method ){
|
||||
.then( response => {
|
||||
dispatch({
|
||||
type: 'SPOTIFY_PLAYLIST_FOLLOWING',
|
||||
uri: uri,
|
||||
key: uri,
|
||||
data: new_state
|
||||
});
|
||||
});
|
||||
@ -963,7 +956,7 @@ export function addTracksToPlaylist( uri, tracks_uris ){
|
||||
.then( response => {
|
||||
dispatch({
|
||||
type: 'PLAYLIST_TRACKS_ADDED',
|
||||
uri: uri,
|
||||
key: uri,
|
||||
tracks_uris: tracks_uris,
|
||||
snapshot_id: response.snapshot_id
|
||||
});
|
||||
@ -977,7 +970,7 @@ export function deleteTracksFromPlaylist( uri, snapshot_id, tracks_indexes ){
|
||||
.then( response => {
|
||||
dispatch({
|
||||
type: 'PLAYLIST_TRACKS_REMOVED',
|
||||
uri: uri,
|
||||
key: uri,
|
||||
tracks_indexes: tracks_indexes,
|
||||
snapshot_id: response.snapshot_id
|
||||
});
|
||||
@ -991,7 +984,7 @@ export function reorderPlaylistTracks( uri, range_start, range_length, insert_be
|
||||
.then( response => {
|
||||
dispatch({
|
||||
type: 'PLAYLIST_TRACKS_REORDERED',
|
||||
uri: uri,
|
||||
key: uri,
|
||||
range_start: range_start,
|
||||
range_length: range_length,
|
||||
insert_before: insert_before,
|
||||
|
||||
@ -96,7 +96,7 @@ const SpotifyMiddleware = (function(){
|
||||
case 'SPOTIFY_PLAYLIST_FOLLOWING_LOADED':
|
||||
store.dispatch({
|
||||
type: 'PLAYLIST_LOADED',
|
||||
uri: action.uri,
|
||||
key: action.key,
|
||||
playlist: {
|
||||
is_following: action.is_following
|
||||
}
|
||||
@ -106,7 +106,7 @@ const SpotifyMiddleware = (function(){
|
||||
case 'SPOTIFY_ALBUM_FOLLOWING_LOADED':
|
||||
store.dispatch({
|
||||
type: 'ALBUM_LOADED',
|
||||
uri: action.uri,
|
||||
key: action.key,
|
||||
album: {
|
||||
is_following: action.is_following
|
||||
}
|
||||
@ -116,7 +116,7 @@ const SpotifyMiddleware = (function(){
|
||||
case 'SPOTIFY_ARTIST_FOLLOWING_LOADED':
|
||||
store.dispatch({
|
||||
type: 'ARTIST_LOADED',
|
||||
uri: action.uri,
|
||||
key: action.key,
|
||||
artist: {
|
||||
is_following: action.is_following
|
||||
}
|
||||
@ -126,7 +126,7 @@ const SpotifyMiddleware = (function(){
|
||||
case 'SPOTIFY_USER_FOLLOWING_LOADED':
|
||||
store.dispatch({
|
||||
type: 'USER_LOADED',
|
||||
uri: action.uri,
|
||||
key: action.key,
|
||||
user: {
|
||||
is_following: action.is_following
|
||||
}
|
||||
@ -153,7 +153,7 @@ const SpotifyMiddleware = (function(){
|
||||
});
|
||||
store.dispatch({
|
||||
type: 'ARTIST_ALBUMS_LOADED',
|
||||
uri: action.uri,
|
||||
key: action.key,
|
||||
uris: helpers.asURIs(action.data.items),
|
||||
more: action.data.next,
|
||||
total: action.data.total
|
||||
@ -185,13 +185,45 @@ const SpotifyMiddleware = (function(){
|
||||
|
||||
store.dispatch({
|
||||
type: 'USER_PLAYLISTS_LOADED',
|
||||
uri: action.uri,
|
||||
key: action.key,
|
||||
uris: helpers.asURIs(playlists),
|
||||
more: action.data.next,
|
||||
total: action.data.total
|
||||
});
|
||||
break
|
||||
|
||||
case 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED':
|
||||
var playlists = []
|
||||
for( var i = 0; i < action.data.playlists.items.length; i++ ){
|
||||
var playlist = Object.assign(
|
||||
{},
|
||||
action.data.playlists.items[i],
|
||||
{
|
||||
can_edit: (store.getState().spotify.authorized && store.getState().spotify.me && action.data.playlists.items[i].owner.id == store.getState().spotify.me.id),
|
||||
tracks_total: action.data.playlists.items[i].tracks.total
|
||||
}
|
||||
)
|
||||
|
||||
// remove our tracklist. It'll overwrite any full records otherwise
|
||||
delete playlist.tracks
|
||||
|
||||
playlists.push(playlist)
|
||||
}
|
||||
|
||||
store.dispatch({
|
||||
type: 'PLAYLISTS_LOADED',
|
||||
playlists: playlists
|
||||
});
|
||||
|
||||
store.dispatch({
|
||||
type: 'CATEGORY_PLAYLISTS_LOADED',
|
||||
key: action.key,
|
||||
uris: helpers.asURIs(playlists),
|
||||
more: action.data.playlists.next,
|
||||
total: action.data.playlists.total
|
||||
});
|
||||
break
|
||||
|
||||
case 'SPOTIFY_LIBRARY_PLAYLISTS_LOADED':
|
||||
var playlists = []
|
||||
for( var i = 0; i < action.playlists.length; i++ ){
|
||||
|
||||
@ -150,21 +150,6 @@ export default function reducer(spotify = {}, action){
|
||||
case 'SPOTIFY_FEATURED_PLAYLISTS_LOADED':
|
||||
return Object.assign({}, spotify, { featured_playlists: action.data })
|
||||
|
||||
case 'SPOTIFY_CATEGORIES_LOADED':
|
||||
return Object.assign({}, spotify, { categories: action.data })
|
||||
|
||||
case 'SPOTIFY_CATEGORY_LOADED':
|
||||
return Object.assign({}, spotify, { category: action.data })
|
||||
|
||||
// TODO: update this
|
||||
case 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED_MORE':
|
||||
return Object.assign({}, spotify, { category_playlists: {
|
||||
href: action.data.href,
|
||||
next: action.data.next,
|
||||
previous: action.data.previous,
|
||||
items: [ ...spotify.category_playlists.items, ...action.data.items ]
|
||||
}})
|
||||
|
||||
case 'SPOTIFY_NEW_RELEASES_LOADED':
|
||||
return Object.assign({}, spotify, { new_releases: action.data });
|
||||
|
||||
|
||||
@ -71,14 +71,14 @@ export function set( data ){
|
||||
}
|
||||
}
|
||||
|
||||
export function reorderPlaylistTracks( uri, indexes, insert_before, snapshot_id = false ){
|
||||
export function reorderPlaylistTracks( key, indexes, insert_before, snapshot_id = false ){
|
||||
var range = helpers.createRange( indexes );
|
||||
switch( helpers.uriSource( uri ) ){
|
||||
switch( helpers.uriSource( key ) ){
|
||||
|
||||
case 'spotify':
|
||||
return {
|
||||
type: 'SPOTIFY_REORDER_PLAYLIST_TRACKS',
|
||||
uri: uri,
|
||||
key: key,
|
||||
range_start: range.start,
|
||||
range_length: range.length,
|
||||
insert_before: insert_before,
|
||||
@ -88,7 +88,7 @@ export function reorderPlaylistTracks( uri, indexes, insert_before, snapshot_id
|
||||
case 'm3u':
|
||||
return {
|
||||
type: 'MOPIDY_REORDER_PLAYLIST_TRACKS',
|
||||
uri: uri,
|
||||
key: key,
|
||||
range_start: range.start,
|
||||
range_length: range.length,
|
||||
insert_before: insert_before
|
||||
@ -96,13 +96,13 @@ export function reorderPlaylistTracks( uri, indexes, insert_before, snapshot_id
|
||||
}
|
||||
}
|
||||
|
||||
export function savePlaylist( uri, name, is_public = false ){
|
||||
switch( helpers.uriSource( uri ) ){
|
||||
export function savePlaylist( key, name, is_public = false ){
|
||||
switch( helpers.uriSource( key ) ){
|
||||
|
||||
case 'spotify':
|
||||
return {
|
||||
type: 'SPOTIFY_SAVE_PLAYLIST',
|
||||
uri: uri,
|
||||
key: key,
|
||||
name: name,
|
||||
is_public: is_public
|
||||
}
|
||||
@ -110,7 +110,7 @@ export function savePlaylist( uri, name, is_public = false ){
|
||||
case 'm3u':
|
||||
return {
|
||||
type: 'MOPIDY_SAVE_PLAYLIST',
|
||||
uri: uri,
|
||||
key: key,
|
||||
name: name
|
||||
}
|
||||
}
|
||||
@ -137,39 +137,39 @@ export function createPlaylist( scheme, name, is_public = false ){
|
||||
return false
|
||||
}
|
||||
|
||||
export function removeTracksFromPlaylist( uri, tracks_indexes ){
|
||||
switch( helpers.uriSource( uri ) ){
|
||||
export function removeTracksFromPlaylist( key, tracks_indexes ){
|
||||
switch( helpers.uriSource( key ) ){
|
||||
|
||||
case 'spotify':
|
||||
return {
|
||||
type: 'SPOTIFY_REMOVE_PLAYLIST_TRACKS',
|
||||
uri: uri,
|
||||
key: key,
|
||||
tracks_indexes: tracks_indexes
|
||||
}
|
||||
|
||||
case 'm3u':
|
||||
return {
|
||||
type: 'MOPIDY_REMOVE_PLAYLIST_TRACKS',
|
||||
uri: uri,
|
||||
key: key,
|
||||
tracks_indexes: tracks_indexes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function addTracksToPlaylist( uri, tracks_uris ){
|
||||
switch( helpers.uriSource( uri ) ){
|
||||
export function addTracksToPlaylist( key, tracks_uris ){
|
||||
switch( helpers.uriSource( key ) ){
|
||||
|
||||
case 'spotify':
|
||||
return {
|
||||
type: 'SPOTIFY_ADD_PLAYLIST_TRACKS',
|
||||
uri: uri,
|
||||
key: key,
|
||||
tracks_uris: tracks_uris
|
||||
}
|
||||
|
||||
case 'm3u':
|
||||
return {
|
||||
type: 'MOPIDY_ADD_PLAYLIST_TRACKS',
|
||||
uri: uri,
|
||||
key: key,
|
||||
tracks_uris: tracks_uris
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,6 +125,57 @@ export default function reducer(ui = {}, action){
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Categories
|
||||
**/
|
||||
|
||||
case 'CATEGORY_LOADED':
|
||||
var categories = Object.assign([], ui.categories)
|
||||
|
||||
if (categories[action.key]){
|
||||
var category = Object.assign({}, categories[action.key], action.category)
|
||||
}else{
|
||||
var category = Object.assign({}, action.category)
|
||||
}
|
||||
|
||||
categories[action.key] = category
|
||||
return Object.assign({}, ui, { categories: categories });
|
||||
|
||||
case 'CATEGORIES_LOADED':
|
||||
var categories = Object.assign([], ui.categories)
|
||||
|
||||
for (var i = 0; i < action.categories.length; i++){
|
||||
var key = 'category:'+action.categories[i].id
|
||||
if (categories[key]){
|
||||
var category = Object.assign({}, categories[key], action.categories[i])
|
||||
}else{
|
||||
var category = Object.assign({}, action.categories[i])
|
||||
}
|
||||
categories[key] = category
|
||||
}
|
||||
|
||||
return Object.assign({}, ui, { categories: categories });
|
||||
|
||||
case 'CATEGORY_PLAYLISTS_LOADED':
|
||||
var categories = Object.assign([], ui.categories)
|
||||
var playlists_uris = []
|
||||
if (categories[action.key].playlists_uris) playlists_uris = categories[action.key].playlists_uris
|
||||
|
||||
var category = Object.assign(
|
||||
{},
|
||||
categories[action.key],
|
||||
{
|
||||
playlists_uris: [...playlists_uris, ...action.uris],
|
||||
playlists_more: action.more,
|
||||
playlists_total: action.total
|
||||
}
|
||||
)
|
||||
categories[action.key] = category
|
||||
return Object.assign({}, ui, { categories: categories });
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Albums
|
||||
**/
|
||||
@ -132,13 +183,13 @@ export default function reducer(ui = {}, action){
|
||||
case 'ALBUM_LOADED':
|
||||
var albums = Object.assign([], ui.albums)
|
||||
|
||||
if (albums[action.uri]){
|
||||
var album = Object.assign({}, albums[action.uri], action.album)
|
||||
if (albums[action.key]){
|
||||
var album = Object.assign({}, albums[action.key], action.album)
|
||||
}else{
|
||||
var album = Object.assign({}, action.album)
|
||||
}
|
||||
|
||||
albums[action.uri] = album
|
||||
albums[action.key] = album
|
||||
return Object.assign({}, ui, { albums: albums });
|
||||
|
||||
case 'ALBUMS_LOADED':
|
||||
@ -203,16 +254,16 @@ export default function reducer(ui = {}, action){
|
||||
case 'ARTIST_LOADED':
|
||||
var artists = Object.assign([], ui.artists)
|
||||
|
||||
if (artists[action.uri]){
|
||||
if (artists[action.key]){
|
||||
// if we've already got images, delete our new ones
|
||||
// this is to prevent LastFM overwriting Spotify images
|
||||
if (artists[action.uri].images) delete action.artist.images
|
||||
var artist = Object.assign({}, artists[action.uri], action.artist)
|
||||
if (artists[action.key].images) delete action.artist.images
|
||||
var artist = Object.assign({}, artists[action.key], action.artist)
|
||||
}else{
|
||||
var artist = Object.assign({}, action.artist)
|
||||
}
|
||||
|
||||
artists[action.uri] = artist
|
||||
artists[action.key] = artist
|
||||
return Object.assign({}, ui, { artists: artists });
|
||||
|
||||
case 'ARTISTS_LOADED':
|
||||
@ -231,18 +282,18 @@ export default function reducer(ui = {}, action){
|
||||
case 'ARTIST_ALBUMS_LOADED':
|
||||
var artists = Object.assign([], ui.artists)
|
||||
var albums_uris = []
|
||||
if (artists[action.uri].albums_uris) albums_uris = artists[action.uri].albums_uris
|
||||
if (artists[action.key].albums_uris) albums_uris = artists[action.key].albums_uris
|
||||
|
||||
var artist = Object.assign(
|
||||
{},
|
||||
artists[action.uri],
|
||||
artists[action.key],
|
||||
{
|
||||
albums_uris: [...albums_uris, ...action.uris],
|
||||
albums_more: action.more,
|
||||
albums_total: action.total
|
||||
}
|
||||
)
|
||||
artists[action.uri] = artist
|
||||
artists[action.key] = artist
|
||||
return Object.assign({}, ui, { artists: artists });
|
||||
|
||||
case 'LIBRARY_ARTISTS_LOADED':
|
||||
@ -275,30 +326,30 @@ export default function reducer(ui = {}, action){
|
||||
case 'USER_LOADED':
|
||||
var users = Object.assign([], ui.users)
|
||||
|
||||
if (users[action.uri]){
|
||||
var user = Object.assign({}, users[action.uri], action.user)
|
||||
if (users[action.key]){
|
||||
var user = Object.assign({}, users[action.key], action.user)
|
||||
}else{
|
||||
var user = Object.assign({}, action.user)
|
||||
}
|
||||
|
||||
users[action.uri] = user
|
||||
users[action.key] = user
|
||||
return Object.assign({}, ui, { users: users });
|
||||
|
||||
case 'USER_PLAYLISTS_LOADED':
|
||||
var users = Object.assign([], ui.users)
|
||||
var playlists_uris = []
|
||||
if (users[action.uri].playlists_uris) playlists_uris = users[action.uri].playlists_uris
|
||||
if (users[action.key].playlists_uris) playlists_uris = users[action.key].playlists_uris
|
||||
|
||||
var artist = Object.assign(
|
||||
{},
|
||||
users[action.uri],
|
||||
users[action.key],
|
||||
{
|
||||
playlists_uris: [...playlists_uris, ...action.uris],
|
||||
playlists_more: action.more,
|
||||
playlists_total: action.total
|
||||
}
|
||||
)
|
||||
users[action.uri] = artist
|
||||
users[action.key] = artist
|
||||
return Object.assign({}, ui, { users: users });
|
||||
|
||||
|
||||
@ -312,13 +363,13 @@ export default function reducer(ui = {}, action){
|
||||
case 'PLAYLIST_UPDATED':
|
||||
var playlists = Object.assign([], ui.playlists)
|
||||
|
||||
if (playlists[action.uri]){
|
||||
var playlist = Object.assign({}, playlists[action.uri], action.playlist)
|
||||
if (playlists[action.key]){
|
||||
var playlist = Object.assign({}, playlists[action.key], action.playlist)
|
||||
}else{
|
||||
var playlist = Object.assign({}, action.playlist)
|
||||
}
|
||||
|
||||
playlists[action.uri] = playlist
|
||||
playlists[action.key] = playlist
|
||||
return Object.assign({}, ui, { playlists: playlists });
|
||||
|
||||
case 'PLAYLISTS_LOADED':
|
||||
@ -342,20 +393,20 @@ export default function reducer(ui = {}, action){
|
||||
var playlists = Object.assign([], ui.playlists)
|
||||
var playlist = Object.assign(
|
||||
{},
|
||||
playlists[action.uri],
|
||||
playlists[action.key],
|
||||
{
|
||||
tracks: [...playlists[action.uri].tracks, ...helpers.flattenTracks(action.data.items)],
|
||||
tracks: [...playlists[action.key].tracks, ...helpers.flattenTracks(action.data.items)],
|
||||
tracks_more: action.data.next,
|
||||
tracks_total: action.data.total
|
||||
}
|
||||
)
|
||||
|
||||
playlists[action.uri] = playlist
|
||||
playlists[action.key] = playlist
|
||||
return Object.assign({}, ui, { playlists: playlists });
|
||||
|
||||
case 'PLAYLIST_TRACKS_REMOVED':
|
||||
var playlists = Object.assign([], ui.playlists)
|
||||
var playlist = Object.assign({}, playlists[action.uri])
|
||||
var playlist = Object.assign({}, playlists[action.key])
|
||||
var tracks = Object.assign([], playlist.tracks)
|
||||
var indexes = action.tracks_indexes.reverse()
|
||||
for( var i = 0; i < indexes.length; i++ ){
|
||||
@ -364,19 +415,19 @@ export default function reducer(ui = {}, action){
|
||||
var snapshot_id = null
|
||||
if( action.snapshot_id ) snapshot_id = action.snapshot_id
|
||||
Object.assign(playlist, { tracks: tracks, snapshot_id: snapshot_id })
|
||||
playlists[action.uri] = playlist
|
||||
playlists[action.key] = playlist
|
||||
return Object.assign({}, ui, { playlists: playlists });
|
||||
|
||||
case 'PLAYLIST_TRACKS':
|
||||
var playlists = Object.assign([], ui.playlists)
|
||||
var playlist = Object.assign({}, playlists[action.uri], { tracks: action.tracks })
|
||||
var playlist = Object.assign({}, playlists[action.key], { tracks: action.tracks })
|
||||
|
||||
playlists[action.uri] = playlist
|
||||
playlists[action.key] = playlist
|
||||
return Object.assign({}, ui, { playlists: playlists });
|
||||
|
||||
case 'PLAYLIST_TRACKS_REORDERED':
|
||||
var playlists = Object.assign([], ui.playlists)
|
||||
var playlist = Object.assign({}, playlists[action.uri])
|
||||
var playlist = Object.assign({}, playlists[action.key])
|
||||
var tracks = Object.assign([], playlist.tracks)
|
||||
|
||||
// handle insert_before offset if we're moving BENEATH where we're slicing tracks
|
||||
@ -394,14 +445,14 @@ export default function reducer(ui = {}, action){
|
||||
var snapshot_id = null
|
||||
if( action.snapshot_id ) snapshot_id = action.snapshot_id
|
||||
Object.assign(playlist, { tracks: tracks, snapshot_id: snapshot_id })
|
||||
playlists[action.uri] = playlist
|
||||
playlists[action.key] = playlist
|
||||
return Object.assign({}, ui, { playlists: playlists });
|
||||
|
||||
case 'PLAYLIST_FOLLOWING_LOADED':
|
||||
var playlists = Object.assign([], ui.playlists)
|
||||
var playlist = Object.assign({}, playlists[action.uri], { following: action.is_following })
|
||||
var playlist = Object.assign({}, playlists[action.key], { following: action.is_following })
|
||||
|
||||
playlists[action.uri] = playlist
|
||||
playlists[action.key] = playlist
|
||||
return Object.assign({}, ui, { playlists: playlists });
|
||||
|
||||
case 'LIBRARY_PLAYLISTS_LOADED':
|
||||
|
||||
@ -14,17 +14,26 @@ class DiscoverCategories extends React.Component{
|
||||
super(props);
|
||||
}
|
||||
|
||||
// on render
|
||||
componentDidMount(){
|
||||
this.props.spotifyActions.getCategories();
|
||||
}
|
||||
|
||||
render(){
|
||||
if (!this.props.categories) return null
|
||||
|
||||
// convert categories object into simple array
|
||||
var categories = []
|
||||
for (var key in this.props.categories){
|
||||
if (this.props.categories.hasOwnProperty(key)){
|
||||
categories.push(this.props.categories[key])
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="view discover-categories-view">
|
||||
<Header icon="grid" title="Genre / Mood" />
|
||||
<section className="grid-wrapper">
|
||||
{ this.props.spotify.categories ? <CategoryGrid categories={this.props.spotify.categories.items} /> : null }
|
||||
<CategoryGrid categories={categories} />
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
@ -39,7 +48,9 @@ class DiscoverCategories extends React.Component{
|
||||
**/
|
||||
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
return state;
|
||||
return {
|
||||
categories: state.ui.categories
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
|
||||
@ -26,18 +26,21 @@ class DiscoverCategory extends React.Component{
|
||||
}
|
||||
|
||||
loadMore(){
|
||||
if( !this.props.playlists_next || !this.props.playlists_next ) return
|
||||
this.props.spotifyActions.getURL( this.props.playlists_next, 'SPOTIFY_NEW_RELEASES_LOADED_MORE' );
|
||||
if (this.props.category.playlists_more){
|
||||
this.props.spotifyActions.getURL( this.props.category.playlists_more, 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED', 'category:'+this.props.params.id );
|
||||
}
|
||||
}
|
||||
|
||||
render(){
|
||||
if (!this.props.category) return null
|
||||
|
||||
var playlists = []
|
||||
for (var i = 0; i < this.props.category.playlists.length; i++){
|
||||
var uri = this.props.category.playlists[i]
|
||||
if (this.props.playlists.hasOwnProperty(uri)){
|
||||
playlists.push(this.props.playlists[uri])
|
||||
if (this.props.category.playlists_uris){
|
||||
for (var i = 0; i < this.props.category.playlists_uris.length; i++){
|
||||
var key = this.props.category.playlists_uris[i]
|
||||
if (this.props.playlists.hasOwnProperty(key)){
|
||||
playlists.push(this.props.playlists[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +66,7 @@ class DiscoverCategory extends React.Component{
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
return {
|
||||
playlists: state.ui.playlists,
|
||||
category: state.spotify.category
|
||||
category: (state.ui.categories && typeof(state.ui.categories['category:'+ownProps.params.id]) !== 'undefined' ? state.ui.categories['category:'+ownProps.params.id] : false )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user