From 243987aa40b32330f091546bee415f335ca771d3 Mon Sep 17 00:00:00 2001 From: highperfocused Date: Sun, 13 Apr 2025 13:07:52 +0200 Subject: [PATCH] wip pt3 --- app/page.tsx | 6 +- components/upload-component.tsx | 292 +++++++++++++++++--------------- 2 files changed, 153 insertions(+), 145 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 5da2d1c..0ff7da4 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -4,10 +4,8 @@ export default function UploadPage() { return (
-

Upload Image

-
- -
+

Uploader

+
) diff --git a/components/upload-component.tsx b/components/upload-component.tsx index dff0bb2..0d94bf3 100644 --- a/components/upload-component.tsx +++ b/components/upload-component.tsx @@ -7,20 +7,13 @@ import { Input } from "@/components/ui/input" import type { NostrEvent } from "nostr-tools" import { Label } from "@/components/ui/label" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" -import { - Drawer, - DrawerContent, - DrawerHeader, - DrawerTitle, - DrawerDescription, - DrawerFooter, -} from "@/components/ui/drawer" import { signEvent } from "@/lib/utils" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" -import { Copy, Check, ExternalLink, FileImage, Clock, Database } from "lucide-react" +import { Copy, Check, ExternalLink, FileImage, Clock, Database, ArrowLeft } from "lucide-react" import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip" +import { Spinner } from "./spinner" interface UploadResponse { url: string @@ -75,149 +68,166 @@ const CopyButton = ({ text }: { text: string }) => { ) } -const UploadResponseView = ({ data }: { data: UploadResponse }) => { +const UploadResponseView = ({ data, onReset }: { data: UploadResponse; onReset: () => void }) => { const dimensions = data.nip94.tags.find((tag) => tag[0] === "dim")?.[1] || "" const blurhash = data.nip94.tags.find((tag) => tag[0] === "blurhash")?.[1] || "" const thumbUrl = data.nip94.tags.find((tag) => tag[0] === "thumb")?.[1] || "" return ( - - -
- Upload Successful - - {data.type} - -
- File uploaded on {formatDate(data.uploaded)} -
- -
-
- Uploaded image +
+
+ +
+ + + +
+ Upload Successful + + {data.type} +
-
-
-
- - File Size -
-
{formatBytes(data.size)}
+ File uploaded on {formatDate(data.uploaded)} + + +
+
+ Uploaded image
- -
-
- - Upload Time -
-
{formatDate(data.uploaded)}
-
- - {dimensions && ( +
- - Dimensions + + File Size
-
{dimensions}
+
{formatBytes(data.size)}
- )} -
-
- - - URL - Hash - Metadata - - - -
- -
- {data.url} -
- - +
+
+ + Upload Time
+
{formatDate(data.uploaded)}
+ + {dimensions && ( +
+
+ + Dimensions +
+
{dimensions}
+
+ )}
+
- {thumbUrl && ( + + + URL + Hash + Metadata + + +
- +
- {thumbUrl} + {data.url}
- +
- )} -
- -
- -
- {data.sha256} - -
-
+ {thumbUrl && ( +
+ +
+ {thumbUrl} +
+ + +
+
+
+ )} +
- {blurhash && ( +
- +
- {blurhash} - + {data.sha256} +
- )} -
- -
- -
- {data.nip94.tags.map((tag, index) => ( -
- - {tag[0]} - - {tag[1]} - + {blurhash && ( +
+ +
+ {blurhash} +
- ))} -
-
- - +
+ )} + -
- - -
- - + +
+ +
+ {data.nip94.tags.map((tag, index) => ( +
+ + {tag[0]} + + {tag[1]} + +
+ ))} +
+
+
+ + +
+ + +
+ + +
) } @@ -262,7 +272,6 @@ const UploadComponent = () => { const loginType = typeof window !== "undefined" ? window.localStorage.getItem("loginType") : null const [previewUrl, setPreviewUrl] = useState("") const [isLoading, setIsLoading] = useState(false) - const [isDrawerOpen, setIsDrawerOpen] = useState(false) const [uploadedNoteId, setUploadedNoteId] = useState("") const [retryCount, setRetryCount] = useState(0) const [shouldFetch, setShouldFetch] = useState(false) @@ -270,6 +279,7 @@ const UploadComponent = () => { const [events, setEvents] = useState([]) const [isNoteLoading, setIsNoteLoading] = useState(false) const [uploadResponse, setUploadResponse] = useState(null) + const [showUploadForm, setShowUploadForm] = useState(true) useEffect(() => { if (uploadedNoteId) { @@ -322,6 +332,16 @@ const UploadComponent = () => { setServerChoice(value) } + const resetUpload = () => { + setUploadResponse(null) + setShowUploadForm(true) + setPreviewUrl("") + setUploadedNoteId("") + setEvents([]) + setRetryCount(0) + setShouldFetch(false) + } + async function onSubmit(event: FormEvent) { event.preventDefault() setIsLoading(true) @@ -421,7 +441,7 @@ const UploadComponent = () => { setIsLoading(false) if (finalFileUrl != null) { - setIsDrawerOpen(true) + setShowUploadForm(false) setShouldFetch(true) setRetryCount(0) } @@ -438,8 +458,8 @@ const UploadComponent = () => { } return ( - <> -
+
+ {showUploadForm ? (
@@ -474,26 +494,16 @@ const UploadComponent = () => { )} -
- - - - - Upload Result - Your file has been successfully uploaded - - -
{uploadResponse && }
- - - - -
-
- + ) : uploadResponse ? ( + + ) : ( +
+ +

Processing upload...

+
+ )} +
) } -export default UploadComponent +export default UploadComponent \ No newline at end of file