import type { CardDownloadType } from '@/types/cards' import Mdown from './Mdown' import { useState } from 'react' interface Props { title: string content: string id?: number downloads?: Array } export default function Card({ title, content, id, downloads }: Props) { return (

{title}

{content}
{downloads != null ? (
Téléchargments
    {downloads.map((e, i) => ( ))}
) : null}
) } interface DownloadProps { e: CardDownloadType i: number } function Download({ e, i }: DownloadProps) { const [isDownloading, setIsDownloading] = useState(false) function download(path: URL, fileName = 'file') { if (isDownloading) { return } setIsDownloading(true) fetch(path) .then((response) => response.blob()) .then((blob) => { const url = window.URL.createObjectURL(new Blob([blob])) const link = document.createElement('a') link.href = url link.download = fileName document.body.appendChild(link) link.click() link.parentNode?.removeChild(link) setIsDownloading(false) }) } return (
  • download(e.link, e.filename)} > {isDownloading ? '[Téléchargement en cours ...] ' : null}{' '} {e.title}
  • ) }