From a96d2a47be29b72a590676cb0f32112c288303f4 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Thu, 30 Dec 2021 13:36:28 -0600 Subject: [PATCH] Create new anytime form state to explicitly set to release to now. Clear internal scheduled tag when editing. --- .../publishStreamReleaseDate/view.jsx | 11 +++++++--- ui/redux/actions/publish.js | 22 +++++++++++-------- ui/redux/reducers/publish.js | 2 ++ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/ui/component/publishStreamReleaseDate/view.jsx b/ui/component/publishStreamReleaseDate/view.jsx index 6abcf3223..837ffce20 100644 --- a/ui/component/publishStreamReleaseDate/view.jsx +++ b/ui/component/publishStreamReleaseDate/view.jsx @@ -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.' diff --git a/ui/redux/actions/publish.js b/ui/redux/actions/publish.js index 83519b24a..811f7d143 100644 --- a/ui/redux/actions/publish.js +++ b/ui/redux/actions/publish.js @@ -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, @@ -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); } diff --git a/ui/redux/reducers/publish.js b/ui/redux/reducers/publish.js index aaf8a9a63..dd527a3cc 100644 --- a/ui/redux/reducers/publish.js +++ b/ui/redux/reducers/publish.js @@ -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: '',