From d324d01bb9413a023a158a7bd15ba36bb7beb9bc Mon Sep 17 00:00:00 2001
From: trisusilo48 <tri.susilo@altama.co.id>
Date: Fri, 29 Nov 2024 14:38:24 +0700
Subject: update performance

---
 src/lib/home/components/PromotionProgram.jsx | 47 ++++++++--------------------
 1 file changed, 13 insertions(+), 34 deletions(-)

(limited to 'src/lib/home/components/PromotionProgram.jsx')

diff --git a/src/lib/home/components/PromotionProgram.jsx b/src/lib/home/components/PromotionProgram.jsx
index 562fa138..fc23bf78 100644
--- a/src/lib/home/components/PromotionProgram.jsx
+++ b/src/lib/home/components/PromotionProgram.jsx
@@ -4,56 +4,35 @@ import { bannerApi } from '@/api/bannerApi';
 import useDevice from '@/core/hooks/useDevice';
 import { Swiper, SwiperSlide } from 'swiper/react';
 import BannerPromoSkeleton from '../components/Skeleton/BannerPromoSkeleton';
+
 import { useEffect, useState } from 'react';
 const { useQuery } = require('react-query');
 const BannerSection = () => {
   const { isMobile, isDesktop } = useDevice();
   const [data, setData] = useState(null);
   const [shouldFetch, setShouldFetch] = useState(false);
+  const [ isLoading, setIsLoading] = useState(true);
   useEffect(() => {
     const fetchData = async () => {
-      const res = await fetch(`/api/hero-banner?type=banner-promotion`);
-      const { data } = await res.json();
-      if (data) {
-        setData(data);
+      try {
+        const res = await fetch(`/api/hero-banner?type=banner-promotion`);
+        const { data } = await res.json();
+        if (data) {
+          setData(data);
+        }
+      } catch (e) {
+        console.log(e);
+      } finally {
+        setIsLoading(false);
       }
     };
 
     fetchData();
   }, []);
 
-  // useEffect(() => {
-  //   const localData = localStorage.getItem('Homepage_promotionProgram');
-  //   if (localData) {
-  //     setData(JSON.parse(localData));
-  //   } else {
-  //     setShouldFetch(true);
-  //   }
-  // }, []);
-
-  // const getPromotionProgram = useQuery(
-  //   'promotionProgram',
-  //   bannerApi({ type: 'banner-promotion' }),
-  //   {
-  //     enabled: shouldFetch,
-  //     onSuccess: (data) => {
-  //       if (data) {
-  //         localStorage.setItem(
-  //           'Homepage_promotionProgram',
-  //           JSON.stringify(data)
-  //         );
-  //         setData(data);
-  //       }
-  //     },
-  //   }
-  // );
-
   const promotionProgram = data;
 
-  // if (getPromotionProgram?.isLoading && !data) {
-  //   return <BannerPromoSkeleton />;
-  // }
-  if (!data) {
+  if (isLoading) {
     return <BannerPromoSkeleton />;
   }
 
-- 
cgit v1.2.3

