From be9bfa6409da4eacc1242759f84151a131e9517c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 15 Apr 2022 17:51:12 -0500 Subject: [PATCH] StatusContent: refactor updateStatusLinks, remove reblogContent prop --- app/soapbox/components/status.tsx | 4 +--- app/soapbox/components/status_content.tsx | 21 ++++++++------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/app/soapbox/components/status.tsx b/app/soapbox/components/status.tsx index 812f8d3779..c3417c35e3 100644 --- a/app/soapbox/components/status.tsx +++ b/app/soapbox/components/status.tsx @@ -342,7 +342,7 @@ class Status extends ImmutablePureComponent { render() { let media = null; const poll = null; - let prepend, rebloggedByText, reblogContent, reblogElement, reblogElementMobile; + let prepend, rebloggedByText, reblogElement, reblogElementMobile; const { intl, hidden, featured, unread, group } = this.props; @@ -447,7 +447,6 @@ class Status extends ImmutablePureComponent { // @ts-ignore what the FUCK account = status.account; - reblogContent = status.contentHtml; status = status.reblog; } @@ -646,7 +645,6 @@ class Status extends ImmutablePureComponent { = ({ onClick, hidden, tabIndex }) interface IStatusContent { status: Status, - reblogContent?: string, // FIXME: not used! expanded?: boolean, onExpandedToggle?: () => void, onClick?: () => void, @@ -106,26 +105,27 @@ const StatusContent: React.FC = ({ status, expanded = false, onE const links = node.current.querySelectorAll('a'); - for (let i = 0; i < links.length; ++i) { - const link = links[i]; - if (link.classList.contains('status-link')) { - continue; - } + links.forEach(link => { + // Skip already processed + if (link.classList.contains('status-link')) return; + + // Add attributes link.classList.add('status-link'); link.setAttribute('rel', 'nofollow noopener'); link.setAttribute('target', '_blank'); const mention = status.mentions.find(mention => link.href === `${mention.url}`); + // Add event listeners on mentions and hashtags if (mention) { link.addEventListener('click', onMentionClick.bind(link, mention), false); link.setAttribute('title', mention.acct); - } else if (link.textContent?.charAt(0) === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) { + } else if (link.textContent?.charAt(0) === '#' || (link.previousSibling?.textContent?.charAt(link.previousSibling.textContent.length - 1) === '#')) { link.addEventListener('click', onHashtagClick.bind(link, link.text), false); } else { link.setAttribute('title', link.href); } - } + }); }; const maybeSetCollapsed = (): void => { @@ -192,11 +192,6 @@ const StatusContent: React.FC = ({ status, expanded = false, onE } }; - // const handleCollapsedClick: React.EventHandler = (e) => { - // e.preventDefault(); - // setCollapsed(!collapsed); - // }; - const getHtmlContent = (): string => { const { contentHtml: html } = status; if (greentext) return addGreentext(html);