diff --git a/src/components/DownloadModal/DownloadModal.tsx b/src/components/DownloadModal/DownloadModal.tsx index 2dabb7f8..0fa12052 100644 --- a/src/components/DownloadModal/DownloadModal.tsx +++ b/src/components/DownloadModal/DownloadModal.tsx @@ -1,5 +1,5 @@ import { Button, DialogModal } from "@fluffylabs/shared-ui"; -import { useContext, useState } from "react"; +import { type MouseEvent, useContext, useRef, useState } from "react"; import { Tooltip } from "react-tooltip"; import { DOC_CONFIG } from "../../config/documentConfig"; import { SHORT_COMMIT_HASH_LENGTH } from "../LocationProvider/utils/constants"; @@ -10,6 +10,7 @@ import { type IPdfContext, type ITheme, PdfContext, themesOrder } from "../PdfPr export function DownloadModal() { const [isOpen, setIsOpen] = useState(false); const [isProcessing, setIsProcessing] = useState(false); + const isProcessingRef = useRef(false); const [error, setError] = useState(); const { version } = useVersionContext(); const { urlGetters } = useContext(MetadataContext) as IMetadataContext; @@ -19,6 +20,10 @@ export function DownloadModal() { const shortVersion = version.substring(0, SHORT_COMMIT_HASH_LENGTH); const handleGeneratePdf = async () => { + if (isProcessingRef.current) { + return; + } + isProcessingRef.current = true; setIsProcessing(true); setError(undefined); try { @@ -30,11 +35,16 @@ export function DownloadModal() { } catch { setError("Failed to generate PDF. Please try again."); } finally { + isProcessingRef.current = false; setIsProcessing(false); } }; const fetchAndSave = async (url: string, filename: string) => { + if (isProcessingRef.current) { + return; + } + isProcessingRef.current = true; setIsProcessing(true); setError(undefined); try { @@ -53,17 +63,26 @@ export function DownloadModal() { } catch { setError(`Failed to download ${filename}. The file may not be available for this version.`); } finally { + isProcessingRef.current = false; setIsProcessing(false); } }; - const handleDownloadDarkPdf = () => { - fetchAndSave(urlGetters.pdf(version), `${DOC_CONFIG.pdfFilePrefix}-${shortVersion}.pdf`); + const handleLinkClick = (url: string, filename: string) => (event: MouseEvent) => { + if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) { + return; + } + event.preventDefault(); + if (isProcessingRef.current) { + return; + } + void fetchAndSave(url, filename); }; - const handleDownloadMarkdown = () => { - fetchAndSave(urlGetters.md(version), `${DOC_CONFIG.pdfFilePrefix}-${shortVersion}.md`); - }; + const pdfUrl = urlGetters.pdf(version); + const pdfFilename = `${DOC_CONFIG.pdfFilePrefix}-${shortVersion}.pdf`; + const mdUrl = urlGetters.md(version); + const mdFilename = `${DOC_CONFIG.pdfFilePrefix}-${shortVersion}.md`; return (
@@ -85,11 +104,25 @@ export function DownloadModal() { Download
- -
diff --git a/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-header-options-menu-light-mode-linux.png b/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-header-options-menu-light-mode-linux.png index 4c6e7568..be9c4955 100644 Binary files a/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-header-options-menu-light-mode-linux.png and b/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-header-options-menu-light-mode-linux.png differ diff --git a/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-sidebar-overlay-light-mode-linux.png b/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-sidebar-overlay-light-mode-linux.png index 5b19b4df..565264c8 100644 Binary files a/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-sidebar-overlay-light-mode-linux.png and b/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-sidebar-overlay-light-mode-linux.png differ diff --git a/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-view-opened-light-mode-linux.png b/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-view-opened-light-mode-linux.png index aade7480..8a46593c 100644 Binary files a/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-view-opened-light-mode-linux.png and b/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-view-opened-light-mode-linux.png differ diff --git a/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-view-via-url-dark-mode-linux.png b/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-view-via-url-dark-mode-linux.png index f0612c9a..2ca774d6 100644 Binary files a/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-view-via-url-dark-mode-linux.png and b/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-view-via-url-dark-mode-linux.png differ diff --git a/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-view-via-url-light-mode-linux.png b/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-view-via-url-light-mode-linux.png index 8a46593c..aade7480 100644 Binary files a/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-view-via-url-light-mode-linux.png and b/tools/snapshot-tests/tests/split-screen.spec.ts-snapshots/split-view-via-url-light-mode-linux.png differ