From 0663d38834320644db3f9eca0ffe96835aee7d25 Mon Sep 17 00:00:00 2001 From: Xevion Date: Thu, 2 Jan 2025 13:46:02 -0600 Subject: [PATCH] Remove unnecessary logs, switch to simple window.open download, suppressHydrationWarning --- frontend/src/components/Demo.tsx | 2 - frontend/src/components/DownloadButton.tsx | 45 +++------------------- frontend/src/components/useSocket.ts | 4 +- 3 files changed, 7 insertions(+), 44 deletions(-) diff --git a/frontend/src/components/Demo.tsx b/frontend/src/components/Demo.tsx index 9cc148b..e71358e 100644 --- a/frontend/src/components/Demo.tsx +++ b/frontend/src/components/Demo.tsx @@ -13,8 +13,6 @@ const Demo = ({ class: className }: DemoProps) => { const { id, downloads, executables } = useSocket(); // TODO: Toasts - console.log([executables == null]); - const [highlightedIndex, setHighlightedIndex] = useState(null); const highlightedTimeoutRef = useRef(null); diff --git a/frontend/src/components/DownloadButton.tsx b/frontend/src/components/DownloadButton.tsx index 66fde31..f888822 100644 --- a/frontend/src/components/DownloadButton.tsx +++ b/frontend/src/components/DownloadButton.tsx @@ -1,5 +1,3 @@ -"use client"; - import type { Executable } from "@/components/useSocket"; import { cn, withBackend } from "@/util"; import { @@ -45,8 +43,6 @@ export default function DownloadButton({ }: DownloadButtonProps) { const menuRef = useRef(null); - console.log({ disabled }); - function getExecutable(id: string) { return executables?.find((e) => e.id.toLowerCase() === id.toLowerCase()); } @@ -58,41 +54,8 @@ export default function DownloadButton({ return; } - try { - const response = await fetch(withBackend(`/download/${executable.id}`), { - method: "GET", - headers: { - "Content-Type": "application/octet-stream", - }, - }); - - if (!response.ok) { - if (response.headers.get("Content-Type") === "application/json") { - const json = await response.json(); - console.error("Download failed", json); - } else { - console.error( - "Download failed (unreadable response)", - response.statusText - ); - } - } - - // Create blob link to download - const blob = await response.blob(); - const url = window.URL.createObjectURL(blob); - - // Create a link element and click it to download the file - const link = document.createElement("a"); - link.href = url; - link.setAttribute("download", executable.filename); - document.body.appendChild(link); - link.click(); - link.parentNode!.removeChild(link); - window.URL.revokeObjectURL(url); - } catch (error) { - console.error("Download failed", error); - } + // Open the download link in a new tab + window.open(withBackend(`/download/${executable.id}`), "_blank"); } function handleDownloadAutomatic() { @@ -121,6 +84,7 @@ export default function DownloadButton({ >