Categories moved to spotify, formatted images
This commit is contained in:
@ -602,8 +602,8 @@ const CoreMiddleware = (function(){
|
||||
var artists_index = Object.assign({}, core.artists);
|
||||
var artists_loaded = [];
|
||||
var tracks_loaded = [];
|
||||
|
||||
action.artists.forEach(raw_artist => {
|
||||
|
||||
for (var raw_artist of action.artists){
|
||||
var artist = helpers.formatArtist(raw_artist);
|
||||
|
||||
// Already have an artist in the index
|
||||
@ -628,7 +628,7 @@ const CoreMiddleware = (function(){
|
||||
}
|
||||
|
||||
artists_loaded.push(artist);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
action.artists = artists_loaded;
|
||||
@ -736,10 +736,6 @@ const CoreMiddleware = (function(){
|
||||
var records = action.records_data;
|
||||
}
|
||||
|
||||
if (action.records_type == 'track'){
|
||||
records = helpers.formatTracks(records);
|
||||
}
|
||||
|
||||
var records_type_plural = action.records_type+'s';
|
||||
var records_index = Object.assign({});
|
||||
var records_uris = helpers.arrayOf('uri', records);
|
||||
|
||||
@ -65,55 +65,6 @@ export default function reducer(core = {}, action){
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Categories
|
||||
**/
|
||||
|
||||
case 'CATEGORY_LOADED':
|
||||
var categories = Object.assign([], core.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({}, core, { categories: categories });
|
||||
|
||||
case 'CATEGORIES_LOADED':
|
||||
var categories = Object.assign([], core.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({}, core, { categories: categories });
|
||||
|
||||
case 'CATEGORY_PLAYLISTS_LOADED':
|
||||
var categories = Object.assign([], core.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({}, core, { categories: categories });
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -384,7 +384,7 @@ export function getCategories(){
|
||||
.then(
|
||||
response => {
|
||||
dispatch({
|
||||
type: 'CATEGORIES_LOADED',
|
||||
type: 'SPOTIFY_CATEGORIES_LOADED',
|
||||
categories: response.categories.items
|
||||
});
|
||||
},
|
||||
@ -400,24 +400,18 @@ export function getCategories(){
|
||||
|
||||
export function getCategory(id){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
dispatch({
|
||||
type: 'CATEGORY_LOADED',
|
||||
key: 'category:'+id,
|
||||
category: {
|
||||
playlists_uris: null
|
||||
}
|
||||
});
|
||||
|
||||
// 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)
|
||||
type: 'SPOTIFY_CATEGORY_LOADED',
|
||||
category: Object.assign(
|
||||
{
|
||||
uri: 'category:'+response.id,
|
||||
playlist_uris: []
|
||||
},
|
||||
response
|
||||
)
|
||||
});
|
||||
},
|
||||
error => {
|
||||
@ -427,33 +421,18 @@ export function getCategory(id){
|
||||
));
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// and the category's playlists
|
||||
export function getCategoryPlaylists(id){
|
||||
return (dispatch, getState) => {
|
||||
sendRequest(dispatch, getState, 'browse/categories/'+id+'/playlists?limit=50&country='+getState().spotify.country+'&locale='+getState().spotify.locale )
|
||||
.then(
|
||||
response => {
|
||||
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: 'PLAYLISTS_LOADED',
|
||||
playlists: playlists
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED',
|
||||
key: 'category:'+id,
|
||||
data: response
|
||||
uri: 'category:'+id,
|
||||
playlists: response.playlists
|
||||
});
|
||||
},
|
||||
error => {
|
||||
@ -670,31 +649,19 @@ export function getAutocompleteResults(field_id, query, types = ['album','artist
|
||||
}
|
||||
|
||||
if (response.artists && response.artists.items){
|
||||
dispatch({
|
||||
type: 'ARTISTS_LOADED',
|
||||
artists: response.artists.items
|
||||
});
|
||||
dispatch(coreActions.artistsLoaded(response.artists.items));
|
||||
}
|
||||
|
||||
if (response.albums && response.albums.items){
|
||||
dispatch({
|
||||
type: 'ALBUMS_LOADED',
|
||||
albums: response.albums.items
|
||||
});
|
||||
dispatch(coreActions.albumsLoaded(response.albums.items));
|
||||
}
|
||||
|
||||
if (response.playlists && response.playlists.items){
|
||||
dispatch({
|
||||
type: 'PLAYLISTS_LOADED',
|
||||
playlists: response.playlists.items
|
||||
});
|
||||
dispatch(coreActions.playlistsLoaded(response.playlists.items));
|
||||
}
|
||||
|
||||
if (response.tracks && response.tracks.items){
|
||||
dispatch({
|
||||
type: 'TRACKS_LOADED',
|
||||
tracks: response.tracks.items
|
||||
});
|
||||
dispatch(coreActions.tracksLoaded(response.tracks.items));
|
||||
}
|
||||
|
||||
dispatch({
|
||||
|
||||
@ -14,7 +14,7 @@ const SpotifyMiddleware = (function(){
|
||||
* The actual middleware inteceptor
|
||||
**/
|
||||
return store => next => action => {
|
||||
var state = store.getState();
|
||||
var spotify = store.getState().spotify;
|
||||
|
||||
switch(action.type){
|
||||
|
||||
@ -84,7 +84,7 @@ const SpotifyMiddleware = (function(){
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_REMOVE_PLAYLIST_TRACKS':
|
||||
var playlist = Object.assign({},state.core.playlists[action.key]);
|
||||
var playlist = Object.assign({}, store.getState().core.playlists[action.key]);
|
||||
store.dispatch(spotifyActions.deleteTracksFromPlaylist(playlist.uri, playlist.snapshot_id, action.tracks_indexes ))
|
||||
break;
|
||||
|
||||
@ -158,9 +158,11 @@ const SpotifyMiddleware = (function(){
|
||||
});
|
||||
break
|
||||
|
||||
/*
|
||||
|
||||
case 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED':
|
||||
var playlists = []
|
||||
for(var i = 0; i < action.data.playlists.items.length; i++){
|
||||
for (var i = 0; i < action.data.playlists.items.length; i++){
|
||||
var playlist = Object.assign(
|
||||
{},
|
||||
action.data.playlists.items[i],
|
||||
@ -188,6 +190,59 @@ const SpotifyMiddleware = (function(){
|
||||
total: action.data.playlists.total
|
||||
});
|
||||
break
|
||||
*/
|
||||
|
||||
case 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED':
|
||||
store.dispatch(coreActions.playlistsLoaded(action.playlists.items));
|
||||
|
||||
action.uris = helpers.arrayOf('uri',action.playlists.items);
|
||||
action.more = action.playlists.next;
|
||||
action.total = action.playlists.total;
|
||||
delete action.playlists;
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED_MORE':
|
||||
store.dispatch({
|
||||
type: 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED',
|
||||
uri: action.uri,
|
||||
playlists: action.data.playlists
|
||||
});
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_CATEGORY_LOADED':
|
||||
store.dispatch({
|
||||
type: 'SPOTIFY_CATEGORIES_LOADED',
|
||||
categories: [action.category]
|
||||
});
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_CATEGORIES_LOADED':
|
||||
var categories_index = Object.assign({}, spotify.categories);
|
||||
var categories_loaded = [];
|
||||
|
||||
for (var raw_category of action.categories){
|
||||
var category = Object.assign({}, raw_category);
|
||||
|
||||
if (!category.uri){
|
||||
category.uri = "category:"+category.id;
|
||||
}
|
||||
|
||||
if (categories_index[category.uri] !== undefined){
|
||||
category = Object.assign({}, categories_index[category.uri], category);
|
||||
}
|
||||
|
||||
if (category.icons){
|
||||
category.icons = helpers.formatImages(category.icons);
|
||||
}
|
||||
|
||||
categories_loaded.push(category);
|
||||
}
|
||||
|
||||
action.categories = categories_loaded;
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR':
|
||||
store.dispatch(spotifyActions.getLibraryPlaylistsProcessor(action.data))
|
||||
|
||||
@ -164,6 +164,39 @@ export default function reducer(spotify = {}, action){
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* Categories
|
||||
**/
|
||||
|
||||
case 'SPOTIFY_CATEGORIES_LOADED':
|
||||
var categories = Object.assign({}, spotify.categories);
|
||||
for (var category of action.categories){
|
||||
categories[category.uri] = category
|
||||
}
|
||||
return Object.assign({}, spotify, { categories: categories });
|
||||
|
||||
case 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED':
|
||||
var categories = Object.assign({}, spotify.categories)
|
||||
var playlists_uris = [];
|
||||
|
||||
if (categories[action.uri].playlists_uris){
|
||||
playlists_uris = categories[action.uri].playlists_uris;
|
||||
}
|
||||
|
||||
var category = Object.assign(
|
||||
{},
|
||||
categories[action.uri],
|
||||
{
|
||||
playlists_uris: [...playlists_uris, ...action.uris],
|
||||
playlists_more: action.more,
|
||||
playlists_total: action.total
|
||||
}
|
||||
)
|
||||
categories[action.uri] = category
|
||||
return Object.assign({}, spotify, { categories: categories });
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Library
|
||||
**/
|
||||
|
||||
Reference in New Issue
Block a user