diff --git a/src/pages/tutorial/section/components/Leran.tsx b/src/pages/tutorial/section/components/Leran.tsx index 7597a0f..e769c10 100644 --- a/src/pages/tutorial/section/components/Leran.tsx +++ b/src/pages/tutorial/section/components/Leran.tsx @@ -1,3 +1,4 @@ +import { useState } from "react"; import { LearnProps } from "../../../../types/props"; import { useQuery } from "@tanstack/react-query"; import useAxios from "../../../../hooks/useAxios"; @@ -6,6 +7,12 @@ import { MdErrorOutline } from "react-icons/md"; import Button from "../../../../components/button"; import { saveAs } from "file-saver"; import { Fragment } from "react/jsx-runtime"; +import { + IoClose, + IoDocumentTextOutline, + IoDownloadOutline, + IoPlayCircleOutline, +} from "react-icons/io5"; const getMediaType = (url: string) => { const extension = url.split(".").pop()?.toLowerCase(); @@ -20,6 +27,9 @@ const getMediaType = (url: string) => { return "unknown"; }; +type Attachment = { id: number | null; title: string; url: string }; +type LightboxState = { url: string; type: "image" | "video" } | null; + const Learn = ({ activeTutorial }: LearnProps) => { const axios = useAxios(); const { data, isLoading, isFetching, error } = useQuery({ @@ -28,8 +38,41 @@ const Learn = ({ activeTutorial }: LearnProps) => { return axios.get(`/home/category/learning/${activeTutorial}`); }, }); + const [lightbox, setLightbox] = useState(null); + return (
+ {lightbox && ( +
setLightbox(null)} + > + + {lightbox.type === "image" ? ( + media e.stopPropagation()} + /> + ) : ( +
+ )} + {isLoading || isFetching ? (
{ id: string; title: string; medias: string[]; - file: string | null; + attachments?: Attachment[]; url_file: string; }) => (
{i.title} -
- {i.medias.map((media, index) => { - const mediaType = getMediaType(media); - return ( -
- {mediaType === "image" ? ( - media - ) : mediaType === "video" ? ( -
-
- ); - })} -
- {i.file && ( - + ) : mediaType === "video" ? ( + <> +
)} + + {i.attachments && i.attachments.length > 0 && ( +
+ {i.attachments.map((att) => ( +
+
+ + + {att.title} + +
+ +
+ ))} +
+ )} + {i.url_file && ( - <> - - + )}