From 0f4bc36bcd69ceb0efc108d95c3b3c92483568a0 Mon Sep 17 00:00:00 2001 From: hackrush Date: Sat, 22 Jul 2017 14:40:37 +0530 Subject: [PATCH] The URL name is automatically suggested. Fixes #347 minor clean up --- CHANGELOG.md | 1 + ui/js/component/publishForm/view.jsx | 17 +++++++++++++++++ ui/js/lbry.js | 2 +- ui/js/lbryuri.js | 6 ++++-- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f86745569..477ed8013 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Web UI version numbers should always match the corresponding version of LBRY App * Support markdown makeup in claim description * Replaced free speech flag (used when image is missing) with labeled color tiles * Added a loading message to file actions + * URL is auto suggested in Publish Page ### Changed * Publishes now uses claims rather than files diff --git a/ui/js/component/publishForm/view.jsx b/ui/js/component/publishForm/view.jsx index e73038e16..970787205 100644 --- a/ui/js/component/publishForm/view.jsx +++ b/ui/js/component/publishForm/view.jsx @@ -43,6 +43,7 @@ class PublishForm extends React.PureComponent { creatingChannel: false, modal: null, isFee: false, + customUrl: false, }; } @@ -203,6 +204,9 @@ class PublishForm extends React.PureComponent { handleNameChange(event) { var rawName = event.target.value; + this.setState({ + customUrl: Boolean(rawName.length), + }); this.nameChanged(rawName); } @@ -445,11 +449,24 @@ class PublishForm extends React.PureComponent { onFileChange() { if (this.refs.file.getValue()) { this.setState({ hasFile: true }); + if (!this.state.customUrl) { + let fileName = this._getFileName(this.refs.file.getValue()); + this.nameChanged(fileName); + } } else { this.setState({ hasFile: false }); } } + _getFileName(fileName) { + const path = require("path"); + const extension = path.extname(fileName); + + fileName = path.basename(fileName, extension); + fileName = fileName.replace(lbryuri.REGEXP_INVALID_URI, ""); + return fileName; + } + getNameBidHelpText() { if (this.state.prefillDone) { return __("Existing claim data was prefilled"); diff --git a/ui/js/lbry.js b/ui/js/lbry.js index 7409bdde4..e6a014ae2 100644 --- a/ui/js/lbry.js +++ b/ui/js/lbry.js @@ -296,7 +296,7 @@ lbry.formatCredits = function(amount, precision) { lbry.formatName = function(name) { // Converts LBRY name to standard format (all lower case, no special characters, spaces replaced by dashes) name = name.replace("/s+/g", "-"); - name = name.toLowerCase().replace(/[^a-z0-9\-]/g, ""); + name = name.toLowerCase().replace(lbryuri.REGEXP_INVALID_URI, ""); return name; }; diff --git a/ui/js/lbryuri.js b/ui/js/lbryuri.js index 42a825949..a7f43890a 100644 --- a/ui/js/lbryuri.js +++ b/ui/js/lbryuri.js @@ -3,6 +3,8 @@ const CLAIM_ID_MAX_LEN = 40; const lbryuri = {}; +lbryuri.REGEXP_INVALID_URI = /[^A-Za-z0-9-]/g; + /** * Parses a LBRY name into its component parts. Throws errors with user-friendly * messages for invalid names. @@ -70,7 +72,7 @@ lbryuri.parse = function(uri, requireProto = false) { contentName = path; } - const nameBadChars = (channelName || name).match(/[^A-Za-z0-9-]/g); + const nameBadChars = (channelName || name).match(lbryuri.REGEXP_INVALID_URI); if (nameBadChars) { throw new Error( __( @@ -119,7 +121,7 @@ lbryuri.parse = function(uri, requireProto = false) { throw new Error(__("Only channel URIs may have a path.")); } - const pathBadChars = path.match(/[^A-Za-z0-9-]/g); + const pathBadChars = path.match(lbryuri.REGEXP_INVALID_URI); if (pathBadChars) { throw new Error( __(`Invalid character in path: %s`, pathBadChars.join(", "))