From bbb3017b2dfb869236556c43b199b41799d3ecd9 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Tue, 31 Jan 2023 19:31:25 +0800 Subject: [PATCH] Quietly handle hashtag links No follow/unfollow yet. --- src/components/account.jsx | 4 ++-- src/components/status.jsx | 4 ++-- src/components/timeline.jsx | 3 +-- ...ndle-account-links.js => handle-content-links.js} | 12 ++++++++++-- 4 files changed, 15 insertions(+), 8 deletions(-) rename src/utils/{handle-account-links.js => handle-content-links.js} (76%) diff --git a/src/components/account.jsx b/src/components/account.jsx index a996ee26..87feb00f 100644 --- a/src/components/account.jsx +++ b/src/components/account.jsx @@ -4,7 +4,7 @@ import { useEffect, useState } from 'preact/hooks'; import emojifyText from '../utils/emojify-text'; import enhanceContent from '../utils/enhance-content'; -import handleAccountLinks from '../utils/handle-account-links'; +import handleContentLinks from '../utils/handle-content-links'; import shortenNumber from '../utils/shorten-number'; import states from '../utils/states'; import store from '../utils/store'; @@ -186,7 +186,7 @@ function Account({ account, onClose }) { )}
- {uiState !== 'loading' && - (titleComponent ? titleComponent :

{title}

)} + {title && (titleComponent ? titleComponent :

{title}

)}
diff --git a/src/utils/handle-account-links.js b/src/utils/handle-content-links.js similarity index 76% rename from src/utils/handle-account-links.js rename to src/utils/handle-content-links.js index b7156ffc..585671ba 100644 --- a/src/utils/handle-account-links.js +++ b/src/utils/handle-content-links.js @@ -1,6 +1,6 @@ import states from './states'; -function handleAccountLinks(opts) { +function handleContentLinks(opts) { const { mentions = [] } = opts || {}; return (e) => { let { target } = e; @@ -33,8 +33,16 @@ function handleAccountLinks(opts) { const href = target.getAttribute('href'); states.showAccount = href; } + } else if ( + target.tagName.toLowerCase() === 'a' && + target.classList.contains('hashtag') + ) { + e.preventDefault(); + e.stopPropagation(); + const tag = target.innerText.replace(/^#/, '').trim(); + location.hash = `#/t/${tag}`; } }; } -export default handleAccountLinks; +export default handleContentLinks;