diff --git a/src/components/searchModal/container/searchModalContainer.js b/src/components/searchModal/container/searchModalContainer.js index d8dbe74b0..1bf4597c8 100644 --- a/src/components/searchModal/container/searchModalContainer.js +++ b/src/components/searchModal/container/searchModalContainer.js @@ -68,20 +68,26 @@ class SearchModalContainer extends PureComponent { this.setState({ searchResults: { type: 'tag', data: tags } }); }); } else if (text.includes('https')) { - console.log('test :'); - console.log('postUrlParser(text) :', postUrlParser(text)); const { author, permlink } = postUrlParser(text); - console.log('author, permlink :', author, permlink); - if (author && permlink) { + if (author) { handleOnClose(); - navigation.navigate({ - routeName: ROUTES.SCREENS.POST, - params: { - author, - permlink, - }, - key: permlink, - }); + if (permlink) { + navigation.navigate({ + routeName: ROUTES.SCREENS.POST, + params: { + author, + permlink, + }, + key: permlink, + }); + } else { + navigation.navigate({ + routeName: ROUTES.SCREENS.PROFILE, + params: { + username: author, + }, + }); + } } } else { search({ q: text }).then(res => { diff --git a/src/utils/postUrlParser.js b/src/utils/postUrlParser.js index 41939e70f..871b863ed 100644 --- a/src/utils/postUrlParser.js +++ b/src/utils/postUrlParser.js @@ -1,14 +1,21 @@ export default url => { const parseCatAuthorPermlink = u => { - const r = /^https?:\/\/(.*)\/(.*)\/(@[\w.\d-]+)\/(.*)/i; - const match = u.match(r); - if (match && match.length === 5) { + const postRegex = /^https?:\/\/(.*)\/(.*)\/(@[\w.\d-]+)\/(.*)/i; + const postMatch = u.match(postRegex); + if (postMatch && postMatch.length === 5) { return { - author: match[3].replace('@', ''), - permlink: match[4], + author: postMatch[3].replace('@', ''), + permlink: postMatch[4], + }; + } + const authorRegex = /^https?:\/\/(.*)\/(.*)\/(@[\w.\d-]+)/i; + const authorMatch = u.match(authorRegex); + if (authorMatch && authorMatch.length === 4) { + return { + author: authorMatch[3].replace('@', ''), + permlink: null, }; } - return null; }; @@ -21,6 +28,14 @@ export default url => { permlink: match[3], }; } + const authorRegex = /^https?:\/\/(.*)\/(@[\w.\d-]+)/i; + const authorMatch = u.match(authorRegex); + if (authorMatch && authorMatch.length === 3) { + return { + author: authorMatch[2].replace('@', ''), + permlink: null, + }; + } return null; };