truth component updated
This commit is contained in:
226
src/components/new_ui/truth.tsx
Normal file
226
src/components/new_ui/truth.tsx
Normal file
@@ -0,0 +1,226 @@
|
||||
import { Box, HStack, Image, Stack, Text, Link, Flex } from '@chakra-ui/react'
|
||||
import { motion, useInView } from 'framer-motion'
|
||||
import { colors } from '../../colors';
|
||||
import { useEffect, useRef } from 'react';
|
||||
const truthItems = [
|
||||
|
||||
{
|
||||
id: 1,
|
||||
image: '/images/new/ans_step1.webp',
|
||||
desc: '**出街食飯死亡率大增近五成!**即睇營養師拆解「油」之迷思。'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
image: '/images/new/ans_step2.webp',
|
||||
desc: '**三高年輕化警號!**營養師揭港人隱形致肥陷阱!一支好油決定血管命運。'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
image: '/images/new/ans_step3.webp',
|
||||
desc: '**三高人士同樣啱食!**營養師教你自製健康手撕蔥油雞髀。'
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
image: '/images/new/ans_step4.webp',
|
||||
desc: '**BBC認證豬油是健康食材?**混合食油等於垃圾油?純正食油一定最好? 各種食油迷思可能正在誤導你,由營養學家為你拆解多數人不知道的真相!'
|
||||
},
|
||||
]
|
||||
|
||||
const renderDescription = (text: string) => {
|
||||
const parts = text.split(/(\*\*.*?\*\*)/)
|
||||
|
||||
return parts.map((part, index) => {
|
||||
if (part.startsWith('**') && part.endsWith('**')) {
|
||||
return (
|
||||
<Text as="span" key={index} fontWeight={800}>
|
||||
{part.slice(2, -2)}
|
||||
</Text>
|
||||
)
|
||||
}
|
||||
return <Text as="span" key={index}>{part}</Text>
|
||||
})
|
||||
}
|
||||
|
||||
function Truth() {
|
||||
|
||||
const shopImages = [
|
||||
{
|
||||
image: '/images/pp.webp',
|
||||
link: 'https://www.pns.hk/en/all-brands/b/112546/lion-globe',
|
||||
},
|
||||
{
|
||||
image: '/images/we.webp',
|
||||
link: 'https://www.wellcome.com.hk/zh-hant/search?keyword=%E7%8D%85%E7%90%83%E5%98%9C&page=1',
|
||||
},
|
||||
{
|
||||
image: '/images/hk.webp',
|
||||
link: 'https://www.hktvmall.com/hktv/zh/main/%E7%8D%85%E7%90%83%E5%98%9C%E6%97%97%E8%89%A6%E5%BA%97/s/H1261001',
|
||||
},
|
||||
]
|
||||
|
||||
const fbContainerRef = useRef<HTMLDivElement>(null);
|
||||
const titleRef = useRef<HTMLDivElement>(null);
|
||||
const isTitleInView = useInView(titleRef, { once: true });
|
||||
|
||||
|
||||
// Load Facebook SDK and initialize the plugin
|
||||
useEffect(() => {
|
||||
// Add Facebook SDK if it doesn't exist
|
||||
if (!document.getElementById('facebook-jssdk')) {
|
||||
const script = document.createElement('script');
|
||||
script.id = 'facebook-jssdk';
|
||||
script.src = 'https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v18.0';
|
||||
script.async = true;
|
||||
script.defer = true;
|
||||
document.body.appendChild(script);
|
||||
}
|
||||
|
||||
// Parse XFBML when SDK is loaded
|
||||
const handleSDKLoad = () => {
|
||||
if ((window as any).FB && fbContainerRef.current) {
|
||||
(window as any).FB.XFBML.parse(fbContainerRef.current);
|
||||
}
|
||||
};
|
||||
|
||||
// Check if FB is already loaded
|
||||
if ((window as any).FB) {
|
||||
handleSDKLoad();
|
||||
} else {
|
||||
// Listen for SDK load
|
||||
(window as any).fbAsyncInit = handleSDKLoad;
|
||||
}
|
||||
|
||||
return () => {
|
||||
// Clean up
|
||||
(window as any).fbAsyncInit = undefined;
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<Box
|
||||
position="relative"
|
||||
w="100%"
|
||||
bgColor="white"
|
||||
zIndex={3}
|
||||
overflow="hidden"
|
||||
justifyItems={'center'}
|
||||
>
|
||||
|
||||
<Text
|
||||
className='font-melle font-xbold'
|
||||
color='#458B02'
|
||||
mt={{ base: 10, sm: 10, md: 10, lg: 10, xl: 10 }}
|
||||
fontSize={{ base: '2xl', sm: '3xl', md: '5xl', lg: '5xl', xl: '5xl' }}
|
||||
textAlign={'center'}>
|
||||
想知道更多食用油健康真相?
|
||||
</Text>
|
||||
|
||||
<Stack
|
||||
mt={{ base: 3, sm: -5, md: -5, lg: -5, xl: -5 }}
|
||||
columns={{ base: 1, sm: 1, md: 2 }}
|
||||
p={{ base: 5, sm: 12, md: 20 }}
|
||||
w={{ base: '100%', sm: '100%', md: '80%', lg: '80%', xl: '60%' }}
|
||||
h={'auto'}
|
||||
gap={{ base: 7, md: 7 }}
|
||||
justifyItems={'center'}
|
||||
alignItems={'flex-start'}
|
||||
>
|
||||
{truthItems.map((item) => (
|
||||
<HStack
|
||||
gap={{ base: 4, md: 5 }}
|
||||
justifyItems={'flex-start'}
|
||||
alignItems={'flex-start'}>
|
||||
<Image
|
||||
src={item.image}
|
||||
alt={`truth item ${item.id}`}
|
||||
w={{ base: '70px', sm: '70px', md: '70px', lg: '70px', xl: '70px' }}
|
||||
/>
|
||||
<Text
|
||||
className="font-noto-sans font-regular"
|
||||
color='#458B02'
|
||||
fontSize={{ base: 'lg', sm: 'lg', md: 'lg', lg: 'lg', xl: 'lg' }}
|
||||
>
|
||||
{renderDescription(item.desc)}
|
||||
</Text>
|
||||
|
||||
</HStack>
|
||||
|
||||
))}
|
||||
</Stack>
|
||||
<motion.div
|
||||
ref={titleRef}
|
||||
initial={{ opacity: 0, y: 50 }}
|
||||
animate={isTitleInView ? { opacity: 1, y: 0 } : { opacity: 0, y: 50 }}
|
||||
transition={{ duration: 0.7 }}
|
||||
>
|
||||
<Stack
|
||||
w='100%'
|
||||
justify={'center'}
|
||||
align={'center'}
|
||||
>
|
||||
<Text
|
||||
className='font-melle font-xbold'
|
||||
color={"#458B02"}
|
||||
fontSize={{ base: '2xl', sm: '3xl', md: '5xl', lg: '5xl', xl: '5xl' }}
|
||||
>
|
||||
點擊以下銷售點連結
|
||||
</Text>
|
||||
</Stack>
|
||||
</motion.div>
|
||||
|
||||
<Flex
|
||||
gap={12}
|
||||
direction={{ base: 'column', sm: 'column', md: 'row' }}
|
||||
justify="center"
|
||||
mt={5}
|
||||
align={'flex-end'}
|
||||
|
||||
>
|
||||
{shopImages.map((image, index) => (
|
||||
<motion.div
|
||||
key={index}
|
||||
initial={{ opacity: 0, y: 30 }}
|
||||
whileInView={{ opacity: 1, y: 0 }}
|
||||
viewport={{ once: true }}
|
||||
transition={{ duration: 0.5, delay: index * 0.2 }}
|
||||
>
|
||||
<Stack
|
||||
w='250px'
|
||||
justify={'flex-end'}
|
||||
>
|
||||
<Link href={image.link}>
|
||||
<Image src={image.image} cursor="pointer" fit={'contain'}
|
||||
loading="lazy" />
|
||||
</Link>
|
||||
</Stack>
|
||||
</motion.div>
|
||||
))}
|
||||
</Flex>
|
||||
|
||||
|
||||
<Stack
|
||||
my={15}
|
||||
ml={2}
|
||||
mt={10}
|
||||
>
|
||||
<Link href={"https://www.facebook.com/profile.php?id=100064320806613"}
|
||||
_focus={{ outline: 'none', boxShadow: 'none' }}
|
||||
_active={{ outline: 'none', boxShadow: 'none' }}>
|
||||
<Image
|
||||
src={'/images/facebook.webp'}
|
||||
alt="salespoint"
|
||||
w={"400px"}
|
||||
loading='lazy'
|
||||
/>
|
||||
</Link>
|
||||
</Stack>
|
||||
|
||||
</Box>
|
||||
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
export default Truth;
|
||||
@@ -5,6 +5,7 @@ import Wraning from '@/components/new_ui/wraning'
|
||||
import Info from '@/components/new_ui/info'
|
||||
import Advantages from '@/components/new_ui/advantages'
|
||||
import OilInfo from '@/components/new_ui/oilInfo'
|
||||
import Truth from '@/components/new_ui/truth'
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +19,7 @@ function MainPage() {
|
||||
<Info />
|
||||
<Advantages />
|
||||
<OilInfo />
|
||||
<Truth />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user