diff --git a/src/components/editorElements/tagArea/view/tagAreaView.js b/src/components/editorElements/tagArea/view/tagAreaView.js index 7dcc76b7d..31b376b0c 100644 --- a/src/components/editorElements/tagArea/view/tagAreaView.js +++ b/src/components/editorElements/tagArea/view/tagAreaView.js @@ -38,8 +38,7 @@ export default class TagAreaView extends Component { // Component Functions _handleOnChange = (text, i) => { - this.setState({ currentText: text.replace(/\s/g, '').toLowerCase() }); - + this.setState({ currentText: text.replace(/\s/g, '') }); if (text.indexOf(' ') > 0 && text) { this._handleTagAdded(); } diff --git a/src/screens/editor/container/editorContainer.js b/src/screens/editor/container/editorContainer.js index 621b6cd5c..3b98516cf 100644 --- a/src/screens/editor/container/editorContainer.js +++ b/src/screens/editor/container/editorContainer.js @@ -291,7 +291,19 @@ class EditorContainer extends Component { const meta = extractMetadata(fields.body); const jsonMeta = makeJsonMetadata(meta, fields.tags); // TODO: check if permlink is available github: #314 https://github.com/esteemapp/esteem-mobile/pull/314 - const permlink = generatePermlink(fields.title); + let permlink = generatePermlink(fields.title); + + let dublicatePost; + try { + dublicatePost = await getPurePost(currentAccount.name, permlink); + } catch (e) { + dublicatePost = null; + } + + if (dublicatePost && dublicatePost.id) { + permlink = generatePermlink(fields.title, true); + } + const author = currentAccount.name; const options = makeOptions(author, permlink); const parentPermlink = fields.tags[0]; diff --git a/src/utils/editor.js b/src/utils/editor.js index c23b0d595..851213626 100644 --- a/src/utils/editor.js +++ b/src/utils/editor.js @@ -3,14 +3,16 @@ import { diff_match_patch } from 'diff-match-patch'; export const getWordsCount = text => (text && typeof text === 'string' ? text.replace(/^\s+|\s+$/g, '').split(/\s+/).length : 0); -export const generatePermlink = (title, random = false) => { - if (title) { - const slug = getSlug(title); - let perm = slug.toString(); +const permlinkRnd = () => (Math.random() + 1).toString(16).substring(2); +export const generatePermlink = (title, random = false) => { + const slug = getSlug(title); + let perm = slug.toString(); + + if (title) { if (random) { const rnd = (Math.random() + 1).toString(16).substring(2); - perm = `${slug.toString()}-${rnd}est`; + perm = `${slug.toString()}${rnd}est`; } // STEEMIT_MAX_PERMLINK_LENGTH @@ -20,9 +22,13 @@ export const generatePermlink = (title, random = false) => { // only letters numbers and dashes perm = perm.toLowerCase().replace(/[^a-z0-9-]+/g, ''); - return perm; + + if (perm.length === 0) { + return permlinkRnd(); + } } - return null; + + return perm; }; export const generateReplyPermlink = (toAuthor) => {