fix: download not working

This commit is contained in:
Alzalia 2025-09-06 21:20:48 +02:00
parent 21d22ab5e8
commit ce1751c871

View file

@ -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) {
<li>
<a
key={i}
className="text-sky-600 underline"
className={
isDownloading
? 'text-gray-600 underline cursor-wait'
: 'text-sky-600 underline cursor-pointer'
}
onClick={() => download(e.link, e.filename)}
>
{isDownloading
? '[Téléchargement en cours ...] '
: null}{' '}
{e.title}
</a>
</li>