handle hashtags in search view

This commit is contained in:
hzrd149 2023-06-28 08:23:36 +00:00
parent 9936c25f8a
commit 644c53ec76
3 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
"nostrudel": minor
---
Handle hashtags in search view

View File

@ -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");
});
});
});

View File

@ -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 });
}