summaryrefslogtreecommitdiff
path: root/src-migrate/modules/promo/components/Hero.tsx
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2024-02-17 10:23:23 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2024-02-17 10:23:23 +0700
commit8d8c43d90373aab6238773e291a48d65d55c52a2 (patch)
treecf7764337d3b79462ad4c8b53d85723e1d88618d /src-migrate/modules/promo/components/Hero.tsx
parentebfaccbff6aba23cb6e999fc6155596bc4cbf1b5 (diff)
Add voucher section
Diffstat (limited to 'src-migrate/modules/promo/components/Hero.tsx')
-rw-r--r--src-migrate/modules/promo/components/Hero.tsx23
1 files changed, 16 insertions, 7 deletions
diff --git a/src-migrate/modules/promo/components/Hero.tsx b/src-migrate/modules/promo/components/Hero.tsx
index 63524509..5470b93b 100644
--- a/src-migrate/modules/promo/components/Hero.tsx
+++ b/src-migrate/modules/promo/components/Hero.tsx
@@ -1,19 +1,21 @@
-import { Swiper, SwiperProps, SwiperSlide } from 'swiper/react';
-import style from '../styles/hero.module.css';
-import 'swiper/css'
+import 'swiper/css';
+
import Image from 'next/image';
+import { useEffect, useMemo } from 'react';
import { useQuery } from 'react-query';
+import { Swiper, SwiperProps, SwiperSlide } from 'swiper/react';
+
import { getBanner } from '~/services/banner';
+import style from '../styles/hero.module.css';
const swiperBanner: SwiperProps = {
autoplay: {
delay: 6000,
disableOnInteraction: false
},
- // modules: [Pagination, Autoplay],
- loop: true,
+ loop: false,
className: 'h-[400px] w-full',
- slidesPerView: 1.1,
+ slidesPerView: 1,
spaceBetween: 10
}
@@ -23,7 +25,14 @@ const Hero = () => {
queryFn: () => getBanner({ type: 'all-promo' })
})
- const banners = bannerQuery.data || []
+ const banners = useMemo(() => bannerQuery.data || [], [bannerQuery.data]);
+
+ useEffect(() => {
+ if (banners.length > 1) {
+ swiperBanner.slidesPerView = 1.1;
+ swiperBanner.loop = true;
+ }
+ }, [banners]);
return (
<div className={style['wrapper']}>