diff --git a/src/element/search.tsx b/src/element/search.tsx index a9ca5e5..d2460d3 100644 --- a/src/element/search.tsx +++ b/src/element/search.tsx @@ -1,35 +1,27 @@ -import { useNavigate, useParams } from "react-router-dom"; -import { Categories } from "../const"; +import { useNavigate } from "react-router-dom"; import { useEffect, useState } from "react"; -export function Search() { - const params = useParams(); +export function Search(params: { term?: string; tags?: Array }) { const navigate = useNavigate(); const [term, setTerm] = useState(""); + const [tags, setTags] = useState>([]); useEffect(() => { setTerm(params.term ?? ""); - }, [params.term]); + setTags(params.tags ?? []); + }, [params]); return ( -
-
- {Categories.map((a) => ( -
- - -
- ))} -
+
setTerm(e.target.value)} onKeyDown={(e) => { if (e.key == "Enter") { - navigate(`/search/${encodeURIComponent(term)}`); + navigate(`/search/${encodeURIComponent(term)}${tags.length > 0 ? `?tags=${tags.join(",")}` : ""}`); } }} /> diff --git a/src/element/torrent-list.tsx b/src/element/torrent-list.tsx index b160c98..7cfe5ec 100644 --- a/src/element/torrent-list.tsx +++ b/src/element/torrent-list.tsx @@ -10,7 +10,7 @@ export function TorrentList({ items }: { items: Array }) { return ( - + @@ -37,12 +37,26 @@ function TorrentTableEntry({ item }: { item: TaggedNostrEvent }) { .reduce((acc, v) => (acc += v), 0); const npub = hexToBech32("npub", item.pubkey); return ( - +
Category Name Uploaded
{item.tags .filter((a) => a[0] === "t") - .map((a) => a[1]) - .join(" > ")} + .slice(0, 3) + .map((a, i, arr) => ( + <> + b[1]) + .join(","), + )}`} + > + {a[1]} + + {arr.length !== i + 1 && " > "} + + ))} diff --git a/src/page/home.tsx b/src/page/home.tsx index dba06a9..96ddcf7 100644 --- a/src/page/home.tsx +++ b/src/page/home.tsx @@ -3,9 +3,9 @@ import { LatestTorrents } from "../element/trending"; export function HomePage() { return ( - <> +
- +
); } diff --git a/src/page/profile.tsx b/src/page/profile.tsx index 0906b55..29c575a 100644 --- a/src/page/profile.tsx +++ b/src/page/profile.tsx @@ -11,10 +11,10 @@ export function ProfilePage() { if (!link) return; return ( - <> +
- +
); } diff --git a/src/page/search.tsx b/src/page/search.tsx index a568c74..b65403a 100644 --- a/src/page/search.tsx +++ b/src/page/search.tsx @@ -1,5 +1,5 @@ import { NoteCollection, RequestBuilder } from "@snort/system"; -import { useParams } from "react-router-dom"; +import { useLocation, useParams } from "react-router-dom"; import { TorrentKind } from "../const"; import { useRequestBuilder } from "@snort/system-react"; import { TorrentList } from "../element/torrent-list"; @@ -7,22 +7,29 @@ import { Search } from "../element/search"; export function SearchPage() { const params = useParams(); + const location = useLocation(); const term = params.term as string | undefined; + const q = new URLSearchParams(location.search ?? ""); + const tags = q.get("tags")?.split(",") ?? []; - const rb = new RequestBuilder(`search:${term}`); - rb.withFilter() + const rb = new RequestBuilder(`search:${term}+${tags.join(",")}`); + const f = rb + .withFilter() .kinds([TorrentKind]) .search(term) .limit(100) .relay(["wss://relay.nostr.band", "wss://relay.noswhere.com"]); + if (tags.length > 0) { + f.tag("t", tags); + } const data = useRequestBuilder(NoteCollection, rb); return ( - <> - +
+

Search Results:

- +
); }