+
+
+
{profile?.name}
- {profile?.website && (
-
- {new URL(profile.website).hostname}
-
- )}
+
);
}
+
+function WebSiteLink({ profile }: { profile?: MetadataCache }) {
+ const website = profile?.website;
+ if (!website) return;
+
+ const hostname = website.startsWith("http") ? new URL(website).hostname : website;
+ const url = website.startsWith("http") ? website : `https://${website}`;
+
+ return (
+
+ {hostname}
+
+ );
+}
diff --git a/src/page/search.tsx b/src/page/search.tsx
index b65403a..bc3f3af 100644
--- a/src/page/search.tsx
+++ b/src/page/search.tsx
@@ -3,7 +3,6 @@ import { useLocation, useParams } from "react-router-dom";
import { TorrentKind } from "../const";
import { useRequestBuilder } from "@snort/system-react";
import { TorrentList } from "../element/torrent-list";
-import { Search } from "../element/search";
export function SearchPage() {
const params = useParams();
@@ -26,9 +25,8 @@ export function SearchPage() {
const data = useRequestBuilder(NoteCollection, rb);
return (
-
-
-
Search Results:
+
+
Search Results
);
diff --git a/src/page/torrent.tsx b/src/page/torrent.tsx
index 7a02324..ea4419f 100644
--- a/src/page/torrent.tsx
+++ b/src/page/torrent.tsx
@@ -1,13 +1,15 @@
import { unwrap } from "@snort/shared";
import { NostrLink, NoteCollection, RequestBuilder, TaggedNostrEvent, parseNostrLink } from "@snort/system";
import { useRequestBuilder } from "@snort/system-react";
-import { useLocation, useNavigate, useParams } from "react-router-dom";
+import { Link, useLocation, useNavigate, useParams } from "react-router-dom";
import { FormatBytes, TorrentKind } from "../const";
import { ProfileImage } from "../element/profile-image";
import { MagnetLink } from "../element/magnet";
import { useLogin } from "../login";
import { Button } from "../element/button";
import { Comments } from "../element/comments";
+import { useMemo } from "react";
+import { Text } from "../element/text";
export function TorrentPage() {
const location = useLocation();
@@ -31,11 +33,11 @@ export function TorrentDetail({ item }: { item: TaggedNostrEvent }) {
const navigate = useNavigate();
const link = NostrLink.fromEvent(item);
const name = item.tags.find((a) => a[0] === "title")?.at(1);
- const size = item.tags
- .filter((a) => a[0] === "file")
- .map((a) => Number(a[2]))
- .reduce((acc, v) => (acc += v), 0);
+
const files = item.tags.filter((a) => a[0] === "file");
+ const size = useMemo(() => files.map((a) => Number(a[2])).reduce((acc, v) => (acc += v), 0), [files]);
+ const sortedFiles = useMemo(() => files.sort((a, b) => (a[1] < b[1] ? -1 : 1)), [files]);
+
const tags = item.tags.filter((a) => a[0] === "t").map((a) => a[1]);
async function deleteTorrent() {
@@ -47,45 +49,74 @@ export function TorrentDetail({ item }: { item: TaggedNostrEvent }) {
}
return (
-
-
+
+
-
-
Size: {FormatBytes(size)}
-
Uploaded: {new Date(item.created_at * 1000).toLocaleDateString()}
-
- Tags:{" "}
-
- {tags.map((a) => (
-
#{a}
- ))}
+
+
+
+
Size: {FormatBytes(size)}
+
Uploaded: {new Date(item.created_at * 1000).toLocaleDateString()}
+
+ Tags:{" "}
+
+ {tags.map((a, i) => (
+
+ #{a}
+
+ ))}
+
+
+
+
+
+ Get this torrent
+
+ {item.pubkey == login?.publicKey && (
+
+ )}
-
-
- Get this torrent
-
-
-
Description
-
{item.content}
-
Files
-
- {files.map((a) => (
-
- {a[1]}
- {FormatBytes(Number(a[2]))}
-
- ))}
-
- {item.pubkey == login?.publicKey && (
-
+ {item.content && (
+ <>
+
Description
+
+
+
+ >
)}
-
Comments
+
Files
+
+
+
+
+
+ Filename
+ |
+
+ Size
+ |
+
+
+
+ {sortedFiles.map((a, i) => (
+
+ {a[1]} |
+ {FormatBytes(Number(a[2]))} |
+
+ ))}
+
+
+
+
Comments
);