tom rebase attempt #5881

Closed
tzarebczan wants to merge 10 commits from replays-rebased-tom into master
4 changed files with 41 additions and 13 deletions
Showing only changes of commit 0b643028d7 - Show all commits

View file

@ -48,6 +48,7 @@ type Props = {
isLivestreamClaim: boolean, isLivestreamClaim: boolean,
checkLivestreams: () => void, checkLivestreams: () => void,
isCheckingLivestreams: boolean, isCheckingLivestreams: boolean,
setWaitForFile: (boolean) => void,
}; };
function PublishFile(props: Props) { function PublishFile(props: Props) {
@ -78,6 +79,7 @@ function PublishFile(props: Props) {
subtitle, subtitle,
checkLivestreams, checkLivestreams,
isCheckingLivestreams, isCheckingLivestreams,
setWaitForFile,
} = props; } = props;
const SOURCE_NONE = 'none'; const SOURCE_NONE = 'none';
@ -111,6 +113,7 @@ function PublishFile(props: Props) {
{ label: __('None'), actionName: SOURCE_NONE }, { label: __('None'), actionName: SOURCE_NONE },
]; ];
const livestreamDataStr = JSON.stringify(livestreamData);
const hasLivestreamData = livestreamData && Boolean(livestreamData.length); const hasLivestreamData = livestreamData && Boolean(livestreamData.length);
const showSourceSelector = isLivestreamClaim; const showSourceSelector = isLivestreamClaim;
@ -138,6 +141,7 @@ function PublishFile(props: Props) {
// set default file source to select if necessary // set default file source to select if necessary
useEffect(() => { useEffect(() => {
if (hasLivestreamData && isLivestreamClaim) { if (hasLivestreamData && isLivestreamClaim) {
setWaitForFile(true);
setFileSelectSource(SOURCE_SELECT); setFileSelectSource(SOURCE_SELECT);
} else if (isLivestreamClaim) { } else if (isLivestreamClaim) {
setFileSelectSource(SOURCE_NONE); setFileSelectSource(SOURCE_NONE);
@ -157,12 +161,13 @@ function PublishFile(props: Props) {
}; };
// update remoteUrl when replay selected // update remoteUrl when replay selected
useEffect(() => { useEffect(() => {
if (selectedFileIndex !== null) { const livestreamData = JSON.parse(livestreamDataStr);
if (selectedFileIndex !== null && livestreamData && livestreamData.length) {
updatePublishForm({ updatePublishForm({
remoteFileUrl: normalizeUrlForProtocol(livestreamData[selectedFileIndex].data.fileLocation), remoteFileUrl: normalizeUrlForProtocol(livestreamData[selectedFileIndex].data.fileLocation),
}); });
} }
}, [selectedFileIndex, updatePublishForm]); }, [selectedFileIndex, updatePublishForm, livestreamDataStr]);
useEffect(() => { useEffect(() => {
if (!filePath || filePath === '') { if (!filePath || filePath === '') {
@ -320,6 +325,7 @@ function PublishFile(props: Props) {
} }
} }
setFileSelectSource(source); setFileSelectSource(source);
setWaitForFile(source !== SOURCE_NONE);
} }
function handleTitleChange(event) { function handleTitleChange(event) {

View file

@ -14,6 +14,7 @@ import {
SETTINGS, SETTINGS,
selectMyChannelClaims, selectMyChannelClaims,
makeSelectClaimIsStreamPlaceholder, makeSelectClaimIsStreamPlaceholder,
makeSelectPublishFormValue,
} from 'lbry-redux'; } from 'lbry-redux';
import * as RENDER_MODES from 'constants/file_render_modes'; import * as RENDER_MODES from 'constants/file_render_modes';
import { doPublishDesktop } from 'redux/actions/publish'; import { doPublishDesktop } from 'redux/actions/publish';
@ -45,6 +46,8 @@ const select = (state) => {
// If I clicked the "edit" button, have I changed the uri? // If I clicked the "edit" button, have I changed the uri?
// Need this to make it easier to find the source on previously published content // Need this to make it easier to find the source on previously published content
myClaimForUri, myClaimForUri,
filePath: makeSelectPublishFormValue('filePath')(state),
remoteUrl: makeSelectPublishFormValue('remoteFileUrl')(state),
isStillEditing: selectIsStillEditing(state), isStillEditing: selectIsStillEditing(state),
isResolvingUri: selectIsResolvingPublishUris(state), isResolvingUri: selectIsResolvingPublishUris(state),
totalRewardValue: selectUnclaimedRewardValue(state), totalRewardValue: selectUnclaimedRewardValue(state),

View file

@ -9,7 +9,8 @@
*/ */
import { SITE_NAME, ENABLE_NO_SOURCE_CLAIMS, SIMPLE_SITE, CHANNEL_STAKED_LEVEL_LIVESTREAM } from 'config'; import { SITE_NAME, ENABLE_NO_SOURCE_CLAIMS, SIMPLE_SITE, CHANNEL_STAKED_LEVEL_LIVESTREAM } from 'config';
import React, { useEffect } from 'react'; import { SITE_NAME, ENABLE_NO_SOURCE_CLAIMS, SIMPLE_SITE } from 'config';
import React, { useEffect, useState } from 'react';
import { buildURI, isURIValid, isNameValid, THUMBNAIL_STATUSES, Lbry } from 'lbry-redux'; import { buildURI, isURIValid, isNameValid, THUMBNAIL_STATUSES, Lbry } from 'lbry-redux';
import Button from 'component/button'; import Button from 'component/button';
import ChannelSelect from 'component/channelSelector'; import ChannelSelect from 'component/channelSelector';
@ -87,6 +88,7 @@ type Props = {
isLivestreamClaim: boolean, isLivestreamClaim: boolean,
isPostClaim: boolean, isPostClaim: boolean,
permanentUrl: ?string, permanentUrl: ?string,
remoteUrl: ?string,
}; };
function PublishForm(props: Props) { function PublishForm(props: Props) {
@ -122,6 +124,7 @@ function PublishForm(props: Props) {
isLivestreamClaim, isLivestreamClaim,
isPostClaim, isPostClaim,
permanentUrl, permanentUrl,
remoteUrl,
} = props; } = props;
const { replace, location } = useHistory(); const { replace, location } = useHistory();
@ -189,8 +192,9 @@ function PublishForm(props: Props) {
const [fileEdited, setFileEdited] = React.useState(false); const [fileEdited, setFileEdited] = React.useState(false);
const [prevFileText, setPrevFileText] = React.useState(''); const [prevFileText, setPrevFileText] = React.useState('');
const [waitForFile, setWaitForFile] = useState(false);
const [livestreamData, setLivestreamData] = React.useState([]); const [livestreamData, setLivestreamData] = React.useState([]);
const [signedMessage, setSignedMessage] = React.useState({}); const [signedMessage, setSignedMessage] = React.useState({ signature: undefined, signing_ts: undefined });
const signedMessageStr = JSON.stringify(signedMessage); const signedMessageStr = JSON.stringify(signedMessage);
const TAGS_LIMIT = 5; const TAGS_LIMIT = 5;
const fileFormDisabled = mode === PUBLISH_MODES.FILE && !filePath; const fileFormDisabled = mode === PUBLISH_MODES.FILE && !filePath;
@ -208,6 +212,7 @@ function PublishForm(props: Props) {
const nameEdited = isStillEditing && name !== prevName; const nameEdited = isStillEditing && name !== prevName;
const waitingForFile = waitForFile && !remoteUrl && !filePath;
// If they are editing, they don't need a new file chosen // If they are editing, they don't need a new file chosen
const formValidLessFile = const formValidLessFile =
name && name &&
@ -222,8 +227,8 @@ function PublishForm(props: Props) {
const formValid = isOverwritingExistingClaim const formValid = isOverwritingExistingClaim
? false ? false
: editingURI && !filePath : editingURI && !filePath // if we're editing we don't need a file
? isStillEditing && formValidLessFile ? isStillEditing && formValidLessFile && !waitingForFile
: formValidLessFile; : formValidLessFile;
const [previewing, setPreviewing] = React.useState(false); const [previewing, setPreviewing] = React.useState(false);
@ -258,10 +263,9 @@ function PublishForm(props: Props) {
}, [modal]); }, [modal]);
// move this to lbryinc OR to a file under ui, and/or provide a standardized livestreaming config. // move this to lbryinc OR to a file under ui, and/or provide a standardized livestreaming config.
function checkLivestreams(channelId, signature, timestamp) { function fetchLivestreams(channelId, signature, timestamp) {
// $FlowFixMe Bitwave's API can handle garbage
setCheckingLivestreams(true); setCheckingLivestreams(true);
fetch(`${BITWAVE_REPLAY_API}/${channelId}?signature=${signature}&signing_ts=${timestamp}`) // claimChannelId fetch(`${BITWAVE_REPLAY_API}/${channelId}?signature=${signature || ''}&signing_ts=${timestamp || ''}`) // claimChannelId
.then((res) => res.json()) .then((res) => res.json())
.then((res) => { .then((res) => {
if (!res || !res.data) { if (!res || !res.data) {
@ -279,7 +283,7 @@ function PublishForm(props: Props) {
useEffect(() => { useEffect(() => {
const signedMessage = JSON.parse(signedMessageStr); const signedMessage = JSON.parse(signedMessageStr);
if (claimChannelId && isLivestreamClaim && signedMessage.signature) { if (claimChannelId && isLivestreamClaim && signedMessage.signature) {
checkLivestreams(claimChannelId, signedMessage.signature, signedMessage.signing_ts); fetchLivestreams(claimChannelId, signedMessage.signature, signedMessage.signing_ts);
} }
}, [claimChannelId, isLivestreamClaim, signedMessageStr]); }, [claimChannelId, isLivestreamClaim, signedMessageStr]);
@ -544,8 +548,11 @@ function PublishForm(props: Props) {
setPrevFileText={setPrevFileText} setPrevFileText={setPrevFileText}
livestreamData={livestreamData} livestreamData={livestreamData}
subtitle={customSubtitle} subtitle={customSubtitle}
setWaitForFile={setWaitForFile}
isCheckingLivestreams={isCheckingLivestreams} isCheckingLivestreams={isCheckingLivestreams}
checkLivestreams={checkLivestreams} checkLivestreams={(claimChannelId, signature = signedMessage.signature, ts = signedMessage.signing_ts) =>
fetchLivestreams(claimChannelId, signature, ts)
}
header={ header={
<> <>
{AVAILABLE_MODES.map((modeName) => ( {AVAILABLE_MODES.map((modeName) => (
@ -619,7 +626,7 @@ function PublishForm(props: Props) {
</div> </div>
<p className="help"> <p className="help">
{!formDisabled && !formValid ? ( {!formDisabled && !formValid ? (
<PublishFormErrors mode={mode} /> <PublishFormErrors mode={mode} waitForFile={waitingForFile} />
) : ( ) : (
<I18nMessage <I18nMessage
tokens={{ tokens={{

View file

@ -12,14 +12,26 @@ type Props = {
filePath: ?string, filePath: ?string,
isStillEditing: boolean, isStillEditing: boolean,
uploadThumbnailStatus: string, uploadThumbnailStatus: string,
waitForFile: boolean,
}; };
function PublishFormErrors(props: Props) { function PublishFormErrors(props: Props) {
const { name, title, bid, bidError, editingURI, filePath, isStillEditing, uploadThumbnailStatus } = props; const {
name,
title,
bid,
bidError,
editingURI,
filePath,
isStillEditing,
uploadThumbnailStatus,
waitForFile,
} = props;
// These are extra help // These are extra help
// If there is an error it will be presented as an inline error as well // If there is an error it will be presented as an inline error as well
return ( return (
<div className="error__text"> <div className="error__text">
{waitForFile && <div>{__('Choose a replay file, or select None')}</div>}
{!title && <div>{__('A title is required')}</div>} {!title && <div>{__('A title is required')}</div>}
{!name && <div>{__('A URL is required')}</div>} {!name && <div>{__('A URL is required')}</div>}
{!isNameValid(name, false) && INVALID_NAME_ERROR} {!isNameValid(name, false) && INVALID_NAME_ERROR}