Pre-fill metadata on Publish page #142
1 changed files with 76 additions and 24 deletions
|
@ -25,6 +25,15 @@ class PublishPage extends React.PureComponent {
|
||||||
newChannelBid: 10,
|
newChannelBid: 10,
|
||||||
myClaimValue: 0.0,
|
myClaimValue: 0.0,
|
||||||
myClaimMetadata: null,
|
myClaimMetadata: null,
|
||||||
|
metadata: {
|
||||||
|
title: "",
|
||||||
|
thumbnail: "",
|
||||||
|
description: "",
|
||||||
|
language: "en",
|
||||||
|
nsfw: "0",
|
||||||
|
license: "",
|
||||||
|
license_url: "",
|
||||||
|
},
|
||||||
copyrightNotice: "",
|
copyrightNotice: "",
|
||||||
otherLicenseDescription: "",
|
otherLicenseDescription: "",
|
||||||
otherLicenseUrl: "",
|
otherLicenseUrl: "",
|
||||||
|
@ -90,18 +99,13 @@ class PublishPage extends React.PureComponent {
|
||||||
"license_url",
|
"license_url",
|
||||||
"language",
|
"language",
|
||||||
]) {
|
]) {
|
||||||
var value = this.refs["meta_" + metaField].getValue();
|
const value = this.state.metadata[metaField];
|
||||||
if (value !== "") {
|
if (value) {
|
||||||
metadata[metaField] = value;
|
metadata[metaField] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata.nsfw = parseInt(this.refs.meta_nsfw.getValue()) === 1;
|
metadata.nsfw = !!parseInt(this.state.metadata.nsfw);
|
||||||
|
|
||||||
const licenseUrl = this.refs.meta_license_url.getValue();
|
|
||||||
if (licenseUrl) {
|
|
||||||
metadata.license_url = licenseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
var doPublish = () => {
|
var doPublish = () => {
|
||||||
var publishArgs = {
|
var publishArgs = {
|
||||||
|
@ -275,6 +279,15 @@ class PublishPage extends React.PureComponent {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleMetadataChange(event) {
|
||||||
|
this.setState({
|
||||||
|
metadata: {
|
||||||
|
...this.state.metadata,
|
||||||
|
...{ [event.target.name]: event.target.value },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
handleLicenseChange(event) {
|
handleLicenseChange(event) {
|
||||||
var licenseType = event.target.options[
|
var licenseType = event.target.options[
|
||||||
event.target.selectedIndex
|
event.target.selectedIndex
|
||||||
|
@ -363,15 +376,26 @@ class PublishPage extends React.PureComponent {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLicenseDescription() {
|
||||||
|
if (!this._meta_license) {
|
||||||
|
// first render
|
||||||
|
return "";
|
||||||
|
} else if (this.state.otherLicenseChosen) {
|
||||||
|
return this.state.otherLicenseDescription;
|
||||||
|
} else {
|
||||||
|
return this.metadata.license_description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getLicenseUrl() {
|
getLicenseUrl() {
|
||||||
if (!this.refs.meta_license) {
|
if (!this._meta_license) {
|
||||||
|
// first render
|
||||||
return "";
|
return "";
|
||||||
} else if (this.state.otherLicenseChosen) {
|
} else if (this.state.otherLicenseChosen) {
|
||||||
return this.state.otherLicenseUrl;
|
return this.state.otherLicenseUrl;
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
this.refs.meta_license.getSelectedElement().getAttribute("data-url") ||
|
this._meta_license.getSelectedElement().getAttribute("data-url") || ""
|
||||||
""
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -471,36 +495,47 @@ class PublishPage extends React.PureComponent {
|
||||||
<FormRow
|
<FormRow
|
||||||
label={__("Title")}
|
label={__("Title")}
|
||||||
type="text"
|
type="text"
|
||||||
ref="meta_title"
|
|
||||||
name="title"
|
name="title"
|
||||||
placeholder={__("Title")}
|
value={this.state.metadata.title}
|
||||||
|
placeholder="Titular Title"
|
||||||
|
onChange={event => {
|
||||||
|
this.handleMetadataChange(event);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="card__content">
|
<div className="card__content">
|
||||||
<FormRow
|
<FormRow
|
||||||
type="text"
|
type="text"
|
||||||
label={__("Thumbnail URL")}
|
label={__("Thumbnail URL")}
|
||||||
ref="meta_thumbnail"
|
|
||||||
name="thumbnail"
|
name="thumbnail"
|
||||||
|
value={this.state.metadata.thumbnail}
|
||||||
placeholder="http://spee.ch/mylogo"
|
placeholder="http://spee.ch/mylogo"
|
||||||
|
onChange={event => {
|
||||||
|
this.handleMetadataChange(event);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="card__content">
|
<div className="card__content">
|
||||||
<FormRow
|
<FormRow
|
||||||
label={__("Description")}
|
label={__("Description")}
|
||||||
type="textarea"
|
type="textarea"
|
||||||
ref="meta_description"
|
|
||||||
name="description"
|
name="description"
|
||||||
|
value={this.state.metadata.description}
|
||||||
placeholder={__("Description of your content")}
|
placeholder={__("Description of your content")}
|
||||||
|
onChange={event => {
|
||||||
|
this.handleMetadataChange(event);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="card__content">
|
<div className="card__content">
|
||||||
<FormRow
|
<FormRow
|
||||||
label={__("Language")}
|
label={__("Language")}
|
||||||
type="select"
|
type="select"
|
||||||
defaultValue="en"
|
value={this.state.metadata.language}
|
||||||
ref="meta_language"
|
|
||||||
name="language"
|
name="language"
|
||||||
|
onChange={event => {
|
||||||
|
this.handleMetadataChange(event);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<option value="en">{__("English")}</option>
|
<option value="en">{__("English")}</option>
|
||||||
<option value="zh">{__("Chinese")}</option>
|
<option value="zh">{__("Chinese")}</option>
|
||||||
|
@ -515,9 +550,10 @@ class PublishPage extends React.PureComponent {
|
||||||
<FormRow
|
<FormRow
|
||||||
type="select"
|
type="select"
|
||||||
label={__("Maturity")}
|
label={__("Maturity")}
|
||||||
defaultValue="en"
|
|
||||||
ref="meta_nsfw"
|
|
||||||
name="nsfw"
|
name="nsfw"
|
||||||
|
onChange={event => {
|
||||||
|
this.handleMetadataChange(event);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{/* <option value=""></option> */}
|
{/* <option value=""></option> */}
|
||||||
<option value="0">{__("All Ages")}</option>
|
<option value="0">{__("All Ages")}</option>
|
||||||
|
@ -565,8 +601,7 @@ class PublishPage extends React.PureComponent {
|
||||||
placeholder="1.00"
|
placeholder="1.00"
|
||||||
min="0.01"
|
min="0.01"
|
||||||
onChange={event => this.handleFeeAmountChange(event)}
|
onChange={event => this.handleFeeAmountChange(event)}
|
||||||
/>
|
/>{" "}
|
||||||
{" "}
|
|
||||||
<FormField
|
<FormField
|
||||||
type="select"
|
type="select"
|
||||||
onChange={event => {
|
onChange={event => {
|
||||||
|
@ -587,7 +622,9 @@ class PublishPage extends React.PureComponent {
|
||||||
<FormRow
|
<FormRow
|
||||||
label="License"
|
label="License"
|
||||||
type="select"
|
type="select"
|
||||||
ref="meta_license"
|
ref={row => {
|
||||||
|
this._meta_license = row;
|
||||||
|
}}
|
||||||
name="license"
|
name="license"
|
||||||
onChange={event => {
|
onChange={event => {
|
||||||
this.handleLicenseChange(event);
|
this.handleLicenseChange(event);
|
||||||
|
@ -640,12 +677,26 @@ class PublishPage extends React.PureComponent {
|
||||||
{__("Other...")}
|
{__("Other...")}
|
||||||
</option>
|
</option>
|
||||||
</FormRow>
|
</FormRow>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
type="hidden"
|
||||||
|
name="license_description"
|
||||||
|
value={event => {
|
||||||
|
this.getLicenseDescription(event);
|
||||||
|
}}
|
||||||
|
onChange={event => {
|
||||||
|
this.handleMetadataChange(event);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
type="hidden"
|
type="hidden"
|
||||||
ref="meta_license_url"
|
|
||||||
name="license_url"
|
name="license_url"
|
||||||
value={this.getLicenseUrl()}
|
value={this.getLicenseUrl()}
|
||||||
|
onChange={event => {
|
||||||
|
this.handleMetadataChange(event);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{this.state.copyrightChosen
|
{this.state.copyrightChosen
|
||||||
? <FormRow
|
? <FormRow
|
||||||
label={__("Copyright notice")}
|
label={__("Copyright notice")}
|
||||||
|
@ -657,13 +708,14 @@ class PublishPage extends React.PureComponent {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
: null}
|
: null}
|
||||||
|
|
||||||
{this.state.otherLicenseChosen
|
{this.state.otherLicenseChosen
|
||||||
? <FormRow
|
? <FormRow
|
||||||
label={__("License description")}
|
label={__("License description")}
|
||||||
type="text"
|
type="text"
|
||||||
name="other-license-description"
|
name="other-license-description"
|
||||||
onChange={event => {
|
onChange={event => {
|
||||||
this.handleOtherLicenseDescriptionChange();
|
this.handleOtherLicenseDescriptionChange(event);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
: null}
|
: null}
|
||||||
|
|
Loading…
Reference in a new issue