Merge pull request #49 from lbryio/publish-reformat-names
Lowercase and remove special characters from names on Publish page
This commit is contained in:
commit
99c942a214
2 changed files with 14 additions and 6 deletions
|
@ -258,6 +258,11 @@ lbry.formatCredits = function(amount, precision)
|
||||||
return amount.toFixed(precision || 1).replace(/\.?0+$/, '');
|
return amount.toFixed(precision || 1).replace(/\.?0+$/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lbry.formatName = function(name) {
|
||||||
|
// Converts LBRY name to standard format (all lower case, no special characters)
|
||||||
|
return name.toLowerCase().replace(/[^a-z0-9\-]/, '');
|
||||||
|
}
|
||||||
|
|
||||||
lbry.loadJs = function(src, type, onload)
|
lbry.loadJs = function(src, type, onload)
|
||||||
{
|
{
|
||||||
var lbryScriptTag = document.getElementById('lbry'),
|
var lbryScriptTag = document.getElementById('lbry'),
|
||||||
|
|
|
@ -141,9 +141,9 @@ var PublishPage = React.createClass({
|
||||||
error.message);
|
error.message);
|
||||||
},
|
},
|
||||||
handleNameChange: function(event) {
|
handleNameChange: function(event) {
|
||||||
var name = event.target.value;
|
var rawName = event.target.value;
|
||||||
|
|
||||||
if (!name) {
|
if (!rawName) {
|
||||||
this.setState({
|
this.setState({
|
||||||
name: '',
|
name: '',
|
||||||
nameResolved: false,
|
nameResolved: false,
|
||||||
|
@ -152,8 +152,11 @@ var PublishPage = React.createClass({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var name = lbry.formatName(rawName);
|
||||||
|
|
||||||
lbry.resolveName(name, (info) => {
|
lbry.resolveName(name, (info) => {
|
||||||
if (name != this.refs.name.getValue()) {
|
if (name != lbry.formatName(this.refs.name.getValue())) {
|
||||||
|
// A new name has been typed already, so bail
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,9 +288,9 @@ var PublishPage = React.createClass({
|
||||||
lbry://<FormField type="text" ref="name" onChange={this.handleNameChange} />
|
lbry://<FormField type="text" ref="name" onChange={this.handleNameChange} />
|
||||||
{
|
{
|
||||||
(!this.state.name ? '' :
|
(!this.state.name ? '' :
|
||||||
(! this.state.nameResolved ? <em> This name is available: {this.state.name}</em>
|
(! this.state.nameResolved ? <em> The name <strong>{this.state.name}</strong> is available.</em>
|
||||||
: (this.state.nameIsMine ? <em> You already control this name. You can use this page to update your claim.</em>
|
: (this.state.nameIsMine ? <em> You already control the name <strong>{this.state.name}</strong>. You can use this page to update your claim.</em>
|
||||||
: <em> This name is currently claimed for <strong>{lbry.formatCredits(this.state.claimValue)}</strong> credits.</em>)))
|
: <em> The name {this.state.name} is currently claimed for <strong>{lbry.formatCredits(this.state.claimValue)}</strong> credits.</em>)))
|
||||||
}
|
}
|
||||||
<div className="help">What LBRY name would you like to claim for this file?</div>
|
<div className="help">What LBRY name would you like to claim for this file?</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue