Fixed: Queue not always clearing checked items when updated

Signed-off-by: Robin Dadswell <robin@dadswell.email>
pull/770/head
Qstick 4 years ago
parent 97e6240177
commit 8d43d5d7b0

@ -13,6 +13,7 @@ import TableBody from 'Components/Table/TableBody';
import TableOptionsModalWrapper from 'Components/Table/TableOptions/TableOptionsModalWrapper'; import TableOptionsModalWrapper from 'Components/Table/TableOptions/TableOptionsModalWrapper';
import TablePager from 'Components/Table/TablePager'; import TablePager from 'Components/Table/TablePager';
import { align, icons } from 'Helpers/Props'; import { align, icons } from 'Helpers/Props';
import getRemovedItems from 'Utilities/Object/getRemovedItems';
import hasDifferentItems from 'Utilities/Object/hasDifferentItems'; import hasDifferentItems from 'Utilities/Object/hasDifferentItems';
import getSelectedIds from 'Utilities/Table/getSelectedIds'; import getSelectedIds from 'Utilities/Table/getSelectedIds';
import removeOldSelectedState from 'Utilities/Table/removeOldSelectedState'; import removeOldSelectedState from 'Utilities/Table/removeOldSelectedState';
@ -36,34 +37,28 @@ class Queue extends Component {
lastToggled: null, lastToggled: null,
selectedState: {}, selectedState: {},
isPendingSelected: false, isPendingSelected: false,
isConfirmRemoveModalOpen: false isConfirmRemoveModalOpen: false,
items: props.items
}; };
} }
shouldComponentUpdate(nextProps) { componentDidUpdate(prevProps) {
// Don't update when fetching has completed if items have changed, const {
// before books start fetching or when books start fetching. items,
isFetching,
isBooksFetching
} = this.props;
if ( if (
this.props.isFetching && (!isBooksFetching && prevProps.isBooksFetching) ||
nextProps.isPopulated && (!isFetching && prevProps.isFetching) ||
hasDifferentItems(this.props.items, nextProps.items) && (hasDifferentItems(prevProps.items, items) && !items.some((e) => e.bookId))
nextProps.items.some((e) => e.bookId)
) { ) {
return false;
}
if (!this.props.isBooksFetching && nextProps.isBooksFetching) {
return false;
}
return true;
}
componentDidUpdate(prevProps) {
if (hasDifferentItems(prevProps.items, this.props.items)) {
this.setState((state) => { this.setState((state) => {
return removeOldSelectedState(state, prevProps.items); return {
...removeOldSelectedState(state, getRemovedItems(prevProps.items, items)),
items
};
}); });
return; return;
@ -124,7 +119,6 @@ class Queue extends Component {
isFetching, isFetching,
isPopulated, isPopulated,
error, error,
items,
isAuthorFetching, isAuthorFetching,
isAuthorPopulated, isAuthorPopulated,
isBooksFetching, isBooksFetching,
@ -144,7 +138,8 @@ class Queue extends Component {
allUnselected, allUnselected,
selectedState, selectedState,
isConfirmRemoveModalOpen, isConfirmRemoveModalOpen,
isPendingSelected isPendingSelected,
items
} = this.state; } = this.state;
const isRefreshing = isFetching || isAuthorFetching || isBooksFetching || isRefreshMonitoredDownloadsExecuting; const isRefreshing = isFetching || isAuthorFetching || isBooksFetching || isRefreshMonitoredDownloadsExecuting;

@ -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;
Loading…
Cancel
Save