@@ -6,6 +6,7 @@ import NextButton from '@/assets/images/icons/next_button_icon.svg';
66import PrevButton from '@/assets/images/icons/prev_button_icon.svg' ;
77import { USER_EVENT } from '@/constants/eventName' ;
88import useMixpanelTrack from '@/hooks/Mixpanel/useMixpanelTrack' ;
9+ import { useGetBanners } from '@/hooks/Queries/useBanner' ;
910import useDevice from '@/hooks/useDevice' ;
1011import useNavigator from '@/hooks/useNavigator' ;
1112import { detectPlatform , getAppStoreLink } from '@/utils/appStoreLink' ;
@@ -18,6 +19,23 @@ const Banner = () => {
1819 const trackEvent = useMixpanelTrack ( ) ;
1920 const [ swiperInstance , setSwiperInstance ] = useState < SwiperType | null > ( null ) ;
2021 const [ currentIndex , setCurrentIndex ] = useState ( 0 ) ;
22+ const bannerType = isMobile ? 'WEB_MOBILE' : 'WEB' ;
23+ const { data : banners , isLoading, isFetched } = useGetBanners ( bannerType ) ;
24+
25+ const fallbackBanners = BANNERS . map ( ( banner ) => ( {
26+ id : banner . id ,
27+ imageUrl : isMobile ? banner . mobileImage : banner . desktopImage ,
28+ linkTo : banner . linkTo ?? null ,
29+ alt : banner . alt ,
30+ } ) ) ;
31+
32+ const hasApiBanners = ( banners ?. length ?? 0 ) > 0 ;
33+ const shouldUseFallback = isFetched && ! hasApiBanners ;
34+ const displayBanners = hasApiBanners
35+ ? banners
36+ : shouldUseFallback
37+ ? fallbackBanners
38+ : [ ] ;
2139
2240 const handlePrev = ( ) => {
2341 swiperInstance ?. slidePrev ( ) ;
@@ -53,6 +71,14 @@ const Banner = () => {
5371 handleLink ( url ) ;
5472 } ;
5573
74+ if ( isLoading ) {
75+ return null ;
76+ }
77+
78+ if ( displayBanners ?. length === 0 ) {
79+ return null ;
80+ }
81+
5682 return (
5783 < Styled . BannerContainer >
5884 < Styled . BannerWrapper >
@@ -76,31 +102,32 @@ const Banner = () => {
76102 } }
77103 speed = { 500 }
78104 >
79- { BANNERS . map ( ( banner ) => (
105+ { displayBanners ? .map ( ( banner ) => (
80106 < SwiperSlide key = { banner . id } >
81107 < Styled . BannerItem
82108 isClickable = { ! ! banner . linkTo }
83109 onClick = { ( ) =>
84- handleBannerClick ( banner . id , banner . alt , banner . linkTo )
110+ handleBannerClick (
111+ banner . id ,
112+ banner . alt ,
113+ banner . linkTo || undefined ,
114+ )
85115 }
86116 >
87- < img
88- src = { isMobile ? banner . mobileImage : banner . desktopImage }
89- alt = { banner . alt }
90- />
117+ < img src = { banner . imageUrl } alt = { banner . alt } />
91118 </ Styled . BannerItem >
92119 </ SwiperSlide >
93120 ) ) }
94121 </ Swiper >
95122 { isMobile && (
96123 < Styled . NumericPagination >
97- { currentIndex + 1 } / { BANNERS . length }
124+ { currentIndex + 1 } / { displayBanners ? .length ?? 0 }
98125 </ Styled . NumericPagination >
99126 ) }
100127
101128 { ! isMobile && (
102129 < Styled . DotPagination >
103- { BANNERS . map ( ( _ , index ) => (
130+ { displayBanners ? .map ( ( _ , index ) => (
104131 < Styled . Dot key = { index } active = { currentIndex === index } />
105132 ) ) }
106133 </ Styled . DotPagination >
0 commit comments