2022-02-23 22:13:22 +01:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import { generateListSearchUrlParams, formatLbryUrlForWeb } from 'util/url';
|
|
|
|
import { useHistory } from 'react-router';
|
|
|
|
|
|
|
|
// Returns web blob from the streaming url
|
|
|
|
export default function usePlayNext(
|
|
|
|
isFloating: boolean,
|
|
|
|
collectionId: ?string,
|
|
|
|
shouldPlayNext: boolean,
|
|
|
|
nextListUri: ?string,
|
|
|
|
previousListUri: ?string,
|
|
|
|
doNavigate: boolean,
|
2022-03-15 17:28:55 +01:00
|
|
|
doUriInitiatePlay: (playingOptions: PlayingUri, isPlayable: ?boolean, isFloating: ?boolean) => void,
|
2022-02-23 22:13:22 +01:00
|
|
|
resetState: () => void
|
|
|
|
) {
|
|
|
|
const { push } = useHistory();
|
|
|
|
|
|
|
|
const doPlay = React.useCallback(
|
|
|
|
(playUri) => {
|
|
|
|
if (!isFloating) {
|
|
|
|
const navigateUrl = formatLbryUrlForWeb(playUri);
|
|
|
|
|
|
|
|
push({
|
|
|
|
pathname: navigateUrl,
|
|
|
|
search: collectionId && generateListSearchUrlParams(collectionId),
|
|
|
|
state: { collectionId, forceAutoplay: true, hideFloatingPlayer: true },
|
|
|
|
});
|
|
|
|
} else {
|
2022-03-15 17:28:55 +01:00
|
|
|
doUriInitiatePlay({ uri: playUri, collectionId }, true, isFloating);
|
2022-02-23 22:13:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resetState();
|
|
|
|
},
|
|
|
|
[collectionId, doUriInitiatePlay, isFloating, push, resetState]
|
|
|
|
);
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (!doNavigate) return;
|
|
|
|
|
|
|
|
if (shouldPlayNext) {
|
|
|
|
if (nextListUri) doPlay(nextListUri);
|
|
|
|
} else {
|
|
|
|
if (previousListUri) doPlay(previousListUri);
|
|
|
|
}
|
|
|
|
}, [doNavigate, doPlay, nextListUri, shouldPlayNext, previousListUri]);
|
|
|
|
}
|