2021-12-16 22:59:13 +01:00
|
|
|
// @flow
|
2021-12-30 20:36:28 +01:00
|
|
|
import React, { useEffect } from 'react';
|
2021-12-16 22:59:13 +01:00
|
|
|
import { FormField } from 'component/common/form';
|
|
|
|
import DateTimePicker from 'react-datetime-picker';
|
|
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
function linuxTimestampToDate(linuxTimestamp: number) {
|
|
|
|
return new Date(linuxTimestamp * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function dateToLinuxTimestamp(date: Date) {
|
|
|
|
return Number(Math.round(date.getTime() / 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
type Props = {
|
2022-01-05 15:59:26 +01:00
|
|
|
isScheduled: boolean,
|
2021-12-16 22:59:13 +01:00
|
|
|
releaseTime: ?number,
|
|
|
|
updatePublishForm: ({}) => void,
|
|
|
|
};
|
|
|
|
const PublishStreamReleaseDate = (props: Props) => {
|
2022-01-05 15:59:26 +01:00
|
|
|
const { isScheduled, releaseTime, updatePublishForm } = props;
|
2021-12-16 22:59:13 +01:00
|
|
|
|
|
|
|
const [date, setDate] = React.useState(releaseTime ? linuxTimestampToDate(releaseTime) : 'DEFAULT');
|
2022-01-05 15:59:26 +01:00
|
|
|
const [publishLater, setPublishLater] = React.useState(isScheduled);
|
2021-12-16 22:59:13 +01:00
|
|
|
|
|
|
|
const handleToggle = () => {
|
|
|
|
const shouldPublishLater = !publishLater;
|
|
|
|
setPublishLater(shouldPublishLater);
|
|
|
|
onDateTimePickerChanged(
|
|
|
|
shouldPublishLater ? moment().add('1', 'hour').add('30', 'minutes').startOf('hour').toDate() : 'DEFAULT'
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const onDateTimePickerChanged = (value) => {
|
|
|
|
if (value === 'DEFAULT') {
|
|
|
|
setDate(undefined);
|
2021-12-30 20:36:28 +01:00
|
|
|
updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: true });
|
2021-12-16 22:59:13 +01:00
|
|
|
} else {
|
|
|
|
setDate(value);
|
2021-12-30 20:36:28 +01:00
|
|
|
updatePublishForm({ releaseTimeEdited: dateToLinuxTimestamp(value), releaseAnytime: false });
|
2021-12-16 22:59:13 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-12-30 20:36:28 +01:00
|
|
|
useEffect(() => {
|
2022-01-05 15:59:26 +01:00
|
|
|
if (!isScheduled) updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: true });
|
2021-12-30 20:36:28 +01:00
|
|
|
return () => updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: false });
|
|
|
|
}, []);
|
|
|
|
|
2021-12-16 22:59:13 +01:00
|
|
|
const helpText = !publishLater
|
|
|
|
? __(
|
|
|
|
'Confirmation process takes a few minutes, but then you can go live anytime. The stream is not shown anywhere until you are broadcasting.'
|
|
|
|
)
|
|
|
|
: __(
|
|
|
|
'Your scheduled streams will appear on your channel page and for your followers. Chat will not be active until 5 minutes before the start time.'
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2022-06-03 15:28:12 +02:00
|
|
|
<>
|
|
|
|
<h2 className="card__title">{__('Date')}</h2>
|
|
|
|
<div className="card--date">
|
|
|
|
<label htmlFor="date-picker-input">{__('When do you want to go live?')}</label>
|
2021-12-16 22:59:13 +01:00
|
|
|
|
2022-06-03 15:28:12 +02:00
|
|
|
<div className={'w-full flex flex-col mt-s md:mt-0 md:h-12 md:items-center md:flex-row'}>
|
2021-12-16 22:59:13 +01:00
|
|
|
<FormField
|
2021-12-22 22:45:47 +01:00
|
|
|
type="radio"
|
2022-06-03 15:28:12 +02:00
|
|
|
name="anytime"
|
2021-12-16 22:59:13 +01:00
|
|
|
disabled={false}
|
|
|
|
onChange={handleToggle}
|
2022-06-03 15:28:12 +02:00
|
|
|
checked={!publishLater}
|
|
|
|
label={__('Anytime')}
|
2021-12-16 22:59:13 +01:00
|
|
|
/>
|
2022-06-03 15:28:12 +02:00
|
|
|
|
|
|
|
<div className={'md:ml-m mt-s md:mt-0'}>
|
|
|
|
<FormField
|
|
|
|
type="radio"
|
|
|
|
name="scheduled_time"
|
|
|
|
disabled={false}
|
|
|
|
onChange={handleToggle}
|
|
|
|
checked={publishLater}
|
|
|
|
label={__('Scheduled Time')}
|
2021-12-16 22:59:13 +01:00
|
|
|
/>
|
|
|
|
</div>
|
2022-06-03 15:28:12 +02:00
|
|
|
{publishLater && (
|
|
|
|
<div className="form-field-date-picker mb-0 controls md:ml-m">
|
|
|
|
<DateTimePicker
|
|
|
|
className="date-picker-input w-full md:w-auto mt-s md:mt-0"
|
|
|
|
calendarClassName="form-field-calendar"
|
|
|
|
onChange={onDateTimePickerChanged}
|
|
|
|
value={date}
|
|
|
|
format="y-MM-dd h:mm a"
|
|
|
|
disableClock
|
|
|
|
clearIcon={null}
|
|
|
|
minDate={moment().add('30', 'minutes').toDate()}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-12-16 22:59:13 +01:00
|
|
|
|
2022-06-03 15:28:12 +02:00
|
|
|
<p className={'form-field__hint mt-m'}>{helpText}</p>
|
|
|
|
</div>
|
|
|
|
</>
|
2021-12-16 22:59:13 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PublishStreamReleaseDate;
|