Properly cancellable processes; Playlists that refuse to load tracks

This commit is contained in:
James Barnsley
2020-05-25 20:50:25 +12:00
parent 487bd5590b
commit fec4396583
17 changed files with 777 additions and 779 deletions

View File

@ -408,21 +408,22 @@ const CoreMiddleware = (function () {
break;
case 'LOAD_PLAYLIST':
if (
!action.force_reload
&& store.getState().core.playlists[action.uri]
&& store.getState().core.playlists[action.uri].tracks_uris) {
console.info(`Loading "${action.uri}" from index`);
break;
}
if (
!action.force_reload
&& store.getState().core.playlists[action.uri]
&& store.getState().core.playlists[action.uri].tracks_uris !== undefined
) {
console.info(`Loading "${action.uri}" from index`);
break;
}
switch (uriSource(action.uri)) {
case 'spotify':
store.dispatch(spotifyActions.getPlaylist(action.uri));
if (store.getState().spotify.me) {
store.dispatch(spotifyActions.following(action.uri));
}
store.dispatch(spotifyActions.following(action.uri));
}
break;
default:

View File

@ -1895,7 +1895,7 @@ export function getLibraryArtists() {
}
export function getLibraryArtistsProcessor(data) {
return (dispatch, getState) => {
return (dispatch, getState) => {
request(dispatch, getState, data.next)
.then(
(response) => {
@ -1903,17 +1903,6 @@ export function getLibraryArtistsProcessor(data) {
type: 'SPOTIFY_LIBRARY_ARTISTS_LOADED',
artists: response.artists.items,
});
// Check to see if we've been cancelled
if (getState().ui.processes.SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR !== undefined) {
const processor = getState().ui.processes.SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR;
if (processor.status == 'cancelling') {
dispatch(uiActions.processCancelled('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR'));
return false;
}
}
// We got a next link, so we've got more work to be done
if (response.artists.next) {
const { total } = response.artists;

View File

@ -251,7 +251,19 @@ const SpotifyMiddleware = (function () {
break;
case 'SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR':
store.dispatch(spotifyActions.getLibraryPlaylistsProcessor(action.data));
const playlistProcessor = store.getState().ui.processes.SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR || {};
switch (playlistProcessor.status) {
case 'cancelling':
store.dispatch(uiActions.processCancelled('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR'));
break;
case 'cancelled':
break;
default:
store.dispatch(spotifyActions.getLibraryPlaylistsProcessor(action.data));
break;
}
break;
case 'SPOTIFY_LIBRARY_PLAYLISTS_LOADED':
@ -285,7 +297,19 @@ const SpotifyMiddleware = (function () {
break;
case 'SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR':
store.dispatch(spotifyActions.getLibraryArtistsProcessor(action.data));
const artistsProcessor = store.getState().ui.processes.SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR || {};
switch (artistsProcessor.status) {
case 'cancelling':
store.dispatch(uiActions.processCancelled('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR'));
break;
case 'cancelled':
break;
default:
store.dispatch(spotifyActions.getLibraryArtistsProcessor(action.data));
break;
}
break;
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED':
@ -312,7 +336,19 @@ const SpotifyMiddleware = (function () {
break;
case 'SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR':
store.dispatch(spotifyActions.getLibraryAlbumsProcessor(action.data));
const albumsProcessor = store.getState().ui.processes.SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR || {};
switch (albumsProcessor.status) {
case 'cancelling':
store.dispatch(uiActions.processCancelled('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR'));
break;
case 'cancelled':
break;
default:
store.dispatch(spotifyActions.getLibraryAlbumsProcessor(action.data));
break;
}
break;
case 'SPOTIFY_GET_LIBRARY_TRACKS_AND_PLAY_PROCESSOR':

View File

@ -208,6 +208,7 @@ const UIMiddleware = (function () {
store.dispatch({
type: `${action.key}_CANCELLED`,
});
store.dispatch(uiActions.closeProcess(action.key));
next(action);
break;

View File

@ -152,9 +152,12 @@ export default function reducer(ui = {}, action) {
case 'START_PROCESS':
case 'UPDATE_PROCESS':
var processes = { ...(ui.processes ? ui.processes : []) };
if (processes[action.key]) {
var data = { ...processes[action.key].data, ...action.data };
var processes = { ...(ui.processes || []) };
var last_run = processes[action.key];
var status = 'running';
if (last_run) {
var data = { ...last_run.data, ...action.data };
status = last_run.status;
} else {
var { data } = action;
}
@ -162,8 +165,8 @@ export default function reducer(ui = {}, action) {
key: action.key,
content: action.content,
description: action.description,
status: 'running',
level: action.level,
status,
data,
};
return { ...ui, processes };