- {files.map((a) => (
+
+ function getInfo(f: File | NostrEvent): FileInfo {
+ if ("created_at" in f) {
+ return {
+ id: f.tags.find((a) => a[0] === "x")![1],
+ url: f.tags.find((a) => a[0] === "url")?.at(1),
+ name: f.content,
+ type: f.tags.find((a) => a[0] === "m")?.at(1),
+ size: Number(f.tags.find((a) => a[0] === "size")?.at(1)),
+ };
+ } else {
+ return {
+ id: f.name,
+ url: URL.createObjectURL(f),
+ name: f.name,
+ type: f.type,
+ size: f.size,
+ };
+ }
+ }
+
+ function pageButtons(page: number, n: number) {
+ const ret = [];
+ const start = 0;
+
+ for (let x = start; x < n; x++) {
+ ret.push(
onPage?.(x)}
+ className={`bg-neutral-800 hover:bg-neutral-700 min-w-8 text-center cursor-pointer font-bold ${x === start ? "rounded-l-md" : ""} ${x === n - 1 ? "rounded-r-md" : ""} ${page === x ? "bg-neutral-500" : ""}`}
>
-
- {a.name}
-
- {renderInner(a)}
+ {x + 1}
+
,
+ );
+ }
+
+ return ret;
+ }
+
+ function showGrid() {
+ return (
+
+ {files.map((a) => {
+ const info = getInfo(a);
+
+ return (
+
+
+
+ {(info.name?.length ?? 0) === 0 ? "Untitled" : info.name}
+
+
+ {info.size && !isNaN(info.size)
+ ? FormatBytes(info.size, 2)
+ : ""}
+
+
+ Link
+
+
+ {renderInner(info)}
+
+ );
+ })}
+
+ );
+ }
+
+ function showList() {
+ return (
+
+
+
+
+ Name
+ |
+
+ Size
+ |
+
+ Actions
+ |
+
+
+
+ {files.map((a) => {
+ const info = getInfo(a);
+ return (
+
+
+ {(info.name?.length ?? 0) === 0 ? "" : info.name}
+ |
+
+ {info.size && !isNaN(info.size)
+ ? FormatBytes(info.size, 2)
+ : ""}
+ |
+
+
+ Link
+
+ |
+
+ );
+ })}
+
+
+ );
+ }
+
+ return (
+ <>
+
+
setViewType("grid")}
+ className={`bg-neutral-800 hover:bg-neutral-600 min-w-20 text-center cursor-pointer font-bold rounded-l-md ${viewType === "grid" ? "bg-neutral-500" : ""}`}
+ >
+ Grid
- ))}
-
+
setViewType("list")}
+ className={`bg-neutral-800 hover:bg-neutral-600 min-w-20 text-center cursor-pointer font-bold rounded-r-md ${viewType === "list" ? "bg-neutral-500" : ""}`}
+ >
+ List
+
+
+ {viewType === "grid" ? showGrid() : showList()}
+ {pages !== undefined && (
+ <>
+ Page:
+