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

View file

@ -181,7 +181,7 @@ const collectionsReducer = handleActions(
}, },
[ACTIONS.COLLECTION_ITEMS_RESOLVE_COMPLETED]: (state, action) => { [ACTIONS.COLLECTION_ITEMS_RESOLVE_COMPLETED]: (state, action) => {
const { resolvedCollections, failedCollectionIds } = action.data; const { resolvedCollections, failedCollectionIds } = action.data;
const { pending, edited, isResolvingCollectionById, resolved } = state; const { pending, edited, isResolvingCollectionById, resolved, lastUsedCollection } = state;
const newPending = Object.assign({}, pending); const newPending = Object.assign({}, pending);
const newEdited = Object.assign({}, edited); const newEdited = Object.assign({}, edited);
const newResolved = Object.assign({}, resolved, resolvedCollections); 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, { return Object.assign({}, state, {
...state, ...state,
pending: newPending, pending: newPending,
resolved: newResolved, resolved: newResolved,
edited: newEdited, edited: newEdited,
isResolvingCollectionById: newResolving, isResolvingCollectionById: newResolving,
lastUsedCollection: newLastUsedCollection,
}); });
}, },
[ACTIONS.COLLECTION_ITEMS_RESOLVE_FAILED]: (state, action) => { [ACTIONS.COLLECTION_ITEMS_RESOLVE_FAILED]: (state, action) => {