From 60e116965f42e7e8944c0adcc4bc7bc5fc3a485a Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Wed, 6 Aug 2025 10:58:15 +0700
Subject: <hafid> media banner

---
 src/lib/home/components/MediaNews.jsx | 107 ++++++++++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)
 create mode 100644 src/lib/home/components/MediaNews.jsx

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

diff --git a/src/lib/home/components/MediaNews.jsx b/src/lib/home/components/MediaNews.jsx
new file mode 100644
index 00000000..1e538d48
--- /dev/null
+++ b/src/lib/home/components/MediaNews.jsx
@@ -0,0 +1,107 @@
+import Link from '@/core/components/elements/Link/Link';
+import Image from 'next/image';
+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 () => {
+      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();
+  }, []);
+
+  const promotionProgram = data;
+
+  if (isLoading) {
+    return <BannerPromoSkeleton />;
+  }
+
+  if (!promotionProgram || promotionProgram.length === 0) {
+    return null; 
+  }
+
+  return (
+    <div className='px-4 sm:px-0'>
+      <div className='flex justify-between items-center mb-4 '>
+        <h1 className='font-semibold text-[14px] sm:text-h-lg'>
+          {' '}
+          <Link href='/shop/promo' className='!text-black font-semibold'>
+            Promo Tersedia
+          </Link>
+        </h1>
+        {isDesktop && (
+          <Link href='/shop/promo' className='!text-red-500 font-semibold'>
+            Lihat Semua
+          </Link>
+        )}
+        {isMobile && (
+          <Link
+            href='/shop/promo'
+            className='!text-red-500 font-semibold sm:text-h-sm'
+          >
+            Lihat Semua
+          </Link>
+        )}
+      </div>
+      {isDesktop && promotionProgram && promotionProgram?.length > 0 && (
+        <div className='grid grid-cols-3 sm:grid-cols-3 gap-4   rounded-md'>
+          {promotionProgram?.map((banner) => (
+            <Link key={banner.id} href={banner.url}>
+              <Image
+                width={439}
+                height={150}
+                quality={85}
+                src={banner.image}
+                alt={banner.name}
+                className='rounded hover:scale-105 transition duration-500 ease-in-out'
+                loading='eager'
+              />
+            </Link>
+          ))}
+        </div>
+      )}
+
+      {isMobile && (
+        <Swiper slidesPerView={1.1} spaceBetween={8} freeMode>
+          {promotionProgram?.map((banner) => (
+            <SwiperSlide key={banner.id}>
+              <Link key={banner.id} href={banner.url}>
+                <Image
+                  width={350}
+                  height={100}
+                  quality={70}
+                  src={banner.image}
+                  alt={banner.name}
+                  className='rounded '
+                  loading='eager'
+                />
+              </Link>
+            </SwiperSlide>
+          ))}
+        </Swiper>
+      )}
+    </div>
+  );
+};
+
+export default BannerSection;
-- 
cgit v1.2.3


From d32ed92902d52934a55cdb9efe110ef11cd920d8 Mon Sep 17 00:00:00 2001
From: "Indoteknik ." <andrifebriyadiputra@gmail.com>
Date: Sat, 16 Aug 2025 09:52:55 +0700
Subject: (andri) make component card mediacard

---
 src/lib/home/components/MediaNews.jsx | 137 +++++++++++++---------------------
 1 file changed, 52 insertions(+), 85 deletions(-)

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

diff --git a/src/lib/home/components/MediaNews.jsx b/src/lib/home/components/MediaNews.jsx
index 1e538d48..1c76398f 100644
--- a/src/lib/home/components/MediaNews.jsx
+++ b/src/lib/home/components/MediaNews.jsx
@@ -1,101 +1,68 @@
-import Link from '@/core/components/elements/Link/Link';
-import Image from 'next/image';
-import { bannerApi } from '@/api/bannerApi';
-import useDevice from '@/core/hooks/useDevice';
 import { Swiper, SwiperSlide } from 'swiper/react';
-import BannerPromoSkeleton from '../components/Skeleton/BannerPromoSkeleton';
+import { Navigation, Pagination, Autoplay } from 'swiper';
+import { useEffect, useState, useCallback } from 'react';
+import MediaNewsSkeleton from './Skeleton/MediaNewsSkeleton';
+import MediaCard from '@/lib/brand/components/MediaCard';
+import useDevice from '@/core/hooks/useDevice';
+import Link from '@/core/components/elements/Link/Link';
 
-import { useEffect, useState } from 'react';
-const { useQuery } = require('react-query');
-const BannerSection = () => {
+const MediaNews = () => {
+  const [isLoading, setIsLoading] = useState(true);
+  const [media, setMedia] = useState([]);
   const { isMobile, isDesktop } = useDevice();
-  const [data, setData] = useState(null);
-  const [shouldFetch, setShouldFetch] = useState(false);
-  const [ isLoading, setIsLoading] = useState(true);
-  useEffect(() => {
-    const fetchData = async () => {
-      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();
+  const loadMedia = useCallback(async () => {
+    try {
+      setIsLoading(true);
+      const res = await fetch(`/api/hero-banner?type=media-berita`);
+      const result = await res.json();
+      setMedia(result.data || []);
+    } catch (err) {
+      console.error('Failed to load media:', err);
+    } finally {
+      setIsLoading(false);
+    }
   }, []);
 
-  const promotionProgram = data;
+  useEffect(() => {
+    loadMedia();
+  }, [loadMedia]);
 
-  if (isLoading) {
-    return <BannerPromoSkeleton />;
-  }
+  const swiperConfig = {
+    modules: [Navigation, Pagination, Autoplay],
+    autoplay: { delay: 4000, disableOnInteraction: false },
+    loop: true,
+    className: 'h-[70px] md:h-[100px] w-full',
+    slidesPerView: isMobile ? 4 : 8,
+    spaceBetween: isMobile ? 12 : 0,
+    pagination: { dynamicBullets: true, dynamicMainBullets: isMobile ? 6 : 8, clickable: true },
+  };
 
-  if (!promotionProgram || promotionProgram.length === 0) {
-    return null; 
-  }
+  const preferredMediaData = media.slice(0, 20);
 
   return (
-    <div className='px-4 sm:px-0'>
-      <div className='flex justify-between items-center mb-4 '>
-        <h1 className='font-semibold text-[14px] sm:text-h-lg'>
-          {' '}
-          <Link href='/shop/promo' className='!text-black font-semibold'>
-            Promo Tersedia
+    <div className="px-4 sm:px-0">
+      <div className="flex justify-between items-center mb-4">
+        <h1 className="font-semibold text-[14px] sm:text-h-lg">
+          <Link href="/shop/media" className="!text-black font-semibold">
+            Media Berita
           </Link>
         </h1>
-        {isDesktop && (
-          <Link href='/shop/promo' className='!text-red-500 font-semibold'>
-            Lihat Semua
-          </Link>
-        )}
-        {isMobile && (
-          <Link
-            href='/shop/promo'
-            className='!text-red-500 font-semibold sm:text-h-sm'
-          >
-            Lihat Semua
-          </Link>
-        )}
+        <Link
+          href="/shop/media"
+          className="!text-red-500 font-semibold sm:text-h-sm"
+        >
+          Lihat Semua
+        </Link>
       </div>
-      {isDesktop && promotionProgram && promotionProgram?.length > 0 && (
-        <div className='grid grid-cols-3 sm:grid-cols-3 gap-4   rounded-md'>
-          {promotionProgram?.map((banner) => (
-            <Link key={banner.id} href={banner.url}>
-              <Image
-                width={439}
-                height={150}
-                quality={85}
-                src={banner.image}
-                alt={banner.name}
-                className='rounded hover:scale-105 transition duration-500 ease-in-out'
-                loading='eager'
-              />
-            </Link>
-          ))}
-        </div>
-      )}
 
-      {isMobile && (
-        <Swiper slidesPerView={1.1} spaceBetween={8} freeMode>
-          {promotionProgram?.map((banner) => (
-            <SwiperSlide key={banner.id}>
-              <Link key={banner.id} href={banner.url}>
-                <Image
-                  width={350}
-                  height={100}
-                  quality={70}
-                  src={banner.image}
-                  alt={banner.name}
-                  className='rounded '
-                  loading='eager'
-                />
-              </Link>
+      {isLoading ? (
+        <MediaNewsSkeleton />
+      ) : (
+        <Swiper {...swiperConfig}>
+          {preferredMediaData.map((item) => (
+            <SwiperSlide key={item.id}>
+              <MediaCard media={item} />
             </SwiperSlide>
           ))}
         </Swiper>
@@ -104,4 +71,4 @@ const BannerSection = () => {
   );
 };
 
-export default BannerSection;
+export default MediaNews;
-- 
cgit v1.2.3


From 8492e0bccb64265d647efb34062787f56a2ddeb8 Mon Sep 17 00:00:00 2001
From: "Indoteknik ." <andrifebriyadiputra@gmail.com>
Date: Sat, 16 Aug 2025 10:51:54 +0700
Subject: (andri) filter swiper only > 8 desktop

---
 src/lib/home/components/MediaNews.jsx | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

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

diff --git a/src/lib/home/components/MediaNews.jsx b/src/lib/home/components/MediaNews.jsx
index 1c76398f..ec27a51d 100644
--- a/src/lib/home/components/MediaNews.jsx
+++ b/src/lib/home/components/MediaNews.jsx
@@ -40,12 +40,14 @@ const MediaNews = () => {
 
   const preferredMediaData = media.slice(0, 20);
 
+  const shouldUseSlider = isDesktop && preferredMediaData.length > 8;
+
   return (
     <div className="px-4 sm:px-0">
       <div className="flex justify-between items-center mb-4">
         <h1 className="font-semibold text-[14px] sm:text-h-lg">
           <Link href="/shop/media" className="!text-black font-semibold">
-            Media Berita
+            Media Partner
           </Link>
         </h1>
         <Link
@@ -58,7 +60,7 @@ const MediaNews = () => {
 
       {isLoading ? (
         <MediaNewsSkeleton />
-      ) : (
+      ) : shouldUseSlider ? (
         <Swiper {...swiperConfig}>
           {preferredMediaData.map((item) => (
             <SwiperSlide key={item.id}>
@@ -66,6 +68,12 @@ const MediaNews = () => {
             </SwiperSlide>
           ))}
         </Swiper>
+      ) : (
+        <div className="flex flex-wrap justify-center gap-4">
+          {preferredMediaData.map((item) => (
+            <MediaCard key={item.id} media={item} />
+          ))}
+        </div>
       )}
     </div>
   );
-- 
cgit v1.2.3


From 8045280d780061e1829fe596410356589e323fb6 Mon Sep 17 00:00:00 2001
From: "Indoteknik ." <andrifebriyadiputra@gmail.com>
Date: Sat, 16 Aug 2025 11:46:59 +0700
Subject: (andri) fix

---
 src/lib/home/components/MediaNews.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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

diff --git a/src/lib/home/components/MediaNews.jsx b/src/lib/home/components/MediaNews.jsx
index ec27a51d..116dda2b 100644
--- a/src/lib/home/components/MediaNews.jsx
+++ b/src/lib/home/components/MediaNews.jsx
@@ -40,7 +40,7 @@ const MediaNews = () => {
 
   const preferredMediaData = media.slice(0, 20);
 
-  const shouldUseSlider = isDesktop && preferredMediaData.length > 8;
+  const shouldUseSlider = isMobile || (isDesktop && preferredMediaData.length > 8);
 
   return (
     <div className="px-4 sm:px-0">
-- 
cgit v1.2.3


From 4690139fb33be48ca49cca1b3d270941a0a5e89a Mon Sep 17 00:00:00 2001
From: "Indoteknik ." <andrifebriyadiputra@gmail.com>
Date: Sat, 16 Aug 2025 13:21:29 +0700
Subject: (andri) fix

---
 src/lib/home/components/MediaNews.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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

diff --git a/src/lib/home/components/MediaNews.jsx b/src/lib/home/components/MediaNews.jsx
index 116dda2b..ac56d4e3 100644
--- a/src/lib/home/components/MediaNews.jsx
+++ b/src/lib/home/components/MediaNews.jsx
@@ -47,7 +47,7 @@ const MediaNews = () => {
       <div className="flex justify-between items-center mb-4">
         <h1 className="font-semibold text-[14px] sm:text-h-lg">
           <Link href="/shop/media" className="!text-black font-semibold">
-            Media Partner
+            Telah Diliput Media
           </Link>
         </h1>
         <Link
-- 
cgit v1.2.3


From 4e7854765e66b27246b9dafc0177905d707d0cd1 Mon Sep 17 00:00:00 2001
From: "Indoteknik ." <andrifebriyadiputra@gmail.com>
Date: Sat, 16 Aug 2025 14:33:24 +0700
Subject: (andri) fix

---
 src/lib/home/components/MediaNews.jsx | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

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

diff --git a/src/lib/home/components/MediaNews.jsx b/src/lib/home/components/MediaNews.jsx
index ac56d4e3..528fbe7c 100644
--- a/src/lib/home/components/MediaNews.jsx
+++ b/src/lib/home/components/MediaNews.jsx
@@ -46,16 +46,10 @@ const MediaNews = () => {
     <div className="px-4 sm:px-0">
       <div className="flex justify-between items-center mb-4">
         <h1 className="font-semibold text-[14px] sm:text-h-lg">
-          <Link href="/shop/media" className="!text-black font-semibold">
+          <Link href="/" className="!text-black font-semibold">
             Telah Diliput Media
           </Link>
         </h1>
-        <Link
-          href="/shop/media"
-          className="!text-red-500 font-semibold sm:text-h-sm"
-        >
-          Lihat Semua
-        </Link>
       </div>
 
       {isLoading ? (
-- 
cgit v1.2.3


From 9fa82a1c56e6e1628ef5a255ba3f66fb6aec83ec Mon Sep 17 00:00:00 2001
From: "Indoteknik ." <andrifebriyadiputra@gmail.com>
Date: Mon, 25 Aug 2025 16:07:26 +0700
Subject: (andri) tidak render media jika tidak ada data

---
 src/lib/home/components/MediaNews.jsx | 4 ++++
 1 file changed, 4 insertions(+)

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

diff --git a/src/lib/home/components/MediaNews.jsx b/src/lib/home/components/MediaNews.jsx
index 528fbe7c..6a0efbfe 100644
--- a/src/lib/home/components/MediaNews.jsx
+++ b/src/lib/home/components/MediaNews.jsx
@@ -42,6 +42,10 @@ const MediaNews = () => {
 
   const shouldUseSlider = isMobile || (isDesktop && preferredMediaData.length > 8);
 
+  if (!isLoading && preferredMediaData.length === 0) {
+    return null;
+  }
+
   return (
     <div className="px-4 sm:px-0">
       <div className="flex justify-between items-center mb-4">
-- 
cgit v1.2.3

