Add last used collection to right click menu.
This commit is contained in:
parent
2ddf0a2cbd
commit
ca1d0e71b7
4 changed files with 33 additions and 0 deletions
|
@ -7,6 +7,7 @@ import {
|
||||||
makeSelectCollectionIsMine,
|
makeSelectCollectionIsMine,
|
||||||
makeSelectEditedCollectionForId,
|
makeSelectEditedCollectionForId,
|
||||||
makeSelectUrlsForCollectionId,
|
makeSelectUrlsForCollectionId,
|
||||||
|
selectLastUsedCollection,
|
||||||
} from 'redux/selectors/collections';
|
} from 'redux/selectors/collections';
|
||||||
import { makeSelectFileInfoForUri } from 'redux/selectors/file_info';
|
import { makeSelectFileInfoForUri } from 'redux/selectors/file_info';
|
||||||
import * as COLLECTIONS_CONSTS from 'constants/collections';
|
import * as COLLECTIONS_CONSTS from 'constants/collections';
|
||||||
|
@ -43,6 +44,7 @@ const select = (state, props) => {
|
||||||
const shuffleList = selectListShuffle(state);
|
const shuffleList = selectListShuffle(state);
|
||||||
const shuffle = shuffleList && shuffleList.collectionId === collectionId && shuffleList.newUrls;
|
const shuffle = shuffleList && shuffleList.collectionId === collectionId && shuffleList.newUrls;
|
||||||
const playNextUri = shuffle && shuffle[0];
|
const playNextUri = shuffle && shuffle[0];
|
||||||
|
const lastUsedCollection = selectLastUsedCollection(state);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
claim,
|
claim,
|
||||||
|
@ -70,6 +72,9 @@ const select = (state, props) => {
|
||||||
editedCollection: makeSelectEditedCollectionForId(collectionId)(state),
|
editedCollection: makeSelectEditedCollectionForId(collectionId)(state),
|
||||||
resolvedList: makeSelectUrlsForCollectionId(collectionId)(state),
|
resolvedList: makeSelectUrlsForCollectionId(collectionId)(state),
|
||||||
playNextUri,
|
playNextUri,
|
||||||
|
lastUsedCollection,
|
||||||
|
hasClaimInLastUsedCollection:
|
||||||
|
lastUsedCollection && makeSelectCollectionForIdHasClaimUrl(lastUsedCollection.id, contentPermanentUri)(state),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,8 @@ type Props = {
|
||||||
resolvedList: boolean,
|
resolvedList: boolean,
|
||||||
fetchCollectionItems: (string) => void,
|
fetchCollectionItems: (string) => void,
|
||||||
doToggleShuffleList: (string) => void,
|
doToggleShuffleList: (string) => void,
|
||||||
|
lastUsedCollection: ?Collection,
|
||||||
|
hasClaimInLastUsedCollection: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
function ClaimMenuList(props: Props) {
|
function ClaimMenuList(props: Props) {
|
||||||
|
@ -100,6 +102,8 @@ function ClaimMenuList(props: Props) {
|
||||||
resolvedList,
|
resolvedList,
|
||||||
fetchCollectionItems,
|
fetchCollectionItems,
|
||||||
doToggleShuffleList,
|
doToggleShuffleList,
|
||||||
|
lastUsedCollection,
|
||||||
|
hasClaimInLastUsedCollection,
|
||||||
} = props;
|
} = props;
|
||||||
const [doShuffle, setDoShuffle] = React.useState(false);
|
const [doShuffle, setDoShuffle] = React.useState(false);
|
||||||
const incognitoClaim = contentChannelUri && !contentChannelUri.includes('@');
|
const incognitoClaim = contentChannelUri && !contentChannelUri.includes('@');
|
||||||
|
@ -359,6 +363,22 @@ function ClaimMenuList(props: Props) {
|
||||||
{__('Add to Lists')}
|
{__('Add to Lists')}
|
||||||
</div>
|
</div>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
{lastUsedCollection && (
|
||||||
|
<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" />
|
<hr className="menu__separator" />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
|
@ -26,6 +26,7 @@ const defaultState: CollectionState = {
|
||||||
},
|
},
|
||||||
resolved: {},
|
resolved: {},
|
||||||
unpublished: {}, // sync
|
unpublished: {}, // sync
|
||||||
|
lastUsedCollection: undefined,
|
||||||
edited: {},
|
edited: {},
|
||||||
pending: {},
|
pending: {},
|
||||||
saved: [],
|
saved: [],
|
||||||
|
@ -53,14 +54,17 @@ const collectionsReducer = handleActions(
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
unpublished: newLists,
|
unpublished: newLists,
|
||||||
|
lastUsedCollection: newList,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
[ACTIONS.COLLECTION_DELETE]: (state, action) => {
|
[ACTIONS.COLLECTION_DELETE]: (state, action) => {
|
||||||
|
const { lastUsedCollection } = state;
|
||||||
const { id, collectionKey } = action.data;
|
const { id, collectionKey } = action.data;
|
||||||
const { edited: editList, unpublished: unpublishedList, pending: pendingList } = state;
|
const { edited: editList, unpublished: unpublishedList, pending: pendingList } = state;
|
||||||
const newEditList = Object.assign({}, editList);
|
const newEditList = Object.assign({}, editList);
|
||||||
const newUnpublishedList = Object.assign({}, unpublishedList);
|
const newUnpublishedList = Object.assign({}, unpublishedList);
|
||||||
|
const isDeletingLastUsedCollection = lastUsedCollection && lastUsedCollection.id === id;
|
||||||
|
|
||||||
const newPendingList = Object.assign({}, pendingList);
|
const newPendingList = Object.assign({}, pendingList);
|
||||||
|
|
||||||
|
@ -85,6 +89,7 @@ const collectionsReducer = handleActions(
|
||||||
edited: newEditList,
|
edited: newEditList,
|
||||||
unpublished: newUnpublishedList,
|
unpublished: newUnpublishedList,
|
||||||
pending: newPendingList,
|
pending: newPendingList,
|
||||||
|
lastUsedCollection: isDeletingLastUsedCollection ? undefined : lastUsedCollection,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -137,6 +142,7 @@ const collectionsReducer = handleActions(
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
unpublished: { ...lists, [id]: collection },
|
unpublished: { ...lists, [id]: collection },
|
||||||
|
lastUsedCollection: collection,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ export const selectMyEditedCollections = createSelector(selectState, (state) =>
|
||||||
|
|
||||||
export const selectPendingCollections = createSelector(selectState, (state) => state.pending);
|
export const selectPendingCollections = createSelector(selectState, (state) => state.pending);
|
||||||
|
|
||||||
|
export const selectLastUsedCollection = createSelector(selectState, (state) => state.lastUsedCollection);
|
||||||
|
|
||||||
export const makeSelectEditedCollectionForId = (id: string) =>
|
export const makeSelectEditedCollectionForId = (id: string) =>
|
||||||
createSelector(selectMyEditedCollections, (eLists) => eLists[id]);
|
createSelector(selectMyEditedCollections, (eLists) => eLists[id]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue