diff --git a/src/js/services/spotify/actions.js b/src/js/services/spotify/actions.js
index ec204bfc..6b9b83b8 100755
--- a/src/js/services/spotify/actions.js
+++ b/src/js/services/spotify/actions.js
@@ -559,6 +559,13 @@ export function getMore(url, core_action = null, custom_action = null, extra_dat
export function getSearchResults({ type, term }, limit = 50, offset = 0) {
const processKey = 'SPOTIFY_GET_SEARCH_RESULTS';
return (dispatch, getState) => {
+ const {
+ spotify: {
+ me: {
+ id: meId,
+ } = {},
+ },
+ } = getState();
dispatch(uiActions.startProcess(processKey, { content: 'Searching Spotify' }));
let typeString = type.replace(/s+$/, '');
@@ -602,7 +609,7 @@ export function getSearchResults({ type, term }, limit = 50, offset = 0) {
if (response.playlists !== undefined) {
const playlists = response.playlists.items.map((item) => ({
...formatPlaylist(item),
- can_edit: (getState().spotify.me && item.owner.id === getState().spotify.me.id),
+ can_edit: (meId === item.owner.id),
}));
dispatch(coreActions.searchResultsLoaded(
{ term, type },
@@ -747,8 +754,15 @@ export function following(uri, method = 'GET') {
}
break;
case 'playlist':
+ const {
+ spotify: {
+ me: {
+ id: meId,
+ } = {},
+ },
+ } = getState();
if (method === 'GET') {
- endpoint = `playlists/${getFromUri('playlistid', uri)}/followers/contains?ids=${getState().spotify.me.id}`;
+ endpoint = `playlists/${getFromUri('playlistid', uri)}/followers/contains?ids=${meId}`;
} else {
endpoint = `playlists/${getFromUri('playlistid', uri)}/followers?`;
}
@@ -1221,8 +1235,15 @@ export function createPlaylist(name, description, is_public, is_collaborative) {
public: is_public,
collaborative: is_collaborative,
};
+ const {
+ spotify: {
+ me: {
+ id: meId,
+ } = {},
+ },
+ } = getState();
- request(dispatch, getState, `users/${getState().spotify.me.id}/playlists/`, 'POST', data)
+ request(dispatch, getState, `users/${meId}/playlists/`, 'POST', data)
.then(
(response) => {
dispatch(coreActions.itemLoaded({
@@ -1256,10 +1277,17 @@ export function savePlaylist(uri, name, description, is_public, is_collaborative
public: is_public,
collaborative: is_collaborative,
};
+ const {
+ spotify: {
+ me: {
+ id: meId,
+ } = {},
+ },
+ } = getState();
// Update the playlist fields
request(
- dispatch, getState, `users/${getState().spotify.me.id}/playlists/${getFromUri('playlistid', uri)}`, 'PUT', data,
+ dispatch, getState, `users/${meId}/playlists/${getFromUri('playlistid', uri)}`, 'PUT', data,
)
.then(
(response) => {
@@ -1267,7 +1295,7 @@ export function savePlaylist(uri, name, description, is_public, is_collaborative
// Save the image
if (image) {
- request(dispatch, getState, `users/${getState().spotify.me.id}/playlists/${getFromUri('playlistid', uri)}/images`, 'PUT', image)
+ request(dispatch, getState, `users/${meId}/playlists/${getFromUri('playlistid', uri)}/images`, 'PUT', image)
.then(
(response) => {
@@ -1315,7 +1343,7 @@ export function savePlaylist(uri, name, description, is_public, is_collaborative
}
export function getPlaylistTracks(uri, { forceRefetch, callbackAction } = {}) {
- return (dispatch, getState) => {
+ return (dispatch, getState) => {
let initialEndpoint = `playlists/${getFromUri('playlistid', uri)}/tracks`;
initialEndpoint += `?market=${getState().spotify.country}`;
if (forceRefetch) initialEndpoint += `&refetch=${Date.now()}`;
@@ -1366,6 +1394,13 @@ export function getPlaylist(uri, options) {
const { full, forceRefetch } = options;
return (dispatch, getState) => {
+ const {
+ spotify: {
+ me: {
+ id: meId,
+ } = {},
+ },
+ } = getState();
let endpoint = `playlists/${getFromUri('playlistid', uri)}`;
endpoint += `?market=${getState().spotify.country}`;
if (forceRefetch) endpoint += `&refetch=${Date.now()}`;
@@ -1389,7 +1424,7 @@ export function getPlaylist(uri, options) {
dispatch(coreActions.itemLoaded({
...formatPlaylist(response),
- can_edit: (getState().spotify.me && getState().spotify.me.id === response.owner.id),
+ can_edit: (meId === response.owner.id),
description,
// Remove tracks. They're handed by another query which allows our detector
// to accurately identify whether we've loaded *ALL* the tracks. Without this, it
@@ -1504,6 +1539,13 @@ export function flushLibrary() {
export function getLibraryPlaylists(forceRefetch) {
return (dispatch, getState) => {
+ const {
+ spotify: {
+ me: {
+ id: meId,
+ } = {},
+ },
+ } = getState();
const processKey = 'SPOTIFY_GET_LIBRARY_PLAYLISTS';
dispatch(uiActions.startProcess(processKey, { notification: false }));
@@ -1526,7 +1568,7 @@ export function getLibraryPlaylists(forceRefetch) {
(item) => ({
...formatPlaylist(item),
in_library: true,
- can_edit: (getState().spotify.me && item.owner.id === getState().spotify.me.id),
+ can_edit: (meId === item.owner.id),
}),
);
libraryItems = [...libraryItems, ...items];
diff --git a/src/js/views/QueueHistory.js b/src/js/views/QueueHistory.js
index 598af197..e7a455c4 100755
--- a/src/js/views/QueueHistory.js
+++ b/src/js/views/QueueHistory.js
@@ -61,7 +61,7 @@ class QueueHistory extends React.Component {
- {tracks && (
+ {tracks.length > 0 && (
{
const source = state.ui.library_playlists_source || 'all';
+ const {
+ spotify: {
+ me: {
+ id: me_id,
+ } = {},
+ },
+ } = state;
const libraryUris = [];
if (source === 'all' || source === 'local') libraryUris.push('mopidy:library:playlists');
@@ -369,7 +376,7 @@ const mapStateToProps = (state) => {
playlists: librarySelector(state),
loading_progress: processProgressSelector(state),
source,
- me_id: (state.spotify.me ? state.spotify.me.id : false),
+ me_id,
view: state.ui.library_playlists_view,
sort: (state.ui.library_playlists_sort ? state.ui.library_playlists_sort : null),
sort_reverse: (state.ui.library_playlists_sort_reverse ? state.ui.library_playlists_sort_reverse : false),
diff --git a/src/js/views/modals/AddToPlaylist.js b/src/js/views/modals/AddToPlaylist.js
index 8b45e6eb..e3ada550 100755
--- a/src/js/views/modals/AddToPlaylist.js
+++ b/src/js/views/modals/AddToPlaylist.js
@@ -106,17 +106,39 @@ class AddToPlaylist extends React.Component {
}
}
-const mapStateToProps = (state, ownProps) => ({
- uris: (ownProps.match.params.uris ? decodeURIComponent(ownProps.match.params.uris).split(',') : []),
- mopidy_uri_schemes: state.mopidy.uri_schemes,
- items: state.core.items,
- mopidy_library: state.core.libraries['mopidy:library:playlists'],
- spotify_library: state.core.libraries['spotify:library:playlists'],
- spotify_available: state.spotify.access_token,
- load_queue: state.ui.load_queue,
- me_id: (state.spotify.me ? state.spotify.me.id : false),
- playlists: state.core.playlists,
-});
+const mapStateToProps = (state, ownProps) => {
+ const {
+ spotify: {
+ me: {
+ id: me_id,
+ } = {},
+ access_token: spotify_available,
+ },
+ ui: {
+ load_queue,
+ },
+ core: {
+ playlists,
+ items,
+ libraries,
+ },
+ mopidy: {
+ uri_schemes: mopidy_uri_schemes,
+ }
+ } = state;
+
+ return {
+ uris: (ownProps.match.params.uris ? decodeURIComponent(ownProps.match.params.uris).split(',') : []),
+ mopidy_uri_schemes,
+ items,
+ mopidy_library: libraries['mopidy:library:playlists'],
+ spotify_library: libraries['spotify:library:playlists'],
+ spotify_available,
+ load_queue,
+ me_id,
+ playlists,
+ };
+};
const mapDispatchToProps = (dispatch) => ({
coreActions: bindActionCreators(coreActions, dispatch),
diff --git a/src/js/views/modals/ShareConfiguration.js b/src/js/views/modals/ShareConfiguration.js
index 59a680f2..b4d8d1a3 100755
--- a/src/js/views/modals/ShareConfiguration.js
+++ b/src/js/views/modals/ShareConfiguration.js
@@ -297,7 +297,7 @@ class ShareConfiguration extends React.Component {
}
}
-const mapStateToProps = (state, ownProps) => ({
+const mapStateToProps = (state) => ({
spotify_authorization: state.spotify.authorization,
spotify_me: state.spotify.me,
genius_authorization: state.genius.authorization,