From 4a5391def4c5d2e8991643287d40e3c3b53980be Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 5 Nov 2024 15:49:45 +0700
Subject: <iman> add redis

---
 src/components/ui/HeroBanner.jsx | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

(limited to 'src/components/ui/HeroBanner.jsx')

diff --git a/src/components/ui/HeroBanner.jsx b/src/components/ui/HeroBanner.jsx
index 64838b85..2eea5915 100644
--- a/src/components/ui/HeroBanner.jsx
+++ b/src/components/ui/HeroBanner.jsx
@@ -6,7 +6,7 @@ import 'swiper/css/pagination';
 import { Swiper, SwiperSlide } from 'swiper/react';
 
 import Image from 'next/image';
-import { useMemo } from 'react';
+import { useEffect, useMemo, useState } from 'react';
 import { useQuery } from 'react-query';
 
 import { bannerApi } from '@/api/bannerApi';
@@ -27,7 +27,20 @@ const swiperBanner = {
 };
 
 const HeroBanner = () => {
-  const heroBanner = useQuery('heroBanner', bannerApi({ type: 'index-a-1' }));
+  // const heroBanner = useQuery('heroBanner', bannerApi({ type: 'index-a-1' }));
+  const [data, setData] = useState(null);
+  useEffect(() => {
+    const fetchData = async () => {
+      const res = await fetch(`/api/hero-banner?type=index-a-1`);
+      const { data } = await res.json();
+      if (data) {
+        setData(data);
+      }
+    };
+
+    fetchData();
+  }, []);
+  const heroBanner = data;
 
   const swiperBannerMobile = {
     ...swiperBanner,
@@ -44,9 +57,9 @@ const HeroBanner = () => {
   };
 
   const BannerComponent = useMemo(() => {
-    if (!heroBanner.data) return null;
+    if (!heroBanner) return null;
 
-    return heroBanner.data.map((banner, index) => (
+    return heroBanner.map((banner, index) => (
       <SwiperSlide key={index}>
         <Link href={banner.url} className='w-full h-auto'>
           <Image
@@ -56,22 +69,22 @@ const HeroBanner = () => {
             width={1152}
             height={768}
             className='w-full h-auto'
-            priority={index === 0} 
-            loading={index === 0 ? 'eager' : 'lazy'} 
-            placeholder="blur" 
-            blurDataURL="/images/indoteknik-placeholder.png" 
-            sizes="(max-width: 768px) 100vw, 50vw" 
+            priority={index === 0}
+            loading={index === 0 ? 'eager' : 'lazy'}
+            placeholder='blur'
+            blurDataURL='/images/indoteknik-placeholder.png'
+            sizes='(max-width: 768px) 100vw, 50vw'
           />
         </Link>
       </SwiperSlide>
     ));
-  }, [heroBanner.data]);
+  }, [heroBanner]);
 
   return (
     <>
       <MobileView>
         <SmoothRender
-          isLoaded={heroBanner.data?.length > 0}
+          isLoaded={heroBanner?.length > 0}
           height='68vw'
           duration='750ms'
           delay='100ms'
@@ -81,7 +94,7 @@ const HeroBanner = () => {
       </MobileView>
 
       <DesktopView>
-        {heroBanner.data?.length > 0 && (
+        {heroBanner?.length > 0 && (
           <Swiper {...swiperBannerDesktop}>{BannerComponent}</Swiper>
         )}
       </DesktopView>
-- 
cgit v1.2.3

