Handle non playable items in playlists.

This commit is contained in:
Franco Montenegro 2022-05-04 19:15:07 -03:00 committed by jessopb
parent 6108860063
commit 8a9af7d354
2 changed files with 64 additions and 38 deletions

View file

@ -340,9 +340,9 @@ function ClaimMenuList(props: Props) {
)}
</>
) : (
isPlayable && (
<>
{/* WATCH LATER */}
{isPlayable && (
<MenuItem
className="comment__menu-option"
onSelect={() => handleAdd(hasClaimInWatchLater, __('Watch Later'), COLLECTIONS_CONSTS.WATCH_LATER_ID)}
@ -352,6 +352,7 @@ function ClaimMenuList(props: Props) {
{hasClaimInWatchLater ? __('In Watch Later') : __('Watch Later')}
</div>
</MenuItem>
)}
{/* FAVORITES LIST */}
<MenuItem
className="comment__menu-option"
@ -390,7 +391,6 @@ function ClaimMenuList(props: Props) {
)}
<hr className="menu__separator" />
</>
)
)}
</>
{!isChannelPage && (

View file

@ -34,12 +34,38 @@ const select = (state, props) => {
const playingUri = selectPlayingUri(state);
const collectionId = urlParams.get(COLLECTIONS_CONSTS.COLLECTION_ID) || (playingUri && playingUri.collectionId);
const isMarkdownOrComment = playingUri && (playingUri.source === 'markdown' || playingUri.source === 'comment');
const isClaimPlayable = (uri) => {
const claim = makeSelectClaimForUri(uri)(state);
// $FlowFixMe
return (
claim &&
// $FlowFixMe
claim.value &&
// $FlowFixMe
claim.value.stream_type &&
// $FlowFixMe
(claim.value.stream_type === 'audio' || claim.value.stream_type === 'video')
);
};
const nextUriInCollection = (fromUri) => {
return makeSelectNextUrlForCollectionAndUrl(collectionId, fromUri)(state);
};
const prevUriInCollection = (fromUri) => {
return makeSelectPreviousUrlForCollectionAndUrl(collectionId, fromUri)(state);
};
let nextRecommendedUri;
let previousListUri;
if (collectionId) {
nextRecommendedUri = makeSelectNextUrlForCollectionAndUrl(collectionId, uri)(state);
previousListUri = makeSelectPreviousUrlForCollectionAndUrl(collectionId, uri)(state);
nextRecommendedUri = uri;
previousListUri = uri;
// Find previous and next playable item in the collection.
do {
nextRecommendedUri = nextUriInCollection(nextRecommendedUri);
} while (nextRecommendedUri && !isClaimPlayable(nextRecommendedUri));
do {
previousListUri = prevUriInCollection(previousListUri);
} while (previousListUri && !isClaimPlayable(previousListUri));
} else {
const recommendedContent = selectRecommendedContentForUri(state, uri);
nextRecommendedUri = recommendedContent && recommendedContent[0];