Merge pull request #448 from esteemapp/bugfix/#435

Bugfix/#435
This commit is contained in:
uğur erdal 2019-01-17 20:25:45 +03:00 committed by GitHub
commit 22722c6e42
3 changed files with 27 additions and 10 deletions

View File

@ -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();
}

View File

@ -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];

View File

@ -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) => {