fix: download not working
This commit is contained in:
parent
21d22ab5e8
commit
ce1751c871
1 changed files with 17 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import type { CardDownloadType } from '@/types/cards'
|
import type { CardDownloadType } from '@/types/cards'
|
||||||
import Mdown from './Mdown'
|
import Mdown from './Mdown'
|
||||||
|
import { useState } from 'react'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
title: string
|
title: string
|
||||||
|
|
@ -9,7 +10,13 @@ interface Props {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Card({ title, content, id, downloads }: Props) {
|
export default function Card({ title, content, id, downloads }: Props) {
|
||||||
|
const [isDownloading, setIsDownloading] = useState(false)
|
||||||
|
|
||||||
function download(path: URL, fileName = 'file') {
|
function download(path: URL, fileName = 'file') {
|
||||||
|
if (isDownloading) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setIsDownloading(true)
|
||||||
fetch(path)
|
fetch(path)
|
||||||
.then((response) => response.blob())
|
.then((response) => response.blob())
|
||||||
.then((blob) => {
|
.then((blob) => {
|
||||||
|
|
@ -24,6 +31,8 @@ export default function Card({ title, content, id, downloads }: Props) {
|
||||||
link.click()
|
link.click()
|
||||||
|
|
||||||
link.parentNode?.removeChild(link)
|
link.parentNode?.removeChild(link)
|
||||||
|
|
||||||
|
setIsDownloading(false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,9 +52,16 @@ export default function Card({ title, content, id, downloads }: Props) {
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a
|
||||||
key={i}
|
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)}
|
onClick={() => download(e.link, e.filename)}
|
||||||
>
|
>
|
||||||
|
{isDownloading
|
||||||
|
? '[Téléchargement en cours ...] '
|
||||||
|
: null}{' '}
|
||||||
{e.title}
|
{e.title}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue