From ce1751c871a2cef53534a351bbe3f5ef5e2e6336 Mon Sep 17 00:00:00 2001 From: Alzalia Date: Sat, 6 Sep 2025 21:20:48 +0200 Subject: [PATCH] fix: download not working --- src/components/Card.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/components/Card.tsx b/src/components/Card.tsx index 2ea9502..54e73ae 100644 --- a/src/components/Card.tsx +++ b/src/components/Card.tsx @@ -1,5 +1,6 @@ import type { CardDownloadType } from '@/types/cards' import Mdown from './Mdown' +import { useState } from 'react' interface Props { title: string @@ -9,7 +10,13 @@ interface Props { } export default function Card({ title, content, id, downloads }: Props) { + const [isDownloading, setIsDownloading] = useState(false) + function download(path: URL, fileName = 'file') { + if (isDownloading) { + return + } + setIsDownloading(true) fetch(path) .then((response) => response.blob()) .then((blob) => { @@ -24,6 +31,8 @@ export default function Card({ title, content, id, downloads }: Props) { link.click() link.parentNode?.removeChild(link) + + setIsDownloading(false) }) } @@ -43,9 +52,16 @@ export default function Card({ title, content, id, downloads }: Props) {
  • download(e.link, e.filename)} > + {isDownloading + ? '[TĂ©lĂ©chargement en cours ...] ' + : null}{' '} {e.title}