2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2019-10-11 02:37:18 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
On submit, this component calls publish, which dispatches doPublishDesktop.
|
|
|
|
doPublishDesktop calls lbry-redux Lbry publish method using lbry-redux publish state as params.
|
|
|
|
Publish simply instructs the SDK to find the file path on disk and publish it with the provided metadata.
|
|
|
|
On web, the Lbry publish method call is overridden in platform/web/api-setup, using a function in platform/web/publish.
|
|
|
|
File upload is carried out in the background by that function.
|
|
|
|
*/
|
2020-04-01 20:43:50 +02:00
|
|
|
import React, { useEffect } from 'react';
|
2019-06-28 09:27:55 +02:00
|
|
|
import { CHANNEL_NEW, CHANNEL_ANONYMOUS } from 'constants/claim';
|
2019-07-24 20:21:34 +02:00
|
|
|
import { buildURI, isURIValid, isNameValid, THUMBNAIL_STATUSES } from 'lbry-redux';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Button from 'component/button';
|
2019-12-06 20:42:44 +01:00
|
|
|
import SelectChannel from 'component/selectChannel';
|
2018-03-26 23:32:43 +02:00
|
|
|
import classnames from 'classnames';
|
2019-10-08 22:40:10 +02:00
|
|
|
import TagsSelect from 'component/tagsSelect';
|
2019-06-28 09:27:55 +02:00
|
|
|
import PublishText from 'component/publishText';
|
|
|
|
import PublishPrice from 'component/publishPrice';
|
|
|
|
import PublishFile from 'component/publishFile';
|
2019-12-06 20:42:44 +01:00
|
|
|
import PublishName from 'component/publishName';
|
2019-06-28 09:27:55 +02:00
|
|
|
import PublishAdditionalOptions from 'component/publishAdditionalOptions';
|
|
|
|
import PublishFormErrors from 'component/publishFormErrors';
|
|
|
|
import SelectThumbnail from 'component/selectThumbnail';
|
2019-09-27 20:56:15 +02:00
|
|
|
import Card from 'component/common/card';
|
2020-05-26 06:10:05 +02:00
|
|
|
import I18nMessage from 'component/i18nMessage';
|
2018-03-26 23:32:43 +02:00
|
|
|
|
|
|
|
type Props = {
|
2019-10-28 19:53:59 +01:00
|
|
|
disabled: boolean,
|
2019-06-28 09:27:55 +02:00
|
|
|
tags: Array<Tag>,
|
2019-11-01 20:17:06 +01:00
|
|
|
publish: (?string) => void,
|
2018-03-26 23:32:43 +02:00
|
|
|
filePath: ?string,
|
|
|
|
bid: ?number,
|
2020-03-02 18:11:14 +01:00
|
|
|
bidError: ?string,
|
2018-03-26 23:32:43 +02:00
|
|
|
editingURI: ?string,
|
|
|
|
title: ?string,
|
|
|
|
thumbnail: ?string,
|
2018-04-02 15:53:29 +02:00
|
|
|
uploadThumbnailStatus: ?string,
|
2018-06-08 06:05:45 +02:00
|
|
|
thumbnailPath: ?string,
|
2018-03-26 23:32:43 +02:00
|
|
|
description: ?string,
|
|
|
|
language: string,
|
|
|
|
nsfw: boolean,
|
|
|
|
contentIsFree: boolean,
|
2019-05-10 01:26:03 +02:00
|
|
|
fee: {
|
2019-05-11 00:27:07 +02:00
|
|
|
amount: string,
|
2018-03-26 23:32:43 +02:00
|
|
|
currency: string,
|
|
|
|
},
|
|
|
|
channel: string,
|
|
|
|
name: ?string,
|
|
|
|
nameError: ?string,
|
|
|
|
isResolvingUri: boolean,
|
|
|
|
winningBidForClaimUri: number,
|
2019-04-24 16:02:08 +02:00
|
|
|
myClaimForUri: ?StreamClaim,
|
2018-03-26 23:32:43 +02:00
|
|
|
licenseType: string,
|
|
|
|
otherLicenseDescription: ?string,
|
|
|
|
licenseUrl: ?string,
|
|
|
|
uri: ?string,
|
|
|
|
publishing: boolean,
|
|
|
|
balance: number,
|
2018-06-12 07:11:17 +02:00
|
|
|
isStillEditing: boolean,
|
2018-03-26 23:32:43 +02:00
|
|
|
clearPublish: () => void,
|
|
|
|
resolveUri: string => void,
|
|
|
|
scrollToTop: () => void,
|
2018-10-13 17:49:47 +02:00
|
|
|
prepareEdit: (claim: any, uri: string) => void,
|
2018-04-02 15:53:29 +02:00
|
|
|
resetThumbnailStatus: () => void,
|
2018-09-25 02:17:08 +02:00
|
|
|
amountNeededForTakeover: ?number,
|
2019-06-28 09:27:55 +02:00
|
|
|
// Add back type
|
|
|
|
updatePublishForm: any => void,
|
2020-04-24 15:51:00 +02:00
|
|
|
checkAvailability: string => void,
|
2020-06-16 11:58:25 +02:00
|
|
|
onChannelChange: string => void,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
2019-06-28 09:27:55 +02:00
|
|
|
function PublishForm(props: Props) {
|
|
|
|
const {
|
|
|
|
thumbnail,
|
|
|
|
name,
|
|
|
|
channel,
|
|
|
|
editingURI,
|
|
|
|
resolveUri,
|
|
|
|
title,
|
|
|
|
bid,
|
2020-03-02 18:11:14 +01:00
|
|
|
bidError,
|
2019-06-28 09:27:55 +02:00
|
|
|
uploadThumbnailStatus,
|
|
|
|
resetThumbnailStatus,
|
|
|
|
updatePublishForm,
|
|
|
|
filePath,
|
|
|
|
publishing,
|
|
|
|
clearPublish,
|
|
|
|
isStillEditing,
|
|
|
|
tags,
|
|
|
|
publish,
|
2019-10-28 19:53:59 +01:00
|
|
|
disabled = false,
|
2020-04-24 15:51:00 +02:00
|
|
|
checkAvailability,
|
2020-06-16 11:58:25 +02:00
|
|
|
onChannelChange,
|
2019-06-28 09:27:55 +02:00
|
|
|
} = props;
|
2020-03-05 22:35:01 +01:00
|
|
|
const TAGS_LIMIT = 5;
|
2019-06-28 09:27:55 +02:00
|
|
|
const formDisabled = (!filePath && !editingURI) || publishing;
|
2019-12-26 16:37:26 +01:00
|
|
|
const isInProgress = filePath || editingURI || name || title;
|
|
|
|
|
2019-06-28 09:27:55 +02:00
|
|
|
// If they are editing, they don't need a new file chosen
|
2019-07-24 20:21:34 +02:00
|
|
|
const formValidLessFile =
|
2020-03-02 18:11:14 +01:00
|
|
|
name &&
|
|
|
|
isNameValid(name, false) &&
|
|
|
|
title &&
|
|
|
|
bid &&
|
|
|
|
!bidError &&
|
|
|
|
!(uploadThumbnailStatus === THUMBNAIL_STATUSES.IN_PROGRESS);
|
2019-06-28 09:27:55 +02:00
|
|
|
const formValid = editingURI && !filePath ? isStillEditing && formValidLessFile : formValidLessFile;
|
|
|
|
|
|
|
|
let submitLabel;
|
|
|
|
if (isStillEditing) {
|
2020-04-29 00:30:28 +02:00
|
|
|
submitLabel = !publishing ? __('Save') : __('Saving...');
|
2019-06-28 09:27:55 +02:00
|
|
|
} else {
|
|
|
|
submitLabel = !publishing ? __('Publish') : __('Publishing...');
|
2018-03-26 23:32:43 +02:00
|
|
|
}
|
|
|
|
|
2019-06-28 09:27:55 +02:00
|
|
|
useEffect(() => {
|
2018-07-17 19:43:43 +02:00
|
|
|
if (!thumbnail) {
|
2019-06-28 09:27:55 +02:00
|
|
|
resetThumbnailStatus();
|
2018-06-13 06:19:39 +02:00
|
|
|
}
|
2019-06-28 09:27:55 +02:00
|
|
|
}, [thumbnail, resetThumbnailStatus]);
|
2018-04-02 15:53:29 +02:00
|
|
|
|
2019-06-28 09:27:55 +02:00
|
|
|
// Every time the channel or name changes, resolve the uris to find winning bid amounts
|
|
|
|
useEffect(() => {
|
2018-04-04 01:17:40 +02:00
|
|
|
// If they are midway through a channel creation, treat it as anonymous until it completes
|
|
|
|
const channelName = channel === CHANNEL_ANONYMOUS || channel === CHANNEL_NEW ? '' : channel;
|
2018-03-26 23:32:43 +02:00
|
|
|
|
2018-09-25 02:17:08 +02:00
|
|
|
// We are only going to store the full uri, but we need to resolve the uri with and without the channel name
|
2018-04-04 01:17:40 +02:00
|
|
|
let uri;
|
|
|
|
try {
|
2019-11-01 18:27:01 +01:00
|
|
|
uri = name && buildURI({ streamName: name, channelName });
|
2019-06-28 09:27:55 +02:00
|
|
|
} catch (e) {}
|
|
|
|
|
2019-08-30 18:23:32 +02:00
|
|
|
if (channelName && name) {
|
2019-06-28 09:27:55 +02:00
|
|
|
// resolve without the channel name so we know the winning bid for it
|
2019-07-02 06:49:21 +02:00
|
|
|
try {
|
2019-08-30 01:18:06 +02:00
|
|
|
const uriLessChannel = buildURI({ streamName: name });
|
2019-07-02 06:49:21 +02:00
|
|
|
resolveUri(uriLessChannel);
|
|
|
|
} catch (e) {}
|
2017-06-30 10:45:54 +02:00
|
|
|
}
|
|
|
|
|
2019-07-03 16:49:28 +02:00
|
|
|
const isValid = isURIValid(uri);
|
2020-04-24 15:51:00 +02:00
|
|
|
if (uri && isValid && checkAvailability && name) {
|
2018-04-04 01:17:40 +02:00
|
|
|
resolveUri(uri);
|
2020-04-24 15:51:00 +02:00
|
|
|
checkAvailability(name);
|
2019-06-28 09:27:55 +02:00
|
|
|
updatePublishForm({ uri });
|
2017-06-30 10:45:54 +02:00
|
|
|
}
|
2020-04-24 15:51:00 +02:00
|
|
|
}, [name, channel, resolveUri, updatePublishForm, checkAvailability]);
|
2019-06-28 09:27:55 +02:00
|
|
|
|
2020-06-16 11:58:25 +02:00
|
|
|
function handleChannelNameChange(channel) {
|
|
|
|
onChannelChange(channel);
|
|
|
|
updatePublishForm({ channel });
|
|
|
|
}
|
|
|
|
|
2019-06-28 09:27:55 +02:00
|
|
|
return (
|
2020-04-01 20:43:50 +02:00
|
|
|
<div className="card-stack">
|
2019-12-26 16:37:26 +01:00
|
|
|
<PublishFile disabled={disabled || publishing} inProgress={isInProgress} />
|
2020-03-24 18:57:17 +01:00
|
|
|
{!publishing && (
|
|
|
|
<div className={classnames({ 'card--disabled': formDisabled })}>
|
|
|
|
<PublishText disabled={formDisabled} />
|
|
|
|
<Card actions={<SelectThumbnail />} />
|
2019-09-27 20:56:15 +02:00
|
|
|
|
2020-04-01 20:43:50 +02:00
|
|
|
<TagsSelect
|
|
|
|
suggestMature
|
|
|
|
disableAutoFocus
|
|
|
|
hideHeader
|
|
|
|
label={__('Selected Tags')}
|
|
|
|
empty={__('No tags added')}
|
|
|
|
limitSelect={TAGS_LIMIT}
|
|
|
|
help={__(
|
|
|
|
'Add tags that are relevant to your content. If mature content, ensure it is tagged mature. Tag abuse and missing mature tags will not be tolerated.'
|
|
|
|
)}
|
|
|
|
placeholder={__('gaming, crypto')}
|
|
|
|
onSelect={newTags => {
|
|
|
|
const validatedTags = [];
|
|
|
|
newTags.forEach(newTag => {
|
|
|
|
if (!tags.some(tag => tag.name === newTag.name)) {
|
|
|
|
validatedTags.push(newTag);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
updatePublishForm({ tags: [...tags, ...validatedTags] });
|
|
|
|
}}
|
|
|
|
onRemove={clickedTag => {
|
|
|
|
const newTags = tags.slice().filter(tag => tag.name !== clickedTag.name);
|
|
|
|
updatePublishForm({ tags: newTags });
|
|
|
|
}}
|
|
|
|
tagsChosen={tags}
|
|
|
|
/>
|
2019-09-27 20:56:15 +02:00
|
|
|
|
2020-03-24 18:57:17 +01:00
|
|
|
<Card
|
|
|
|
actions={
|
|
|
|
<React.Fragment>
|
2020-06-16 11:58:25 +02:00
|
|
|
<SelectChannel channel={channel} onChannelChange={handleChannelNameChange} />
|
2020-03-24 18:57:17 +01:00
|
|
|
<p className="help">
|
|
|
|
{__('This is a username or handle that your content can be found under.')}{' '}
|
|
|
|
{__('Ex. @Marvel, @TheBeatles, @BooksByJoe')}
|
|
|
|
</p>
|
|
|
|
</React.Fragment>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<PublishName disabled={formDisabled} />
|
|
|
|
<PublishPrice disabled={formDisabled} />
|
|
|
|
<PublishAdditionalOptions disabled={formDisabled} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<section>
|
|
|
|
{!formDisabled && !formValid && <PublishFormErrors />}
|
|
|
|
|
|
|
|
<div className="card__actions">
|
|
|
|
<Button
|
|
|
|
button="primary"
|
|
|
|
onClick={() => publish(filePath)}
|
|
|
|
label={submitLabel}
|
|
|
|
disabled={formDisabled || !formValid || uploadThumbnailStatus === THUMBNAIL_STATUSES.IN_PROGRESS}
|
|
|
|
/>
|
|
|
|
<Button button="link" onClick={clearPublish} label={__('Cancel')} />
|
|
|
|
</div>
|
|
|
|
<p className="help">
|
2020-05-26 06:10:05 +02:00
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
|
|
|
lbry_terms_of_service: (
|
|
|
|
<Button button="link" href="https://www.lbry.com/termsofservice" label={__('LBRY Terms of Service')} />
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
By continuing, you accept the %lbry_terms_of_service%.
|
|
|
|
</I18nMessage>
|
2020-03-24 18:57:17 +01:00
|
|
|
</p>
|
|
|
|
</section>
|
2020-04-01 20:43:50 +02:00
|
|
|
</div>
|
2019-06-28 09:27:55 +02:00
|
|
|
);
|
2017-06-30 10:45:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default PublishForm;
|