diff --git a/frontend/src/Activity/Queue/Queue.js b/frontend/src/Activity/Queue/Queue.js index ae22f8f73..0d7047ed9 100644 --- a/frontend/src/Activity/Queue/Queue.js +++ b/frontend/src/Activity/Queue/Queue.js @@ -1,6 +1,7 @@ import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; +import getRemovedItems from 'Utilities/Object/getRemovedItems'; import hasDifferentItems from 'Utilities/Object/hasDifferentItems'; import getSelectedIds from 'Utilities/Table/getSelectedIds'; import removeOldSelectedState from 'Utilities/Table/removeOldSelectedState'; @@ -36,14 +37,22 @@ class Queue extends Component { lastToggled: null, selectedState: {}, isPendingSelected: false, - isConfirmRemoveModalOpen: false + isConfirmRemoveModalOpen: false, + items: props.items }; } componentDidUpdate(prevProps) { - if (hasDifferentItems(prevProps.items, this.props.items)) { + const { + items + } = this.props; + + if (hasDifferentItems(prevProps.items, items) && !items.some((e) => e.movieId)) { this.setState((state) => { - return removeOldSelectedState(state, prevProps.items); + return { + ...removeOldSelectedState(state, getRemovedItems(prevProps.items, items)), + items + }; }); return; @@ -107,7 +116,6 @@ class Queue extends Component { isMoviesFetching, isMoviesPopulated, moviesError, - items, columns, totalRecords, isGrabbing, @@ -122,7 +130,8 @@ class Queue extends Component { allUnselected, selectedState, isConfirmRemoveModalOpen, - isPendingSelected + isPendingSelected, + items } = this.state; const isRefreshing = isFetching || isMoviesFetching || isRefreshMonitoredDownloadsExecuting; diff --git a/frontend/src/Utilities/Object/getRemovedItems.js b/frontend/src/Utilities/Object/getRemovedItems.js new file mode 100644 index 000000000..df7ada3a8 --- /dev/null +++ b/frontend/src/Utilities/Object/getRemovedItems.js @@ -0,0 +1,15 @@ +function getRemovedItems(prevItems, currentItems, idProp = 'id') { + if (prevItems === currentItems) { + return []; + } + + const currentItemIds = new Set(); + + currentItems.forEach((currentItem) => { + currentItemIds.add(currentItem[idProp]); + }); + + return prevItems.filter((prevItem) => !currentItemIds.has(prevItem[idProp])); +} + +export default getRemovedItems;