blob: a7b32a4aa58ab5b875ab3c477c300d7a60a6fee2 (
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
36
37
38
39
|
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 && randomIndex !== null && (
<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"
loading="lazy"
placeholder="blur"
blurDataURL="/images/indoteknik-placeholder.png"
sizes="(max-width: 768px) 100vw, 50vw"
/>
</Link>
)
);
}
export default HeroBannerSecondary
|