From 49cda7ec0828703393f97cabb8941ee7a18fa8b8 Mon Sep 17 00:00:00 2001 From: Ali Josheghani Date: Fri, 24 May 2024 17:02:42 +0330 Subject: [PATCH] fix : bug load images in turotials pages --- .../tutorial/section/components/Leran.tsx | 132 +++++++++--------- 1 file changed, 68 insertions(+), 64 deletions(-) diff --git a/src/pages/tutorial/section/components/Leran.tsx b/src/pages/tutorial/section/components/Leran.tsx index aab4059..defa3b8 100644 --- a/src/pages/tutorial/section/components/Leran.tsx +++ b/src/pages/tutorial/section/components/Leran.tsx @@ -1,100 +1,104 @@ import { useEffect, useState } from "react"; import { LearnProps } from "../../../../types/props"; - -import v2ray from "../../../../assets/tutorial/android/v2ray.png"; -import eshterki1 from "../../../../assets/tutorial/ios/1-eshterki.jpg"; -import eshterki2 from "../../../../assets/tutorial/ios/2-eshteraki.jpg"; -import eshterki3 from "../../../../assets/tutorial/ios/3-eshteraki.jpg"; -import eshterki4 from "../../../../assets/tutorial/ios/4-eshteraki.jpg"; -import Button from "../../../../components/button"; +import { BiLoaderAlt } from "react-icons/bi"; const Learn = ({ activeTutorial, tutorialList }: LearnProps) => { - const data = [ + const tutorialImages = [ { id: 1, - images: [ - { - id: 1, - url: v2ray, - alt: "v2ray", - }, - ], - btn: "دانلود برنامه", + images: [{ urlimg: "https://persain-game.com/front_end/img/v2ray.png" }], }, { id: 2, images: [ - { - id: 1, - url: eshterki1, - alt: "eshterki1", - }, - { - id: 2, - url: eshterki2, - alt: "eshteraki2", - }, - { - id: 3, - url: eshterki3, - alt: "eshterki3", - }, - { - id: 4, - url: eshterki4, - alt: "eshterki4", - }, + { urlimg: "https://persain-game.com/front_end/img/1-eshterki.jpg" }, + { urlimg: "https://persain-game.com/front_end/img/2-eshteraki.jpg" }, + { urlimg: "https://persain-game.com/front_end/img/3-eshteraki.jpg" }, + { urlimg: "https://persain-game.com/front_end/img/4-eshteraki.jpg" }, ], - btn: null, }, { id: 3, - images: [], - btn: null, + images: [ + { urlimg: "https://persain-game.com/front_end/img/cisco-android1.jpg" }, + { urlimg: "https://persain-game.com/front_end/img/cisco-android2.jpg" }, + { urlimg: "https://persain-game.com/front_end/img/cisco-android3.jpg" }, + ], }, { id: 4, - images: [], - btn: null, + images: [ + { urlimg: "https://persain-game.com/front_end/img/cisco-iphone1.jpg" }, + { urlimg: "https://persain-game.com/front_end/img/cisco-iphone2.jpg" }, + { urlimg: "https://persain-game.com/front_end/img/cisco-iphone3.jpg" }, + ], + }, + { + id: 5, + images: [], + }, + { + id: 6, + images: [ + { urlimg: "https://persain-game.com/front_end/img/cisco-pc.jpg" }, + { urlimg: "https://persain-game.com/front_end/img/cisco-pc2.jpg" }, + { urlimg: "https://persain-game.com/front_end/img/cisco-pc3.jpg" }, + ], + }, + { + id: 7, + images: [], }, - { id: 5, images: [], btn: null }, - { id: 6, images: [], btn: null }, - { id: 7, images: [], btn: null }, ]; - const [tutotialImage, setTutorialImage] = useState(data); - const [list, setList] = useState(tutorialList); + const [loading, setLoading] = useState(true); + const [list, setList] = useState( + tutorialList?.filter((id) => id.id === activeTutorial) + ); + const [tutorialImagesState, setTutorialImagesState] = useState( + tutorialImages?.filter((id) => id.id === activeTutorial) + ); useEffect(() => { setList(tutorialList?.filter((id) => id.id === activeTutorial)); - setTutorialImage(data?.filter((id) => id.id === activeTutorial)); + setTutorialImagesState( + tutorialImages?.filter((id) => id.id === activeTutorial) + ); + setLoading(true); }, [activeTutorial]); + const handleLoadingImage = (e) => { + if (e.type === "load") setLoading(false); + }; return (
{list?.map((i) => { - return ( -

- {i.name} -

- ); - })} - {tutotialImage?.map((i) => { return (
-
- {i.images?.map((i, index) => { + {i.name} + {loading && ( +
+ +
+ )} +
+ {tutorialImagesState?.map((i) => { return ( - {i.alt} +
+ {i.images?.map((item) => { + return ( + images handleLoadingImage(e)} + /> + ); + })} +
); })}
- {i.btn && }
); })}