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
import React from 'react';
import React, { useEffect } from 'react';
import { FormField } from 'component/common/form';
import DateTimePicker from 'react-datetime-picker';
import moment from 'moment';
@ -33,13 +33,18 @@ const PublishStreamReleaseDate = (props: Props) => {
const onDateTimePickerChanged = (value) => {
if (value === 'DEFAULT') {
setDate(undefined);
updatePublishForm({ releaseTimeEdited: undefined });
updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: true });
} else {
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
? __(
'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,
language,
releaseTimeEdited,
releaseAnytime,
// license,
licenseUrl,
useLBRYUploader,
@ -93,6 +94,8 @@ function resolvePublishPayload(publishData, myClaimForUri, myChannels, preview)
const namedChannelClaim = myChannels ? myChannels.find((myChannel) => myChannel.name === channel) : null;
const channelId = namedChannelClaim ? namedChannelClaim.claim_id : '';
const nowTimeStamp = Number(Math.round(Date.now() / 1000));
const publishPayload: {
name: ?string,
bid: string,
@ -102,7 +105,7 @@ function resolvePublishPayload(publishData, myClaimForUri, myChannels, preview)
license_url?: string,
license?: string,
thumbnail_url?: string,
release_time?: number,
release_time: number,
fee_currency?: string,
fee_amount?: string,
languages?: Array<string>,
@ -121,6 +124,7 @@ function resolvePublishPayload(publishData, myClaimForUri, myChannels, preview)
languages: [language],
tags: tags && tags.map((tag) => tag.name),
thumbnail_url: thumbnail,
release_time: nowTimeStamp,
blocking: true,
preview: false,
};
@ -148,20 +152,20 @@ function resolvePublishPayload(publishData, myClaimForUri, myChannels, preview)
publishPayload.tags.push(LBRY_FIRST_TAG);
}
const nowTimeStamp = Number(Math.round(Date.now() / 1000));
// Set release time to current date. On edits, keep original release/transaction time as release_time
// 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
if (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);
} else if (myClaimForUriEditing && myClaimForUriEditing.timestamp) {
} else if (!releaseAnytime && myClaimForUriEditing && 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) {
publishPayload.tags.push(SCHEDULED_LIVESTREAM_TAG);
}

View file

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