blob: b1023990fd19862a4ad52a601d888bf47cfeb1fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import Link from '@/core/components/elements/Link/Link'
import { getRandomInt } from '@/utils/getRandomInt'
import Image from 'next/image'
import { useMemo } from 'react'
import { useQuery } from 'react-query'
import { HeroBannerSkeleton } from '../skeleton/BannerSkeleton'
import { bannerApi } from '@/api/bannerApi'
const HeroBannerSecondary = () => {
const heroBannerSecondary = useQuery('heroBannerSecondary', bannerApi({ type: 'index-a-2' }))
const randomIndex = useMemo(() => {
if (!heroBannerSecondary.data) return null
const length = heroBannerSecondary.data?.length
return getRandomInt(length)
}, [heroBannerSecondary.data])
if (heroBannerSecondary.isLoading) return <HeroBannerSkeleton />
return (
heroBannerSecondary.data && (
<Link href={heroBannerSecondary.data[randomIndex].url} className='h-full'>
<Image
src={heroBannerSecondary.data[randomIndex].image}
width={512}
height={1024}
alt={heroBannerSecondary.data[randomIndex].name}
className='object-cover object-center h-full'
/>
</Link>
)
)
}
export default HeroBannerSecondary
|