Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last used collection to right click menu. #7491

Merged
merged 4 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ui/component/claimMenuList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { selectClaimForUri, selectClaimIsMine } from 'redux/selectors/claims';
import { doCollectionEdit, doFetchItemsInCollection } from 'redux/actions/collections';
import { doPrepareEdit } from 'redux/actions/publish';
import {
makeSelectCollectionForId,
makeSelectCollectionForIdHasClaimUrl,
makeSelectCollectionIsMine,
makeSelectEditedCollectionForId,
makeSelectUrlsForCollectionId,
selectLastUsedCollection,
} from 'redux/selectors/collections';
import { makeSelectFileInfoForUri } from 'redux/selectors/file_info';
import * as COLLECTIONS_CONSTS from 'constants/collections';
Expand Down Expand Up @@ -43,6 +45,8 @@ const select = (state, props) => {
const shuffleList = selectListShuffle(state);
const shuffle = shuffleList && shuffleList.collectionId === collectionId && shuffleList.newUrls;
const playNextUri = shuffle && shuffle[0];
const lastUsedCollectionId = selectLastUsedCollection(state);
const lastUsedCollection = makeSelectCollectionForId(lastUsedCollectionId)(state);

return {
claim,
Expand Down Expand Up @@ -70,6 +74,14 @@ const select = (state, props) => {
editedCollection: makeSelectEditedCollectionForId(collectionId)(state),
resolvedList: makeSelectUrlsForCollectionId(collectionId)(state),
playNextUri,
lastUsedCollection,
hasClaimInLastUsedCollection: makeSelectCollectionForIdHasClaimUrl(
lastUsedCollectionId,
contentPermanentUri
)(state),
lastUsedCollectionIsNotBuiltin:
lastUsedCollectionId !== COLLECTIONS_CONSTS.WATCH_LATER_ID &&
lastUsedCollectionId !== COLLECTIONS_CONSTS.FAVORITES_ID,
};
};

Expand Down
22 changes: 22 additions & 0 deletions ui/component/claimMenuList/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type Props = {
resolvedList: boolean,
fetchCollectionItems: (string) => void,
doToggleShuffleList: (string) => void,
lastUsedCollection: ?Collection,
hasClaimInLastUsedCollection: boolean,
lastUsedCollectionIsNotBuiltin: boolean,
};

function ClaimMenuList(props: Props) {
Expand Down Expand Up @@ -100,6 +103,9 @@ function ClaimMenuList(props: Props) {
resolvedList,
fetchCollectionItems,
doToggleShuffleList,
lastUsedCollection,
hasClaimInLastUsedCollection,
lastUsedCollectionIsNotBuiltin,
} = props;
const [doShuffle, setDoShuffle] = React.useState(false);
const incognitoClaim = contentChannelUri && !contentChannelUri.includes('@');
Expand Down Expand Up @@ -359,6 +365,22 @@ function ClaimMenuList(props: Props) {
{__('Add to Lists')}
</div>
</MenuItem>
{lastUsedCollection && lastUsedCollectionIsNotBuiltin && (
<MenuItem
className="comment__menu-option"
onSelect={() =>
handleAdd(hasClaimInLastUsedCollection, lastUsedCollection.name, lastUsedCollection.id)
}
>
<div className="menu__link">
{!hasClaimInLastUsedCollection && <Icon aria-hidden icon={ICONS.ADD} />}
{hasClaimInLastUsedCollection && <Icon aria-hidden icon={ICONS.DELETE} />}
{!hasClaimInLastUsedCollection &&
__('Add to %collection%', { collection: lastUsedCollection.name })}
{hasClaimInLastUsedCollection && __('In %collection%', { collection: lastUsedCollection.name })}
</div>
</MenuItem>
)}
<hr className="menu__separator" />
</>
)
Expand Down
10 changes: 10 additions & 0 deletions ui/redux/reducers/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const defaultState: CollectionState = {
},
resolved: {},
unpublished: {}, // sync
lastUsedCollection: undefined,
edited: {},
pending: {},
saved: [],
Expand Down Expand Up @@ -53,14 +54,17 @@ const collectionsReducer = handleActions(
return {
...state,
unpublished: newLists,
lastUsedCollection: params.id,
};
},

[ACTIONS.COLLECTION_DELETE]: (state, action) => {
const { lastUsedCollection } = state;
const { id, collectionKey } = action.data;
const { edited: editList, unpublished: unpublishedList, pending: pendingList } = state;
const newEditList = Object.assign({}, editList);
const newUnpublishedList = Object.assign({}, unpublishedList);
const isDeletingLastUsedCollection = lastUsedCollection === id;

const newPendingList = Object.assign({}, pendingList);

Expand All @@ -70,6 +74,7 @@ const collectionsReducer = handleActions(
return {
...state,
[collectionKey]: newList,
lastUsedCollection: isDeletingLastUsedCollection ? undefined : lastUsedCollection,
};
} else {
if (newEditList[id]) {
Expand All @@ -85,6 +90,7 @@ const collectionsReducer = handleActions(
edited: newEditList,
unpublished: newUnpublishedList,
pending: newPendingList,
lastUsedCollection: isDeletingLastUsedCollection ? undefined : lastUsedCollection,
};
},

Expand Down Expand Up @@ -112,6 +118,7 @@ const collectionsReducer = handleActions(
edited: newEditList,
unpublished: newUnpublishedList,
pending: newPendingList,
lastUsedCollection: claimId,
};
},

Expand All @@ -123,6 +130,7 @@ const collectionsReducer = handleActions(
return {
...state,
[collectionKey]: { ...lists, [id]: collection },
lastUsedCollection: id,
};
}

Expand All @@ -131,12 +139,14 @@ const collectionsReducer = handleActions(
return {
...state,
edited: { ...lists, [id]: collection },
lastUsedCollection: id,
};
}
const { unpublished: lists } = state;
return {
...state,
unpublished: { ...lists, [id]: collection },
lastUsedCollection: id,
};
},

Expand Down
2 changes: 2 additions & 0 deletions ui/redux/selectors/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const selectMyEditedCollections = createSelector(selectState, (state) =>

export const selectPendingCollections = createSelector(selectState, (state) => state.pending);

export const selectLastUsedCollection = createSelector(selectState, (state) => state.lastUsedCollection);

export const makeSelectEditedCollectionForId = (id: string) =>
createSelector(selectMyEditedCollections, (eLists) => eLists[id]);

Expand Down