diff --git a/web/index.html b/web/index.html index af88f03..7801b60 100644 --- a/web/index.html +++ b/web/index.html @@ -4,7 +4,7 @@ - web + Ephemeral Downloader
diff --git a/web/src/App.tsx b/web/src/App.tsx index febb914..1aea168 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -35,14 +35,6 @@ function DownloadList() { function Main() { const { queueDownload } = useSession(); - const handleDownload = async (url: string) => { - try { - await queueDownload(url); - } catch (error) { - console.error("Failed to queue", error); - } - }; - return (
@@ -56,7 +48,7 @@ function Main() { Paste a link to start. Files are downloaded to the server first.

- + diff --git a/web/src/components/feature/DownloadForm.tsx b/web/src/components/feature/DownloadForm.tsx index f5e1f05..ef2a138 100644 --- a/web/src/components/feature/DownloadForm.tsx +++ b/web/src/components/feature/DownloadForm.tsx @@ -9,14 +9,15 @@ const formSchema = z.object({ }); interface DownloadFormProps { - onDownload: (url: string) => void; + onDownload: (url: string) => Promise; } export function DownloadForm({ onDownload }: DownloadFormProps) { const [url, setUrl] = useState(""); const [error, setError] = useState(null); + const [submitting, setSubmitting] = useState(false); - const handleSubmit = (e: React.FormEvent) => { + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); @@ -27,8 +28,15 @@ export function DownloadForm({ onDownload }: DownloadFormProps) { return; } - onDownload(url); - setUrl(""); + setSubmitting(true); + try { + await onDownload(url); + setUrl(""); + } catch (err) { + setError(err instanceof Error ? err.message : "Failed to queue download"); + } finally { + setSubmitting(false); + } }; return ( @@ -37,14 +45,21 @@ export function DownloadForm({ onDownload }: DownloadFormProps) {
setUrl(e.target.value)} className={error ? "border-destructive focus-visible:ring-destructive" : ""} /> - {error &&

{error}

} + {error && ( + + )}
- diff --git a/web/src/components/ui/ProgressBar.tsx b/web/src/components/ui/ProgressBar.tsx index bcc15bb..3cf0466 100644 --- a/web/src/components/ui/ProgressBar.tsx +++ b/web/src/components/ui/ProgressBar.tsx @@ -14,6 +14,10 @@ const Progress = React.forwardRef( return (
{ - if (!sessionId) return; + if (!sessionId) throw new Error("Session not ready, try again in a moment"); try { const res = await fetch(`${API_URL}/api/queue`, { method: "POST", @@ -101,7 +101,10 @@ export function SessionProvider({ children }: { children: React.ReactNode }) { body: JSON.stringify({ url }), }); - if (!res.ok) throw new Error("Failed to queue download"); + if (!res.ok) { + const body = (await res.json().catch(() => null)) as { error?: string } | null; + throw new Error(body?.error || "Failed to queue download"); + } await refreshTasks(); // Immediate refresh diff --git a/web/src/index.css b/web/src/index.css index 583a1de..7c47070 100644 --- a/web/src/index.css +++ b/web/src/index.css @@ -45,7 +45,7 @@ --accent: 217.2 32.6% 17.5%; --accent-foreground: 210 40% 98%; - --destructive: 0 62.8% 30.6%; + --destructive: 0 72% 54%; --destructive-foreground: 210 40% 98%; --border: 217.2 32.6% 17.5%;