2020-01-27 19:52:25 +01:00
|
|
|
// @flow
|
2021-09-02 22:05:32 +02:00
|
|
|
import React from 'react';
|
2020-01-27 19:52:25 +01:00
|
|
|
import Button from 'component/button';
|
|
|
|
import UriIndicator from 'component/uriIndicator';
|
2020-01-27 21:02:58 +01:00
|
|
|
import I18nMessage from 'component/i18nMessage';
|
2020-01-27 19:52:25 +01:00
|
|
|
import { withRouter } from 'react-router';
|
2020-06-22 17:20:51 +02:00
|
|
|
import debounce from 'util/debounce';
|
2021-09-02 22:05:32 +02:00
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
|
2020-06-22 17:20:51 +02:00
|
|
|
const DEBOUNCE_SCROLL_HANDLER_MS = 150;
|
|
|
|
const CLASSNAME_AUTOPLAY_COUNTDOWN = 'autoplay-countdown';
|
2020-01-27 19:52:25 +01:00
|
|
|
|
|
|
|
type Props = {
|
wip
wip
wip - everything but publish, autoplay, and styling
collection publishing
add channel to collection publish
cleanup
wip
bump
clear mass add after success
move collection item management controls
redirect replace to published collection id
bump
playlist selector on create
bump
use new collection add ui element
bump
wip
gitignore
add content json
wip
bump
context add to playlist
basic collections page style pass wip
wip: edits, buttons, styles...
change fileAuthor to claimAuthor
update, pending bugfixes, delete modal progress, collection header, other bugfixes
bump
cleaning
show page bugfix
builtin collection headers
no playlists, no grid title
wip
style tweaks
use normal looking claim previews for collection tiles
add collection changes
style library previews
collection menulist for delete/view on library
delete modal works for unpublished
rearrange collection publish tabs
clean up collection publishing and items
show on odysee
begin collectoin edit header and css renaming
better thumbnails
bump
fix collection publish redirect
view collection in menu does something
copy and thumbs
list previews, pending, context menus, list page
enter to add collection, lists page empty state
playable lists only, delete feature, bump
put fileListDownloaded back
better collection titles
improve collection claim details
fix horiz more icon
fix up channel page
style, copy, bump
refactor preview overlay properties,
fix reposts showing as floppydisk
add watch later toast,
small overlay properties on wunderbar results,
fix collection actions buttons
bump
cleanup
cleaning, refactoring
bump
preview thumb styling, cleanup
support discover page lists search
sync, bump
bump, fix sync more
enforce builtin order for now
new lists page empty state
try to indicate unpublished edits in lists
bump
fix autoplay and linting
consts, fix autoplay
bugs
fixes
cleanup
fix, bump
lists experimental ui, fixes
refactor listIndex out
hack in collection fallback thumb
bump
2021-02-06 08:03:51 +01:00
|
|
|
history: { push: (string) => void },
|
2020-01-27 19:52:25 +01:00
|
|
|
nextRecommendedClaim: ?StreamClaim,
|
|
|
|
nextRecommendedUri: string,
|
2020-06-22 10:34:39 +02:00
|
|
|
modal: { id: string, modalProps: {} },
|
2021-09-10 19:27:21 +02:00
|
|
|
skipPaid: boolean,
|
2021-09-02 22:05:32 +02:00
|
|
|
doNavigate: () => void,
|
|
|
|
doReplay: () => void,
|
2021-09-10 19:27:21 +02:00
|
|
|
doPrevious: () => void,
|
|
|
|
onCanceled: () => void,
|
2020-01-27 19:52:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function AutoplayCountdown(props: Props) {
|
|
|
|
const {
|
|
|
|
nextRecommendedUri,
|
|
|
|
nextRecommendedClaim,
|
|
|
|
history: { push },
|
2020-06-22 10:34:39 +02:00
|
|
|
modal,
|
2021-09-10 19:27:21 +02:00
|
|
|
skipPaid,
|
2021-09-02 22:05:32 +02:00
|
|
|
doNavigate,
|
|
|
|
doReplay,
|
2021-09-10 19:27:21 +02:00
|
|
|
doPrevious,
|
|
|
|
onCanceled,
|
2020-01-27 19:52:25 +01:00
|
|
|
} = props;
|
|
|
|
const nextTitle = nextRecommendedClaim && nextRecommendedClaim.value && nextRecommendedClaim.value.title;
|
2020-04-14 01:48:11 +02:00
|
|
|
|
|
|
|
/* this value is coupled with CSS timing variables on .autoplay-countdown__timer */
|
2020-04-14 01:50:52 +02:00
|
|
|
const countdownTime = 5;
|
2020-04-14 01:48:11 +02:00
|
|
|
|
|
|
|
const [timer, setTimer] = React.useState(countdownTime);
|
2020-01-27 19:52:25 +01:00
|
|
|
const [timerCanceled, setTimerCanceled] = React.useState(false);
|
2020-06-22 08:55:52 +02:00
|
|
|
const [timerPaused, setTimerPaused] = React.useState(false);
|
2020-06-22 10:34:39 +02:00
|
|
|
const anyModalPresent = modal !== undefined && modal !== null;
|
|
|
|
const isTimerPaused = timerPaused || anyModalPresent;
|
2020-01-27 19:52:25 +01:00
|
|
|
|
2020-12-18 18:34:58 +01:00
|
|
|
function shouldPauseAutoplay() {
|
|
|
|
const elm = document.querySelector(`.${CLASSNAME_AUTOPLAY_COUNTDOWN}`);
|
|
|
|
return elm && elm.getBoundingClientRect().top < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update 'setTimerPaused'.
|
2020-06-22 08:55:52 +02:00
|
|
|
React.useEffect(() => {
|
2020-12-18 18:34:58 +01:00
|
|
|
// Ensure correct 'setTimerPaused' on initial render.
|
|
|
|
setTimerPaused(shouldPauseAutoplay());
|
|
|
|
|
wip
wip
wip - everything but publish, autoplay, and styling
collection publishing
add channel to collection publish
cleanup
wip
bump
clear mass add after success
move collection item management controls
redirect replace to published collection id
bump
playlist selector on create
bump
use new collection add ui element
bump
wip
gitignore
add content json
wip
bump
context add to playlist
basic collections page style pass wip
wip: edits, buttons, styles...
change fileAuthor to claimAuthor
update, pending bugfixes, delete modal progress, collection header, other bugfixes
bump
cleaning
show page bugfix
builtin collection headers
no playlists, no grid title
wip
style tweaks
use normal looking claim previews for collection tiles
add collection changes
style library previews
collection menulist for delete/view on library
delete modal works for unpublished
rearrange collection publish tabs
clean up collection publishing and items
show on odysee
begin collectoin edit header and css renaming
better thumbnails
bump
fix collection publish redirect
view collection in menu does something
copy and thumbs
list previews, pending, context menus, list page
enter to add collection, lists page empty state
playable lists only, delete feature, bump
put fileListDownloaded back
better collection titles
improve collection claim details
fix horiz more icon
fix up channel page
style, copy, bump
refactor preview overlay properties,
fix reposts showing as floppydisk
add watch later toast,
small overlay properties on wunderbar results,
fix collection actions buttons
bump
cleanup
cleaning, refactoring
bump
preview thumb styling, cleanup
support discover page lists search
sync, bump
bump, fix sync more
enforce builtin order for now
new lists page empty state
try to indicate unpublished edits in lists
bump
fix autoplay and linting
consts, fix autoplay
bugs
fixes
cleanup
fix, bump
lists experimental ui, fixes
refactor listIndex out
hack in collection fallback thumb
bump
2021-02-06 08:03:51 +01:00
|
|
|
const handleScroll = debounce((e) => {
|
2020-12-18 18:34:58 +01:00
|
|
|
setTimerPaused(shouldPauseAutoplay());
|
2020-06-22 17:20:51 +02:00
|
|
|
}, DEBOUNCE_SCROLL_HANDLER_MS);
|
2020-06-22 08:55:52 +02:00
|
|
|
|
|
|
|
window.addEventListener('scroll', handleScroll);
|
|
|
|
return () => window.removeEventListener('scroll', handleScroll);
|
|
|
|
}, []);
|
|
|
|
|
2020-12-18 18:34:58 +01:00
|
|
|
// Update countdown timer.
|
2020-01-27 19:52:25 +01:00
|
|
|
React.useEffect(() => {
|
|
|
|
let interval;
|
2020-04-16 23:43:09 +02:00
|
|
|
if (!timerCanceled && nextRecommendedUri) {
|
2020-06-22 10:34:39 +02:00
|
|
|
if (isTimerPaused) {
|
2020-06-22 08:55:52 +02:00
|
|
|
clearInterval(interval);
|
|
|
|
setTimer(countdownTime);
|
|
|
|
} else {
|
|
|
|
interval = setInterval(() => {
|
|
|
|
const newTime = timer - 1;
|
|
|
|
if (newTime === 0) {
|
2021-09-10 19:27:21 +02:00
|
|
|
if (skipPaid) setTimer(countdownTime);
|
2020-06-22 08:55:52 +02:00
|
|
|
doNavigate();
|
|
|
|
} else {
|
|
|
|
setTimer(timer - 1);
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
}
|
2020-01-27 19:52:25 +01:00
|
|
|
}
|
|
|
|
return () => {
|
|
|
|
clearInterval(interval);
|
|
|
|
};
|
2021-09-10 19:27:21 +02:00
|
|
|
}, [timer, doNavigate, push, timerCanceled, isTimerPaused, nextRecommendedUri, skipPaid]);
|
2020-01-27 19:52:25 +01:00
|
|
|
|
2020-04-14 01:48:11 +02:00
|
|
|
if (timerCanceled || !nextRecommendedUri) {
|
2020-01-27 19:52:25 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-04-14 01:48:11 +02:00
|
|
|
<div className="file-viewer__overlay">
|
2020-06-22 17:20:51 +02:00
|
|
|
<div className={CLASSNAME_AUTOPLAY_COUNTDOWN}>
|
2020-04-14 01:48:11 +02:00
|
|
|
<div className="file-viewer__overlay-secondary">
|
|
|
|
<I18nMessage tokens={{ channel: <UriIndicator link uri={nextRecommendedUri} /> }}>
|
|
|
|
Up Next by %channel%
|
|
|
|
</I18nMessage>
|
2020-01-27 20:32:20 +01:00
|
|
|
</div>
|
2020-04-14 01:48:11 +02:00
|
|
|
|
|
|
|
<div className="file-viewer__overlay-title">{nextTitle}</div>
|
|
|
|
<div className="autoplay-countdown__timer">
|
|
|
|
<div className={'autoplay-countdown__button autoplay-countdown__button--' + (timer % 5)}>
|
|
|
|
<Button onClick={doNavigate} iconSize={30} title={__('Play')} className="button--icon button--play" />
|
|
|
|
</div>
|
2020-06-22 10:34:39 +02:00
|
|
|
{isTimerPaused && (
|
2020-06-22 08:55:52 +02:00
|
|
|
<div className="file-viewer__overlay-secondary autoplay-countdown__counter">
|
|
|
|
{__('Autoplay timer paused.')}{' '}
|
|
|
|
</div>
|
|
|
|
)}
|
2020-06-22 10:34:39 +02:00
|
|
|
{!isTimerPaused && (
|
2020-06-22 08:55:52 +02:00
|
|
|
<div className="file-viewer__overlay-secondary autoplay-countdown__counter">
|
2021-09-10 19:27:21 +02:00
|
|
|
{__('Playing %message% in %seconds_left% seconds...', {
|
|
|
|
message: skipPaid ? __('next free content') : __(''),
|
|
|
|
seconds_left: timer,
|
|
|
|
})}{' '}
|
|
|
|
<Button
|
|
|
|
label={__('Cancel')}
|
|
|
|
button="link"
|
|
|
|
onClick={() => {
|
|
|
|
setTimerCanceled(true);
|
|
|
|
if (onCanceled) onCanceled();
|
|
|
|
}}
|
|
|
|
/>
|
2020-06-22 08:55:52 +02:00
|
|
|
</div>
|
|
|
|
)}
|
2021-09-10 19:27:21 +02:00
|
|
|
{skipPaid && doPrevious && (
|
|
|
|
<div>
|
|
|
|
<Button
|
|
|
|
label={__('Play Previous')}
|
|
|
|
button="link"
|
|
|
|
icon={ICONS.PLAY_PREVIOUS}
|
|
|
|
onClick={() => doPrevious()}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div>
|
|
|
|
<Button
|
|
|
|
label={skipPaid ? __('Purchase?') : __('Replay?')}
|
|
|
|
button="link"
|
|
|
|
iconRight={skipPaid ? ICONS.WALLET : ICONS.REPLAY}
|
|
|
|
onClick={() => {
|
|
|
|
setTimerCanceled(true);
|
|
|
|
doReplay();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2020-01-27 19:52:25 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withRouter(AutoplayCountdown);
|