Create new anytime form state to explicitly set to release to now. Clear internal scheduled tag when editing.

This commit is contained in:
Dan Peterson 2021-12-30 13:36:28 -06:00 committed by Thomas Zarebczan
parent 399c4eb56d
commit a96d2a47be
3 changed files with 23 additions and 12 deletions

View file

@ -1,5 +1,5 @@
// @flow // @flow
import React from 'react'; import React, { useEffect } from 'react';
import { FormField } from 'component/common/form'; import { FormField } from 'component/common/form';
import DateTimePicker from 'react-datetime-picker'; import DateTimePicker from 'react-datetime-picker';
import moment from 'moment'; import moment from 'moment';
@ -33,13 +33,18 @@ const PublishStreamReleaseDate = (props: Props) => {
const onDateTimePickerChanged = (value) => { const onDateTimePickerChanged = (value) => {
if (value === 'DEFAULT') { if (value === 'DEFAULT') {
setDate(undefined); setDate(undefined);
updatePublishForm({ releaseTimeEdited: undefined }); updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: true });
} else { } else {
setDate(value); setDate(value);
updatePublishForm({ releaseTimeEdited: dateToLinuxTimestamp(value) }); updatePublishForm({ releaseTimeEdited: dateToLinuxTimestamp(value), releaseAnytime: false });
} }
}; };
useEffect(() => {
if (!releaseTime) updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: true });
return () => updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: false });
}, []);
const helpText = !publishLater 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.' 'Confirmation process takes a few minutes, but then you can go live anytime. The stream is not shown anywhere until you are broadcasting.'

View file

@ -58,6 +58,7 @@ function resolvePublishPayload(publishData, myClaimForUri, myChannels, preview)
description, description,
language, language,
releaseTimeEdited, releaseTimeEdited,
releaseAnytime,
// license, // license,
licenseUrl, licenseUrl,
useLBRYUploader, useLBRYUploader,
@ -93,6 +94,8 @@ function resolvePublishPayload(publishData, myClaimForUri, myChannels, preview)
const namedChannelClaim = myChannels ? myChannels.find((myChannel) => myChannel.name === channel) : null; const namedChannelClaim = myChannels ? myChannels.find((myChannel) => myChannel.name === channel) : null;
const channelId = namedChannelClaim ? namedChannelClaim.claim_id : ''; const channelId = namedChannelClaim ? namedChannelClaim.claim_id : '';
const nowTimeStamp = Number(Math.round(Date.now() / 1000));
const publishPayload: { const publishPayload: {
name: ?string, name: ?string,
bid: string, bid: string,
@ -102,7 +105,7 @@ function resolvePublishPayload(publishData, myClaimForUri, myChannels, preview)
license_url?: string, license_url?: string,
license?: string, license?: string,
thumbnail_url?: string, thumbnail_url?: string,
release_time?: number, release_time: number,
fee_currency?: string, fee_currency?: string,
fee_amount?: string, fee_amount?: string,
languages?: Array<string>, languages?: Array<string>,
@ -121,6 +124,7 @@ function resolvePublishPayload(publishData, myClaimForUri, myChannels, preview)
languages: [language], languages: [language],
tags: tags && tags.map((tag) => tag.name), tags: tags && tags.map((tag) => tag.name),
thumbnail_url: thumbnail, thumbnail_url: thumbnail,
release_time: nowTimeStamp,
blocking: true, blocking: true,
preview: false, preview: false,
}; };
@ -148,20 +152,20 @@ function resolvePublishPayload(publishData, myClaimForUri, myChannels, preview)
publishPayload.tags.push(LBRY_FIRST_TAG); publishPayload.tags.push(LBRY_FIRST_TAG);
} }
const nowTimeStamp = Number(Math.round(Date.now() / 1000)); // Set release time to the newly edited time.
// On edits, if not explicitly set to anytime, keep the original release/transaction time as release_time
// Set release time to current date. On edits, keep original release/transaction time as release_time
if (releaseTimeEdited) { if (releaseTimeEdited) {
publishPayload.release_time = releaseTimeEdited; publishPayload.release_time = releaseTimeEdited;
} else if (myClaimForUriEditing && myClaimForUriEditing.value.release_time) { } else if (!releaseAnytime && myClaimForUriEditing && myClaimForUriEditing.value.release_time) {
publishPayload.release_time = Number(myClaimForUri.value.release_time); publishPayload.release_time = Number(myClaimForUri.value.release_time);
} else if (myClaimForUriEditing && myClaimForUriEditing.timestamp) { } else if (!releaseAnytime && myClaimForUriEditing && myClaimForUriEditing.timestamp) {
publishPayload.release_time = Number(myClaimForUriEditing.timestamp); publishPayload.release_time = Number(myClaimForUriEditing.timestamp);
} else {
publishPayload.release_time = nowTimeStamp;
} }
// Add internal tag if a livestream is being scheduled. // Remove internal scheduled tag if it exists.
publishPayload.tags = publishPayload.tags.filter((tag) => tag !== SCHEDULED_LIVESTREAM_TAG);
// Add internal scheduled tag if claim is a livestream and is being scheduled in the future.
if (isLivestreamPublish && publishPayload.release_time > nowTimeStamp) { if (isLivestreamPublish && publishPayload.release_time > nowTimeStamp) {
publishPayload.tags.push(SCHEDULED_LIVESTREAM_TAG); publishPayload.tags.push(SCHEDULED_LIVESTREAM_TAG);
} }

View file

@ -33,6 +33,7 @@ type PublishState = {
language: string, language: string,
releaseTime: ?number, releaseTime: ?number,
releaseTimeEdited: ?number, releaseTimeEdited: ?number,
releaseAnytime: boolean,
channel: string, channel: string,
channelId: ?string, channelId: ?string,
name: string, name: string,
@ -71,6 +72,7 @@ const defaultState: PublishState = {
language: '', language: '',
releaseTime: undefined, releaseTime: undefined,
releaseTimeEdited: undefined, releaseTimeEdited: undefined,
releaseAnytime: false,
nsfw: false, nsfw: false,
channel: CHANNEL_ANONYMOUS, channel: CHANNEL_ANONYMOUS,
channelId: '', channelId: '',