From bbb3017b2dfb869236556c43b199b41799d3ecd9 Mon Sep 17 00:00:00 2001
From: Lim Chee Aun <cheeaun@gmail.com>
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 }) {
               )}
               <div
                 class="note"
-                onClick={handleAccountLinks()}
+                onClick={handleContentLinks()}
                 dangerouslySetInnerHTML={{
                   __html: enhanceContent(note, { emojis }),
                 }}
diff --git a/src/components/status.jsx b/src/components/status.jsx
index 9498690b..08cf2b1a 100644
--- a/src/components/status.jsx
+++ b/src/components/status.jsx
@@ -20,7 +20,7 @@ import Loader from '../components/loader';
 import Modal from '../components/modal';
 import NameText from '../components/name-text';
 import enhanceContent from '../utils/enhance-content';
-import handleAccountLinks from '../utils/handle-account-links';
+import handleContentLinks from '../utils/handle-content-links';
 import htmlContentLength from '../utils/html-content-length';
 import shortenNumber from '../utils/shorten-number';
 import states, { saveStatus } from '../utils/states';
@@ -346,7 +346,7 @@ function Status({
             lang={language}
             ref={contentRef}
             data-read-more={readMoreText}
-            onClick={handleAccountLinks({ mentions })}
+            onClick={handleContentLinks({ mentions })}
             dangerouslySetInnerHTML={{
               __html: enhanceContent(content, {
                 emojis,
diff --git a/src/components/timeline.jsx b/src/components/timeline.jsx
index 4b2d6597..baaca095 100644
--- a/src/components/timeline.jsx
+++ b/src/components/timeline.jsx
@@ -91,8 +91,7 @@ function Timeline({
               <Icon icon="home" size="l" />
             </Link>
           </div>
-          {uiState !== 'loading' &&
-            (titleComponent ? titleComponent : <h1>{title}</h1>)}
+          {title && (titleComponent ? titleComponent : <h1>{title}</h1>)}
           <div class="header-side">
             <Loader hidden={uiState !== 'loading'} />
           </div>
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;