mirror of
https://github.com/Readarr/Readarr
synced 2025-12-28 03:09:38 +01:00
Fixed: Queue not always clearing checked items when updated
Signed-off-by: Robin Dadswell <robin@dadswell.email>
This commit is contained in:
parent
97e6240177
commit
8d43d5d7b0
2 changed files with 33 additions and 23 deletions
|
|
@ -13,6 +13,7 @@ import TableBody from 'Components/Table/TableBody';
|
|||
import TableOptionsModalWrapper from 'Components/Table/TableOptions/TableOptionsModalWrapper';
|
||||
import TablePager from 'Components/Table/TablePager';
|
||||
import { align, icons } from 'Helpers/Props';
|
||||
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,34 +37,28 @@ class Queue extends Component {
|
|||
lastToggled: null,
|
||||
selectedState: {},
|
||||
isPendingSelected: false,
|
||||
isConfirmRemoveModalOpen: false
|
||||
isConfirmRemoveModalOpen: false,
|
||||
items: props.items
|
||||
};
|
||||
}
|
||||
|
||||
shouldComponentUpdate(nextProps) {
|
||||
// Don't update when fetching has completed if items have changed,
|
||||
// before books start fetching or when books start fetching.
|
||||
componentDidUpdate(prevProps) {
|
||||
const {
|
||||
items,
|
||||
isFetching,
|
||||
isBooksFetching
|
||||
} = this.props;
|
||||
|
||||
if (
|
||||
this.props.isFetching &&
|
||||
nextProps.isPopulated &&
|
||||
hasDifferentItems(this.props.items, nextProps.items) &&
|
||||
nextProps.items.some((e) => e.bookId)
|
||||
(!isBooksFetching && prevProps.isBooksFetching) ||
|
||||
(!isFetching && prevProps.isFetching) ||
|
||||
(hasDifferentItems(prevProps.items, items) && !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) => {
|
||||
return removeOldSelectedState(state, prevProps.items);
|
||||
return {
|
||||
...removeOldSelectedState(state, getRemovedItems(prevProps.items, items)),
|
||||
items
|
||||
};
|
||||
});
|
||||
|
||||
return;
|
||||
|
|
@ -124,7 +119,6 @@ class Queue extends Component {
|
|||
isFetching,
|
||||
isPopulated,
|
||||
error,
|
||||
items,
|
||||
isAuthorFetching,
|
||||
isAuthorPopulated,
|
||||
isBooksFetching,
|
||||
|
|
@ -144,7 +138,8 @@ class Queue extends Component {
|
|||
allUnselected,
|
||||
selectedState,
|
||||
isConfirmRemoveModalOpen,
|
||||
isPendingSelected
|
||||
isPendingSelected,
|
||||
items
|
||||
} = this.state;
|
||||
|
||||
const isRefreshing = isFetching || isAuthorFetching || isBooksFetching || isRefreshMonitoredDownloadsExecuting;
|
||||
|
|
|
|||
15
frontend/src/Utilities/Object/getRemovedItems.js
Normal file
15
frontend/src/Utilities/Object/getRemovedItems.js
Normal file
|
|
@ -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…
Reference in a new issue