From 644c53ec76a95f514af8a426b95c8abf2386f503 Mon Sep 17 00:00:00 2001 From: hzrd149 Date: Wed, 28 Jun 2023 08:23:36 +0000 Subject: [PATCH] handle hashtags in search view --- .changeset/clean-drinks-wink.md | 5 +++++ cypress/e2e/search.cy.ts | 10 ++++++++++ src/views/search/index.tsx | 2 ++ 3 files changed, 17 insertions(+) create mode 100644 .changeset/clean-drinks-wink.md diff --git a/.changeset/clean-drinks-wink.md b/.changeset/clean-drinks-wink.md new file mode 100644 index 000000000..8c0398d8e --- /dev/null +++ b/.changeset/clean-drinks-wink.md @@ -0,0 +1,5 @@ +--- +"nostrudel": minor +--- + +Handle hashtags in search view diff --git a/cypress/e2e/search.cy.ts b/cypress/e2e/search.cy.ts index 6c9f9a60b..7f2025f5f 100644 --- a/cypress/e2e/search.cy.ts +++ b/cypress/e2e/search.cy.ts @@ -56,4 +56,14 @@ describe("Search", () => { }); } }); + + describe("Hashtag", () => { + it("should redirect to hashtag view", () => { + cy.visit("#/search"); + cy.findByRole("searchbox").type("#bitcoin").type("{enter}"); + + cy.url().should("contain", "/t/bitcoin"); + cy.contains("#bitcoin"); + }); + }); }); diff --git a/src/views/search/index.tsx b/src/views/search/index.tsx index 77ea98a19..dcffc807c 100644 --- a/src/views/search/index.tsx +++ b/src/views/search/index.tsx @@ -91,6 +91,8 @@ export default function SearchView() { const handleSearchText = (text: string) => { if (text.startsWith("nostr:") || text.startsWith("web+nostr:") || safeDecode(search)) { navigate({ pathname: "/l/" + encodeURIComponent(text) }, { replace: true }); + } else if (text.trim().match(/^#(\w+)/i)) { + navigate({ pathname: "/t/" + text.toLowerCase().trim().replace(/^#/, "") }); } else { setSearchParams({ q: text }, { replace: true }); }