2021-12-16 22:59:13 +01:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import Icon from 'component/common/icon';
|
|
|
|
import moment from 'moment';
|
|
|
|
import 'scss/component/livestream-scheduled-info.scss';
|
2022-03-31 09:21:28 +02:00
|
|
|
import I18nMessage from 'component/i18nMessage';
|
|
|
|
import { getTimeAgoStr } from 'util/time';
|
2021-12-16 22:59:13 +01:00
|
|
|
|
|
|
|
type Props = {
|
2022-03-31 09:21:28 +02:00
|
|
|
releaseTimeMs: number,
|
2021-12-16 22:59:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function LivestreamScheduledInfo(props: Props) {
|
2022-03-31 09:21:28 +02:00
|
|
|
const { releaseTimeMs } = props;
|
|
|
|
const [startDateFromNow, setStartDateFromNow] = useState('');
|
2021-12-16 22:59:13 +01:00
|
|
|
const [inPast, setInPast] = useState('pending');
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const calcTime = () => {
|
2022-03-31 09:21:28 +02:00
|
|
|
const zeroDurationStr = '---';
|
|
|
|
const timeAgoStr = getTimeAgoStr(releaseTimeMs, true, true, zeroDurationStr);
|
|
|
|
|
|
|
|
if (timeAgoStr === zeroDurationStr) {
|
|
|
|
setInPast(true);
|
|
|
|
} else {
|
|
|
|
setStartDateFromNow(timeAgoStr);
|
|
|
|
setInPast(releaseTimeMs < Date.now());
|
|
|
|
}
|
2021-12-16 22:59:13 +01:00
|
|
|
};
|
2022-03-31 09:21:28 +02:00
|
|
|
|
2021-12-16 22:59:13 +01:00
|
|
|
const intervalId = setInterval(calcTime, 1000);
|
2022-03-31 09:21:28 +02:00
|
|
|
return () => clearInterval(intervalId);
|
|
|
|
}, [releaseTimeMs]);
|
2021-12-16 22:59:13 +01:00
|
|
|
|
2022-03-31 09:21:28 +02:00
|
|
|
const startDate = moment(releaseTimeMs).format('MMMM Do, h:mm a');
|
2021-12-16 22:59:13 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
inPast !== 'pending' && (
|
|
|
|
<div className={'livestream-scheduled'}>
|
|
|
|
<Icon icon={ICONS.LIVESTREAM_SOLID} size={32} />
|
|
|
|
<p className={'livestream-scheduled__time'}>
|
|
|
|
{!inPast && (
|
|
|
|
<span>
|
2022-03-31 09:21:28 +02:00
|
|
|
<I18nMessage tokens={{ time_date: startDateFromNow }}>Live %time_date%</I18nMessage>
|
2021-12-16 22:59:13 +01:00
|
|
|
<br />
|
|
|
|
<span className={'livestream-scheduled__date'}>{startDate}</span>
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{inPast && <span>{__('Starting Soon')}</span>}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|