Update last used collection when a collection is pending or published.

This commit is contained in:
Franco Montenegro 2022-02-24 14:42:00 -03:00 committed by jessopb
parent aa008d8a61
commit c843991378
3 changed files with 27 additions and 2 deletions

View file

@ -75,6 +75,10 @@ const select = (state, props) => {
lastUsedCollection,
hasClaimInLastUsedCollection:
lastUsedCollection && makeSelectCollectionForIdHasClaimUrl(lastUsedCollection.id, contentPermanentUri)(state),
lastUsedCollectionIsNotBuiltin:
lastUsedCollection &&
lastUsedCollection.id !== COLLECTIONS_CONSTS.WATCH_LATER_ID &&
lastUsedCollection.id !== COLLECTIONS_CONSTS.FAVORITES_ID,
};
};

View file

@ -62,6 +62,7 @@ type Props = {
doToggleShuffleList: (string) => void,
lastUsedCollection: ?Collection,
hasClaimInLastUsedCollection: boolean,
lastUsedCollectionIsNotBuiltin: boolean,
};
function ClaimMenuList(props: Props) {
@ -104,6 +105,7 @@ function ClaimMenuList(props: Props) {
doToggleShuffleList,
lastUsedCollection,
hasClaimInLastUsedCollection,
lastUsedCollectionIsNotBuiltin,
} = props;
const [doShuffle, setDoShuffle] = React.useState(false);
const incognitoClaim = contentChannelUri && !contentChannelUri.includes('@');
@ -363,7 +365,7 @@ function ClaimMenuList(props: Props) {
{__('Add to Lists')}
</div>
</MenuItem>
{lastUsedCollection && (
{lastUsedCollection && lastUsedCollectionIsNotBuiltin && (
<MenuItem
className="comment__menu-option"
onSelect={() =>

View file

@ -181,7 +181,7 @@ const collectionsReducer = handleActions(
},
[ACTIONS.COLLECTION_ITEMS_RESOLVE_COMPLETED]: (state, action) => {
const { resolvedCollections, failedCollectionIds } = action.data;
const { pending, edited, isResolvingCollectionById, resolved } = state;
const { pending, edited, isResolvingCollectionById, resolved, lastUsedCollection } = state;
const newPending = Object.assign({}, pending);
const newEdited = Object.assign({}, edited);
const newResolved = Object.assign({}, resolved, resolvedCollections);
@ -208,12 +208,31 @@ const collectionsReducer = handleActions(
});
}
const newAllCollections = [
...Object.values(newPending),
...Object.values(newResolved),
...Object.values(newEdited),
];
let newLastUsedCollection = lastUsedCollection;
// If a collection is being published or got published,
// its id will get updated which means, we have to sync
// the last used collection.
if (lastUsedCollection) {
newLastUsedCollection = newAllCollections.find((collection) => {
// $FlowFixMe
return collection.name === lastUsedCollection.name;
});
}
return Object.assign({}, state, {
...state,
pending: newPending,
resolved: newResolved,
edited: newEdited,
isResolvingCollectionById: newResolving,
lastUsedCollection: newLastUsedCollection,
});
},
[ACTIONS.COLLECTION_ITEMS_RESOLVE_FAILED]: (state, action) => {