From 1e1cef2a46000211b776b44f352e868b6f1add0c Mon Sep 17 00:00:00 2001 From: miko Date: Wed, 20 Nov 2024 17:10:35 +0200 Subject: [PATCH 1/2] Collection edit: Fetch collection items only if not fetched before --- ui/redux/actions/collections.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ui/redux/actions/collections.js b/ui/redux/actions/collections.js index 3778ad2740..9ca5358ba2 100644 --- a/ui/redux/actions/collections.js +++ b/ui/redux/actions/collections.js @@ -566,9 +566,12 @@ export const doCollectionEdit = const isPrivateVersion = selectHasPrivateCollectionForId(state, collectionId); const { uris, remove, replace, order, type, isPreview } = params; - await dispatch(doFetchItemsInCollection({ collectionId })); - state = getState(); - const hasItemsResolved = selectCollectionHasItemsResolvedForId(state, collectionId); + let hasItemsResolved = selectCollectionHasItemsResolvedForId(state, collectionId); + if (!hasItemsResolved && !isPrivateVersion) { + await dispatch(doFetchItemsInCollection({ collectionId })); + state = getState(); + hasItemsResolved = selectCollectionHasItemsResolvedForId(state, collectionId); + } if (!hasItemsResolved && !isPrivateVersion) { return dispatch(doToast({ message: __('Failed to resolve collection items. Please try again.'), isError: true })); } From 3a7b18fae632301f35d96875ee28af1fe9a2eceb Mon Sep 17 00:00:00 2001 From: miko Date: Thu, 21 Nov 2024 13:59:59 +0200 Subject: [PATCH 2/2] Get rid of some dispatches on collection edit --- ui/redux/actions/collections.js | 6 ------ ui/redux/reducers/collections.js | 12 +++++++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ui/redux/actions/collections.js b/ui/redux/actions/collections.js index 9ca5358ba2..89ce6302e5 100644 --- a/ui/redux/actions/collections.js +++ b/ui/redux/actions/collections.js @@ -608,8 +608,6 @@ export const doCollectionEdit = currentUrls.splice(order.to, 0, movedItem); } - await dispatch(doRemoveFromUpdatedCollectionsForCollectionId(collectionId)); - const isQueue = collectionId === COLS.QUEUE_ID; const title = params.title || params.name; @@ -635,10 +633,6 @@ export const doCollectionEdit = }, }, }); - // Needs to be run after collection_edit is dispatched, or saving changes doesn't work from edit page - if (!isPreview) { - dispatch(doRemoveFromUnsavedChangesCollectionsForCollectionId(collectionId)); - } success(); }); }; diff --git a/ui/redux/reducers/collections.js b/ui/redux/reducers/collections.js index 4bc3884e31..77d5aad41f 100644 --- a/ui/redux/reducers/collections.js +++ b/ui/redux/reducers/collections.js @@ -141,11 +141,21 @@ const collectionsReducer = handleActions( const newCollection = Object.assign({}, collection); newCollection.updatedAt = getCurrentTimeInSec(); - return { + const newState = { ...state, [collectionKey]: { ...currentCollections, [id]: newCollection }, lastUsedCollection: id, }; + + // Remove un-wanted versions of the list + [COLS.KEYS.UPDATED, COLS.KEYS.UNSAVED_CHANGES].forEach((key) => { + if (collectionKey !== key) { + const { [id]: _, ...remainingCollections } = state[key]; + newState[key] = remainingCollections; + } + }); + + return newState; }, [ACTIONS.USER_STATE_POPULATE]: (state, action) => {