lbry-desktop/ui/component/publishStreamReleaseDate/view.jsx
Dan Peterson da06c14e60
Fix publish form when editing livestream (#565)
* Update publish form when editing livestream + update to radios for liveststream release time

* Fix bug where upload tools may remain visible upon switching upload type, even when no option to upload is available.

* move publish source state up, when editing livestream only show scheduling option when source is none.

* Reset any set release time if switching to live stream mode.

* Update date/time cmpnts to reset any chnages they made on umount. Update schedule date/time cmpnt to clear release time when selecting anytime option.

* Additional filtering of internal tags

* Default to replay view when editing a liveststream
2021-12-31 11:20:54 -06:00

101 lines
3.3 KiB
JavaScript

// @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 = {
releaseTime: ?number,
updatePublishForm: ({}) => void,
};
const PublishStreamReleaseDate = (props: Props) => {
const { releaseTime, updatePublishForm } = props;
const [date, setDate] = React.useState(releaseTime ? linuxTimestampToDate(releaseTime) : 'DEFAULT');
const [publishLater, setPublishLater] = React.useState(Boolean(releaseTime));
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 (!releaseTime) 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 (
<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
type="radio"
name="anytime"
disabled={false}
onChange={handleToggle}
checked={!publishLater}
label={__('Anytime')}
/>
<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')}
/>
</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;