Detect authorization before we ask for /following
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -98,7 +98,7 @@
|
||||
|
||||
// Release details
|
||||
// These are automatically injected to built HTML
|
||||
var build = "1536744044";
|
||||
var build = "1536782591";
|
||||
var version = "3.25.1";
|
||||
|
||||
// Construct the script tag
|
||||
|
||||
@ -494,6 +494,25 @@ export let formatPlaylist = function(data){
|
||||
return playlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade playlist uris to the new, simplified Spotify syntax (September 2018)
|
||||
*
|
||||
* @param uris = String or Array
|
||||
* @return String or Array
|
||||
**/
|
||||
export let upgradePlaylistsUris = function(uris){
|
||||
if (Array.isArray(uris)){
|
||||
var upgraded = [];
|
||||
for (var uri of uris){
|
||||
upgraded.push(uri.replace(/spotify:user:([^:]*?):/i, "spotify:"));
|
||||
}
|
||||
} else {
|
||||
var upgraded = uris = uris.replace(/spotify:user:([^:]*?):/i, "spotify:");
|
||||
}
|
||||
|
||||
return upgraded;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format a user objects into a universal format
|
||||
@ -956,11 +975,11 @@ export let indexFriendlyUri = function (uri){
|
||||
* @return Array
|
||||
**/
|
||||
export let arrayOf = function(property, items){
|
||||
let array = []
|
||||
for (let i = 0; i < items.length; i++){
|
||||
array.push(items[i][property])
|
||||
let array = [];
|
||||
for (var item of items){
|
||||
array.push(item[property]);
|
||||
}
|
||||
return array
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -344,7 +344,10 @@ const CoreMiddleware = (function(){
|
||||
switch (helpers.uriSource(action.uri)){
|
||||
case 'spotify':
|
||||
store.dispatch(spotifyActions.getTrack(action.uri));
|
||||
store.dispatch(spotifyActions.following(action.uri));
|
||||
|
||||
if (store.getState().spotify.me){
|
||||
store.dispatch(spotifyActions.following(action.uri));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -370,7 +373,10 @@ const CoreMiddleware = (function(){
|
||||
switch (helpers.uriSource(action.uri)){
|
||||
case 'spotify':
|
||||
store.dispatch(spotifyActions.getAlbum(action.uri));
|
||||
store.dispatch(spotifyActions.following(action.uri));
|
||||
|
||||
if (store.getState().spotify.me){
|
||||
store.dispatch(spotifyActions.following(action.uri));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -397,7 +403,10 @@ const CoreMiddleware = (function(){
|
||||
switch (helpers.uriSource(action.uri)){
|
||||
case 'spotify':
|
||||
store.dispatch(spotifyActions.getArtist(action.uri, true));
|
||||
store.dispatch(spotifyActions.following(action.uri));
|
||||
|
||||
if (store.getState().spotify.me){
|
||||
store.dispatch(spotifyActions.following(action.uri));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -423,7 +432,10 @@ const CoreMiddleware = (function(){
|
||||
switch (helpers.uriSource(action.uri)){
|
||||
case 'spotify':
|
||||
store.dispatch(spotifyActions.getPlaylist(action.uri));
|
||||
store.dispatch(spotifyActions.following(action.uri));
|
||||
|
||||
if (store.getState().spotify.me){
|
||||
store.dispatch(spotifyActions.following(action.uri));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -448,7 +460,10 @@ const CoreMiddleware = (function(){
|
||||
switch (helpers.uriSource(action.uri)){
|
||||
case 'spotify':
|
||||
store.dispatch(spotifyActions.getUser(action.uri));
|
||||
store.dispatch(spotifyActions.following(action.uri));
|
||||
|
||||
if (store.getState().spotify.me){
|
||||
store.dispatch(spotifyActions.following(action.uri));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@ -364,7 +364,7 @@ export function getFeaturedPlaylists(){
|
||||
type: 'SPOTIFY_FEATURED_PLAYLISTS_LOADED',
|
||||
data: {
|
||||
message: response.message,
|
||||
playlists: helpers.arrayOf('uri',response.playlists.items)
|
||||
playlists: helpers.upgradePlaylistsUris(helpers.arrayOf('uri',response.playlists.items))
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -738,7 +738,7 @@ export function following(uri, method = 'GET'){
|
||||
} else {
|
||||
endpoint = 'playlists/'+ helpers.getFromUri('playlistid',uri) +'/followers'
|
||||
}
|
||||
break
|
||||
break;
|
||||
}
|
||||
|
||||
sendRequest(dispatch, getState, endpoint, method, data)
|
||||
|
||||
@ -195,11 +195,15 @@ const SpotifyMiddleware = (function(){
|
||||
case 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED':
|
||||
store.dispatch(coreActions.playlistsLoaded(action.playlists.items));
|
||||
|
||||
action.uris = helpers.arrayOf('uri',action.playlists.items);
|
||||
console.log(action);
|
||||
action.uris = helpers.arrayOf('uri', action.playlists.items);
|
||||
action.more = action.playlists.next;
|
||||
action.total = action.playlists.total;
|
||||
delete action.playlists;
|
||||
|
||||
// Upgrade our URIs
|
||||
action.uris = helpers.upgradePlaylistsUris(action.uris);
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
|
||||
@ -159,11 +159,10 @@ class Playlist extends React.Component{
|
||||
|
||||
render(){
|
||||
var scheme = helpers.uriSource(this.props.params.uri);
|
||||
var user_id = helpers.getFromUri('userid',this.props.params.uri);
|
||||
var playlist_id = helpers.getFromUri('playlistid',this.props.params.uri);
|
||||
|
||||
if (!this.props.playlist){
|
||||
if (helpers.isLoading(this.props.load_queue,['spotify_users/'+user_id+'/playlists/'+playlist_id+'?'])){
|
||||
if (helpers.isLoading(this.props.load_queue,['spotify_playlists/'+playlist_id+'?'])){
|
||||
return (
|
||||
<div className="body-loader loading">
|
||||
<div className="loader"></div>
|
||||
@ -181,7 +180,7 @@ class Playlist extends React.Component{
|
||||
context = 'editable-playlist';
|
||||
}
|
||||
|
||||
if (playlist.tracks && playlist.tracks.length <= 0 && helpers.isLoading(this.props.load_queue,['spotify_users/'+user_id+'/playlists/'+playlist_id, 'spotify_users/'+user_id+'/playlists/'+playlist_id+'/tracks'])){
|
||||
if (playlist.tracks && playlist.tracks.length <= 0 && helpers.isLoading(this.props.load_queue,['spotify_playlists/'+playlist_id, 'spotify_playlists/'+playlist_id+'/tracks'])){
|
||||
var is_loading_tracks = true;
|
||||
} else {
|
||||
var is_loading_tracks = false;
|
||||
@ -244,7 +243,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
local_library_playlists: state.mopidy.library_playlists,
|
||||
mopidy_connected: state.mopidy.connected,
|
||||
spotify_authorized: state.spotify.authorization,
|
||||
spotify_userid: state.spotify.me.id
|
||||
spotify_userid: (state.spotify.me && state.spotify.me.id ? state.spotify.me.id : null)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user