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 (
|
|
|
|
<div className="">
|
|
|
|
<label htmlFor="date-picker-input">{__('When do you want to go live?')}</label>
|
|
|
|
|
|
|
|
<div className={'w-full flex flex-col mt-s md:mt-0 md:h-12 md:items-center md:flex-row'}>
|
|
|
|
<FormField
|
2021-12-22 22:45:47 +01:00
|
|
|
type="radio"
|
|
|
|
name="anytime"
|
2021-12-16 22:59:13 +01:00
|
|
|
disabled={false}
|
|
|
|
onChange={handleToggle}
|
|
|
|
checked={!publishLater}
|
|
|
|
label={__('Anytime')}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div className={'md:ml-m mt-s md:mt-0'}>
|
|
|
|
<FormField
|
2021-12-22 22:45:47 +01:00
|
|
|
type="radio"
|
|
|
|
name="scheduled_time"
|
2021-12-16 22:59:13 +01:00
|
|
|
disabled={false}
|
|
|
|
onChange={handleToggle}
|
|
|
|
checked={publishLater}
|
|
|
|
label={__('Scheduled Time')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{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>
|
|
|
|
|
|
|
|
<p className={'form-field__hint mt-m'}>{helpText}</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PublishStreamReleaseDate;
|