6205 remember last used playlist choice odysee (#967)
* Add last used collection to right click menu. * Small fix for last used collection when it's a published collection. * Update last used collection when a collection is pending or published. * Small refactor to get the last used collection.
This commit is contained in:
parent
b9d392526c
commit
69a9245324
4 changed files with 46 additions and 0 deletions
|
@ -3,10 +3,12 @@ import { selectClaimForUri, selectClaimIsMine } from 'redux/selectors/claims';
|
||||||
import { doCollectionEdit, doFetchItemsInCollection } from 'redux/actions/collections';
|
import { doCollectionEdit, doFetchItemsInCollection } from 'redux/actions/collections';
|
||||||
import { doEditForChannel } from 'redux/actions/publish';
|
import { doEditForChannel } from 'redux/actions/publish';
|
||||||
import {
|
import {
|
||||||
|
makeSelectCollectionForId,
|
||||||
makeSelectCollectionForIdHasClaimUrl,
|
makeSelectCollectionForIdHasClaimUrl,
|
||||||
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';
|
||||||
|
@ -44,6 +46,8 @@ 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 lastUsedCollectionId = selectLastUsedCollection(state);
|
||||||
|
const lastUsedCollection = makeSelectCollectionForId(lastUsedCollectionId)(state);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
claim,
|
claim,
|
||||||
|
@ -72,6 +76,14 @@ const select = (state, props) => {
|
||||||
isAuthenticated: Boolean(selectUserVerifiedEmail(state)),
|
isAuthenticated: Boolean(selectUserVerifiedEmail(state)),
|
||||||
resolvedList: makeSelectUrlsForCollectionId(collectionId)(state),
|
resolvedList: makeSelectUrlsForCollectionId(collectionId)(state),
|
||||||
playNextUri,
|
playNextUri,
|
||||||
|
lastUsedCollection,
|
||||||
|
hasClaimInLastUsedCollection: makeSelectCollectionForIdHasClaimUrl(
|
||||||
|
lastUsedCollectionId,
|
||||||
|
contentPermanentUri
|
||||||
|
)(state),
|
||||||
|
lastUsedCollectionIsNotBuiltin:
|
||||||
|
lastUsedCollectionId !== COLLECTIONS_CONSTS.WATCH_LATER_ID &&
|
||||||
|
lastUsedCollectionId !== COLLECTIONS_CONSTS.FAVORITES_ID,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,9 @@ type Props = {
|
||||||
resolvedList: boolean,
|
resolvedList: boolean,
|
||||||
fetchCollectionItems: (string) => void,
|
fetchCollectionItems: (string) => void,
|
||||||
doToggleShuffleList: (string) => void,
|
doToggleShuffleList: (string) => void,
|
||||||
|
lastUsedCollection: ?Collection,
|
||||||
|
hasClaimInLastUsedCollection: boolean,
|
||||||
|
lastUsedCollectionIsNotBuiltin: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
function ClaimMenuList(props: Props) {
|
function ClaimMenuList(props: Props) {
|
||||||
|
@ -108,6 +111,9 @@ function ClaimMenuList(props: Props) {
|
||||||
resolvedList,
|
resolvedList,
|
||||||
fetchCollectionItems,
|
fetchCollectionItems,
|
||||||
doToggleShuffleList,
|
doToggleShuffleList,
|
||||||
|
lastUsedCollection,
|
||||||
|
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('@');
|
||||||
|
@ -355,6 +361,22 @@ function ClaimMenuList(props: Props) {
|
||||||
{__('Add to Lists')}
|
{__('Add to Lists')}
|
||||||
</div>
|
</div>
|
||||||
</MenuItem>
|
</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" />
|
<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: params.id,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
[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 === id;
|
||||||
|
|
||||||
const newPendingList = Object.assign({}, pendingList);
|
const newPendingList = Object.assign({}, pendingList);
|
||||||
|
|
||||||
|
@ -70,6 +74,7 @@ const collectionsReducer = handleActions(
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
[collectionKey]: newList,
|
[collectionKey]: newList,
|
||||||
|
lastUsedCollection: isDeletingLastUsedCollection ? undefined : lastUsedCollection,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
if (newEditList[id]) {
|
if (newEditList[id]) {
|
||||||
|
@ -85,6 +90,7 @@ const collectionsReducer = handleActions(
|
||||||
edited: newEditList,
|
edited: newEditList,
|
||||||
unpublished: newUnpublishedList,
|
unpublished: newUnpublishedList,
|
||||||
pending: newPendingList,
|
pending: newPendingList,
|
||||||
|
lastUsedCollection: isDeletingLastUsedCollection ? undefined : lastUsedCollection,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -112,6 +118,7 @@ const collectionsReducer = handleActions(
|
||||||
edited: newEditList,
|
edited: newEditList,
|
||||||
unpublished: newUnpublishedList,
|
unpublished: newUnpublishedList,
|
||||||
pending: newPendingList,
|
pending: newPendingList,
|
||||||
|
lastUsedCollection: claimId,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -123,6 +130,7 @@ const collectionsReducer = handleActions(
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
[collectionKey]: { ...lists, [id]: collection },
|
[collectionKey]: { ...lists, [id]: collection },
|
||||||
|
lastUsedCollection: id,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,12 +139,14 @@ const collectionsReducer = handleActions(
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
edited: { ...lists, [id]: collection },
|
edited: { ...lists, [id]: collection },
|
||||||
|
lastUsedCollection: id,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const { unpublished: lists } = state;
|
const { unpublished: lists } = state;
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
unpublished: { ...lists, [id]: collection },
|
unpublished: { ...lists, [id]: collection },
|
||||||
|
lastUsedCollection: id,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@ export const selectMyUnpublishedCollections = (state: State) => selectState(stat
|
||||||
export const selectMyEditedCollections = (state: State) => selectState(state).edited;
|
export const selectMyEditedCollections = (state: State) => selectState(state).edited;
|
||||||
export const selectPendingCollections = (state: State) => selectState(state).pending;
|
export const selectPendingCollections = (state: State) => selectState(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