diff --git a/js/page/publish.js b/js/page/publish.js index 2b84cea78..e605ae686 100644 --- a/js/page/publish.js +++ b/js/page/publish.js @@ -10,15 +10,20 @@ var publishNumberStyle = { }; var PublishPage = React.createClass({ - _requiredFields: ['name', 'file', 'bid', 'meta_title', 'meta_author', 'meta_license', 'meta_description'], + _requiredFields: ['name', 'bid', 'meta_title', 'meta_author', 'meta_license', 'meta_description'], handleSubmit: function() { this.setState({ submitting: true, }); + var checkFields = this._requiredFields.slice(); + if (!this.state.nameIsMine) { + checkFields.push('file'); + } + var missingFieldFound = false; - for (let fieldName of this._requiredFields) { + for (let fieldName of checkFields) { var field = this.refs[fieldName]; if (field.getValue() === '') { field.warnRequired(); @@ -60,17 +65,20 @@ var PublishPage = React.createClass({ } var doPublish = () => { - console.log({name: this.state.name, - file_path: this._tempFilePath, + var publishArgs = { + name: this.state.name, bid: parseFloat(this.state.bid), metadata: metadata, - }); - lbry.publish({ - name: this.refs.name.getValue(), - file_path: this._tempFilePath, - bid: parseFloat(this.state.bid), - metadata: metadata, - }, (message) => { + }; + + if (this.refs.file.getValue() === '') { + publishArgs.metadata.sources = this.state.claimMetadata.sources; + } else { + publishArgs.file_path = this._tempFilePath; + } + + console.log(publishArgs); + lbry.publish(publishArgs, (message) => { this.handlePublishSuccess(); this.setState({ submitting: false, @@ -106,7 +114,9 @@ var PublishPage = React.createClass({ feeAmount: '', feeCurrency: 'USD', nameResolved: false, + nameIsMine: false, claimValue: 0.0, + claimMetadata: null, fileInfo: null, uploadProgress: 0.0, uploaded: false, @@ -143,11 +153,22 @@ var PublishPage = React.createClass({ }); } else { lbry.getClaimInfo(name, (claimInfo) => { - this.setState({ + var newState = { name: name, nameResolved: true, + nameIsMine: true, //claimInfo.is_mine, claimValue: parseFloat(claimInfo.amount), - }); + claimMetadata: claimInfo.value, + }; + + if (claimInfo.is_mine) { + newState.bid = claimInfo.amount; + } else if (this.state.nameIsMine && !claimInfo.name_is_mine) { + // Just changed away from a name we control, so clear pre-fill + newState.bid = ''; + } + + this.setState(newState); }); } }); @@ -247,8 +268,9 @@ var PublishPage = React.createClass({ lbry:// { (!this.state.name ? '' : - (this.state.nameResolved ? This name is currently claimed for {lbry.formatCredits(this.state.claimValue)} credits - : This name is available)) + (! this.state.nameResolved ? This name is available + : (this.state.nameIsMine ? You already control this name. You can use this page to update your claim. + : This name is currently claimed for {lbry.formatCredits(this.state.claimValue)} credits.))) }
What LBRY name would you like to claim for this file?
@@ -264,6 +286,7 @@ var PublishPage = React.createClass({ :
File ready for publishing!
) } + { this.state.nameIsMine ?
If you don't choose a file, the file from your existing claim will be used.
: null }
@@ -271,7 +294,8 @@ var PublishPage = React.createClass({ Credits
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. - : You must bid over {lbry.formatCredits(this.state.claimValue)} credits to claim this name. } + : (this.state.nameIsMine ? Your current bid is {lbry.formatCredits(this.state.claimValue)} credits. + : You must bid over {lbry.formatCredits(this.state.claimValue)} credits to claim this name.) }
@@ -335,4 +359,4 @@ var PublishPage = React.createClass({ ); } -}); \ No newline at end of file +});