pl-fe: fix hashtag links in statuses
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
acf31a11a3
commit
3f6c4fb5df
2 changed files with 6 additions and 4 deletions
|
@ -7,7 +7,7 @@ interface IHashtagLink {
|
||||||
}
|
}
|
||||||
|
|
||||||
const HashtagLink: React.FC<IHashtagLink> = ({ hashtag }) => (
|
const HashtagLink: React.FC<IHashtagLink> = ({ hashtag }) => (
|
||||||
<Link to={`/tags/${hashtag}`}>
|
<Link to={`/tags/${hashtag}`} onClick={(e) => e.stopPropagation()}>
|
||||||
#{hashtag}
|
#{hashtag}
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
|
|
|
@ -23,6 +23,9 @@ import type { MinifiedStatus } from 'pl-fe/reducers/statuses';
|
||||||
const MAX_HEIGHT = 322; // 20px * 16 (+ 2px padding at the top)
|
const MAX_HEIGHT = 322; // 20px * 16 (+ 2px padding at the top)
|
||||||
const BIG_EMOJI_LIMIT = 10;
|
const BIG_EMOJI_LIMIT = 10;
|
||||||
|
|
||||||
|
const nodesToText = (nodes: Array<DOMNode>): string =>
|
||||||
|
nodes.map(node => node.type === 'text' ? node.data : node.type === 'tag' ? nodesToText(node.children as Array<DOMNode>) : '').join('');
|
||||||
|
|
||||||
interface IReadMoreButton {
|
interface IReadMoreButton {
|
||||||
onClick: React.MouseEventHandler;
|
onClick: React.MouseEventHandler;
|
||||||
quote?: boolean;
|
quote?: boolean;
|
||||||
|
@ -148,10 +151,9 @@ const StatusContent: React.FC<IStatusContent> = React.memo(({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classes?.includes('hashtag')) {
|
if (classes?.includes('hashtag')) {
|
||||||
const child = domToReact(domNode.children as DOMNode[]);
|
const hashtag = nodesToText(domNode.children as Array<DOMNode>);
|
||||||
const hashtag = typeof child === 'string' ? child.replace(/^#/, '') : undefined;
|
|
||||||
if (hashtag) {
|
if (hashtag) {
|
||||||
return <HashtagLink hashtag={hashtag} />;
|
return <HashtagLink hashtag={hashtag.replace(/^#/, '')} />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue