diff --git a/js/page/publish.js b/js/page/publish.js index 15b2b52f5..19c03511a 100644 --- a/js/page/publish.js +++ b/js/page/publish.js @@ -1,4 +1,4 @@ -var publishNumberInputStyle = { +var publishNumberStyle = { width: '50px', }, publishFieldLabelStyle = { display: 'inline-block', @@ -10,21 +10,47 @@ var publishNumberInputStyle = { }; var PublishPage = React.createClass({ - publish: function() { + _requiredFields: ['name', 'file', 'meta_title', 'meta_author', 'meta_license', 'meta_description'], + + handleSubmit: function() { this.setState({ submitting: true, }); - var metadata = { - title: this.refs.meta_title.value, - author: this.refs.meta_author.value, - description: this.refs.meta_description.value, - language: this.refs.meta_language.value, - license: this.refs.meta_license.value, - }; + var missingFieldFound = false; + for (let fieldName of this._requiredFields) { + var field = this.refs[fieldName]; + if (field.getValue() == '') { + field.warnRequired(); + if (!missingFieldFound) { + field.focus(); + missingFieldFound = true; + } + } + } - if (this.refs.meta_thumbnail.value) { - metadata.thumbnail = this.refs.meta_thumbnail.value; + if (missingFieldFound) { + this.setState({ + submitting: false, + }); + //return; + } + + var metadata = {}; + for (let metaField of ['meta_title', 'meta_author', 'meta_description', 'meta_thumbnail', + 'meta_language']) { + var value = this.refs[metaField].getValue(); + if (value != '') { + metadata[metaField] = value; + } + } + + metadata.license = {}; + metadata.license.name = this.refs.meta_license.getValue(); + + var licenseUrl = this.refs.meta_license_url.getValue(); + if (licenseUrl != '') { + metadata.license.url = this.refs.meta_license_url.getValue(); } var doPublish = () => { @@ -34,7 +60,7 @@ var PublishPage = React.createClass({ bid: parseFloat(this.state.bid), metadata: metadata, }, (message) => { - this.handlePublishSuccess(this.state.name, this.state.title); + this.handlePublishSuccess(); this.setState({ submitting: false, }); @@ -76,8 +102,8 @@ var PublishPage = React.createClass({ submitting: false, }; }, - handlePublishSuccess: function(name, title) { - alert(`Your file ${title} has been published to LBRY at the address lbry://${name}!\n\n` + + handlePublishSuccess: function() { + alert(`Your file ${this.refs.meta_title.value} has been published to LBRY at the address lbry://${this.state.name}!\n\n` + `You will now be taken to your My Files page, where your newly published file should appear within a few minutes.`); window.location = "?files"; }, @@ -200,12 +226,12 @@ var PublishPage = React.createClass({ } return ( -
+

Publish Content

LBRY Name

- lbry:// + lbry:// { (!this.state.name ? '' : (this.state.nameResolved ? This name is currently claimed for {lbry.formatCredits(this.state.claimValue)} credits @@ -217,7 +243,7 @@ var PublishPage = React.createClass({

Choose File

- + { !this.state.fileInfo ? '' : (!this.state.tempFileReady ?
@@ -229,7 +255,7 @@ var PublishPage = React.createClass({

Bid Amount

- Credits + Credits {this.state.bid && isNaN(this.state.bid) ? Must be a number : ''}
How much would you like to bid for this name? { !this.state.nameResolved ? Since this name is not currently resolved, you may bid as low as you want, but higher bids help prevent others from claiming your name. @@ -241,11 +267,11 @@ var PublishPage = React.createClass({

Fee

@@ -256,10 +282,10 @@ var PublishPage = React.createClass({

Your Content

- - - - + - +
-

Additional Content Information (Optional)

-
+
+

Additional Content Information (Optional)

+ + +
- +
);