import { faDownload } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useDownloadLogFiles } from "../../../hooks/useDownloadLogFiles"; import { toast } from "sonner"; const DownloadLogButton = () => { const { downloadLogFilesQuery } = useDownloadLogFiles(); const isLoading = downloadLogFilesQuery?.isFetching; const handleDownloadClick = async () => { try { const blob = await downloadLogFilesQuery?.refetch().then((res) => res.data); if (!blob) { throw new Error("No log file data received"); } const url = window.URL.createObjectURL(new Blob([blob])); const link = document.createElement("a"); if (!link) { throw new Error("Failed to create download link"); } else { link.href = url; link.setAttribute("download", "FlexiAI-0.log"); document.body.appendChild(link); link.click(); link.parentNode?.removeChild(link); window.URL.revokeObjectURL(url); } } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; toast.error(errorMessage); } }; return ( ); }; export default DownloadLogButton;