diff --git a/src/components/Card.tsx b/src/components/Card.tsx index bdffc76..82f7615 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,41 @@ interface Props { } 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) => { @@ -24,37 +59,25 @@ export default function Card({ title, content, id, downloads }: Props) { link.click() link.parentNode?.removeChild(link) + + setIsDownloading(false) }) } return ( -
-

- {title} -

-
- {content} -
- {downloads != null ? ( -
- Téléchargments -
    - {downloads.map((e, i) => ( -
  1. - download(e.link, e.filename)} - > - {e.title} - -
  2. - ))} -
-
- ) : null} -
+
  • + download(e.link, e.filename)} + > + {isDownloading ? '[Téléchargement en cours ...] ' : null}{' '} + {e.title} + +
  • ) } diff --git a/src/components/Mdown.tsx b/src/components/Mdown.tsx index cab339a..8dd4979 100644 --- a/src/components/Mdown.tsx +++ b/src/components/Mdown.tsx @@ -22,9 +22,22 @@ export default function Mdown({ children }: Props) { const { node, ...rest } = props return
  • }, + p(props) { + const { node, ...rest } = props + return

    + }, + code(props) { + const { node, ...rest } = props + return ( + + ) + }, a(props) { const { node, ...rest } = props - const classes = 'text-sky-600 underline' + const classes = 'text-sky-700 underline' if (rest.href?.startsWith('dl:')) { let parts = rest.href.split('/') return ( diff --git a/src/routes/index.tsx b/src/routes/index.tsx index e93f99c..d720a17 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -31,7 +31,7 @@ function App() { return (

    -
    +

    {data.title}

    diff --git a/src/routes/lessons/$lessonName.tsx b/src/routes/lessons/$lessonName.tsx index 41ec497..efabaaf 100644 --- a/src/routes/lessons/$lessonName.tsx +++ b/src/routes/lessons/$lessonName.tsx @@ -44,7 +44,7 @@ export default function Projects() { return (
    -
    +

    {data.title}

    diff --git a/src/routes/lessons/index.tsx b/src/routes/lessons/index.tsx index 0eb6a72..2baf91a 100644 --- a/src/routes/lessons/index.tsx +++ b/src/routes/lessons/index.tsx @@ -31,7 +31,7 @@ export default function Projects() { return (
    -
    +

    {data.title}

    diff --git a/src/routes/projects/index.tsx b/src/routes/projects/index.tsx index 941e840..c34a702 100644 --- a/src/routes/projects/index.tsx +++ b/src/routes/projects/index.tsx @@ -31,7 +31,7 @@ export default function Projects() { return (
    -
    +

    {data.title}