// @flow import React, { useEffect } from 'react'; 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 = { isScheduled: boolean, releaseTime: ?number, updatePublishForm: ({}) => void, }; const PublishStreamReleaseDate = (props: Props) => { const { isScheduled, releaseTime, updatePublishForm } = props; const [date, setDate] = React.useState(releaseTime ? linuxTimestampToDate(releaseTime) : 'DEFAULT'); const [publishLater, setPublishLater] = React.useState(isScheduled); 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); updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: true }); } else { setDate(value); updatePublishForm({ releaseTimeEdited: dateToLinuxTimestamp(value), releaseAnytime: false }); } }; useEffect(() => { if (!isScheduled) updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: true }); return () => updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: false }); }, []); 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 (
{helpText}