Skip to content

Commit

Permalink
Fix links in Memo
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Nov 10, 2023
1 parent 5c8163c commit 3c04866
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const GlobalStyle = createGlobalStyle`
}
`;

const availableDomains = [
export const availableDomains = [
'golos.id',
'golos.in',
'golos.today',
Expand Down
20 changes: 15 additions & 5 deletions app/components/elements/Memo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import tt from 'counterpart';
import { memo, } from 'golos-lib-js';
import { Link, } from 'react-router';

import { availableDomains } from 'app/components/App'
import links from 'app/utils/Links'
import shouldComponentUpdate from 'app/utils/shouldComponentUpdate'
import { validate_account_name, } from 'app/utils/ChainValidation'
Expand Down Expand Up @@ -52,19 +53,28 @@ class Memo extends React.Component {
for (let section of text.split(' ')) {
if (section.trim().length === 0) continue
const matchUserName = section.match(/(^|\s)(@[a-z][-\.a-z\d]+[a-z\d])/i)
const matchLink = section.match(links.local)
let insertPlain = true
if (matchUserName) {
const user2 = matchUserName[0].trim().substring(1)
const userLower = user2.toLowerCase()
const valid = validate_account_name(userLower) == null
valid
? sections.push(<Link key={idx++} to={`/@${userLower}`}>{`@${user2}`}&nbsp;</Link>)
: sections.push(<span key={idx++}>{`@${user2}`}</span>)
insertPlain = false
} else if (section.match(links.any)) {
let hostname
try {
hostname = new URL(section.trim()).hostname
} catch (err) {
console.error(err)
}
if (availableDomains.includes(hostname)) {
sections.push(<a key={idx++} href={section} target='_blank' rel='noopener noreferrer'>{section}&nbsp;</a>)
insertPlain = false
}
}
else if (matchLink) {
sections.push(<Link key={idx++} to={section}>{section}&nbsp;</Link>)
}
else {
if (insertPlain) {
sections.push(<span className="overflow-ellipsis" key={idx++}>{section}&nbsp;</span>)
}
}
Expand Down

0 comments on commit 3c04866

Please sign in to comment.