Fixed: Infinite spinner when toggling seasons on multiple series from season pass

This commit is contained in:
Mark McDowall 2019-08-16 22:46:12 -07:00
parent ec6d407fbb
commit 665d536481
1 changed files with 9 additions and 6 deletions

View File

@ -17,7 +17,7 @@ import { updateItem } from './baseActions';
const MONITOR_TIMEOUT = 1000; const MONITOR_TIMEOUT = 1000;
const seasonsToUpdate = {}; const seasonsToUpdate = {};
let seasonMonitorToggleTimeout = null; const seasonMonitorToggleTimeouts = {};
// //
// Variables // Variables
@ -271,16 +271,19 @@ export const actionHandlers = handleThunks({
}, },
[TOGGLE_SEASON_MONITORED]: function(getState, payload, dispatch) { [TOGGLE_SEASON_MONITORED]: function(getState, payload, dispatch) {
if (seasonMonitorToggleTimeout) {
seasonMonitorToggleTimeout = clearTimeout(seasonMonitorToggleTimeout);
}
const { const {
seriesId: id, seriesId: id,
seasonNumber, seasonNumber,
monitored monitored
} = payload; } = payload;
const seasonMonitorToggleTimeout = seasonMonitorToggleTimeouts[id];
if (seasonMonitorToggleTimeout) {
clearTimeout(seasonMonitorToggleTimeout);
delete seasonMonitorToggleTimeouts[id];
}
const series = getState().series.items.find((s) => s.id === id); const series = getState().series.items.find((s) => s.id === id);
const seasons = _.cloneDeep(series.seasons); const seasons = _.cloneDeep(series.seasons);
const season = seasons.find((s) => s.seasonNumber === seasonNumber); const season = seasons.find((s) => s.seasonNumber === seasonNumber);
@ -296,7 +299,7 @@ export const actionHandlers = handleThunks({
seasonsToUpdate[seasonNumber] = monitored; seasonsToUpdate[seasonNumber] = monitored;
season.monitored = monitored; season.monitored = monitored;
seasonMonitorToggleTimeout = setTimeout(() => { seasonMonitorToggleTimeouts[id] = setTimeout(() => {
createAjaxRequest({ createAjaxRequest({
url: `/series/${id}`, url: `/series/${id}`,
method: 'PUT', method: 'PUT',