mirror of
https://github.com/Xevion/dynamic-preauth.git
synced 2025-12-06 01:14:55 -06:00
Remove unnecessary logs, switch to simple window.open download, suppressHydrationWarning
This commit is contained in:
@@ -13,8 +13,6 @@ const Demo = ({ class: className }: DemoProps) => {
|
|||||||
const { id, downloads, executables } = useSocket();
|
const { id, downloads, executables } = useSocket();
|
||||||
// TODO: Toasts
|
// TODO: Toasts
|
||||||
|
|
||||||
console.log([executables == null]);
|
|
||||||
|
|
||||||
const [highlightedIndex, setHighlightedIndex] = useState<number | null>(null);
|
const [highlightedIndex, setHighlightedIndex] = useState<number | null>(null);
|
||||||
const highlightedTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
const highlightedTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import type { Executable } from "@/components/useSocket";
|
import type { Executable } from "@/components/useSocket";
|
||||||
import { cn, withBackend } from "@/util";
|
import { cn, withBackend } from "@/util";
|
||||||
import {
|
import {
|
||||||
@@ -45,8 +43,6 @@ export default function DownloadButton({
|
|||||||
}: DownloadButtonProps) {
|
}: DownloadButtonProps) {
|
||||||
const menuRef = useRef<HTMLButtonElement>(null);
|
const menuRef = useRef<HTMLButtonElement>(null);
|
||||||
|
|
||||||
console.log({ disabled });
|
|
||||||
|
|
||||||
function getExecutable(id: string) {
|
function getExecutable(id: string) {
|
||||||
return executables?.find((e) => e.id.toLowerCase() === id.toLowerCase());
|
return executables?.find((e) => e.id.toLowerCase() === id.toLowerCase());
|
||||||
}
|
}
|
||||||
@@ -58,41 +54,8 @@ export default function DownloadButton({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// Open the download link in a new tab
|
||||||
const response = await fetch(withBackend(`/download/${executable.id}`), {
|
window.open(withBackend(`/download/${executable.id}`), "_blank");
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDownloadAutomatic() {
|
function handleDownloadAutomatic() {
|
||||||
@@ -121,6 +84,7 @@ export default function DownloadButton({
|
|||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleDownloadAutomatic}
|
onClick={handleDownloadAutomatic}
|
||||||
|
suppressHydrationWarning
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
className={cn("pl-3 font-semibold pr-2.5", {
|
className={cn("pl-3 font-semibold pr-2.5", {
|
||||||
"hover:bg-white/5": !disabled,
|
"hover:bg-white/5": !disabled,
|
||||||
@@ -131,7 +95,8 @@ export default function DownloadButton({
|
|||||||
<Menu>
|
<Menu>
|
||||||
<MenuButton
|
<MenuButton
|
||||||
ref={menuRef}
|
ref={menuRef}
|
||||||
disabled={disabled ?? false}
|
suppressHydrationWarning
|
||||||
|
disabled={disabled}
|
||||||
className={cn("pl-1.5 text-transparent min-h-8 pr-2", {
|
className={cn("pl-1.5 text-transparent min-h-8 pr-2", {
|
||||||
"hover:bg-white/5": !disabled,
|
"hover:bg-white/5": !disabled,
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ function useSocket(): UseSocketResult {
|
|||||||
};
|
};
|
||||||
|
|
||||||
socket.onclose = (event) => {
|
socket.onclose = (event) => {
|
||||||
console.log("WebSocket connection closed", event);
|
console.warn("WebSocket connection closed", event);
|
||||||
|
|
||||||
socketRef.current = null;
|
socketRef.current = null;
|
||||||
if (allowReconnectRef.current) {
|
if (allowReconnectRef.current) {
|
||||||
@@ -105,7 +105,7 @@ function useSocket(): UseSocketResult {
|
|||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
// Close the socket when the component is unmounted
|
// Close the socket when the component is unmounted
|
||||||
console.log("Unmounting, closing WebSocket connection");
|
console.debug("Unmounting, closing WebSocket connection");
|
||||||
socketRef.current?.close();
|
socketRef.current?.close();
|
||||||
allowReconnectRef.current = false;
|
allowReconnectRef.current = false;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user