diff --git a/src/components/sections/CampaignsSection.tsx b/src/components/sections/CampaignsSection.tsx new file mode 100644 index 0000000..0172fa4 --- /dev/null +++ b/src/components/sections/CampaignsSection.tsx @@ -0,0 +1,72 @@ +'use client' +import { useState, useEffect } from 'react'; +import { useVulaContent } from '@/hooks/useVulaContent' +import { Card, CardContent } from '@/components/ui/Card' +import Button from '@/components/ui/Button' +import Image from 'next/image' + +export default function CampaignsSection() { + const { items, loading } = useVulaContent('campaigns') + const [countdown, setCountdown] = useState('') + + // Compute countdown for first campaign with headline containing a date + useEffect(() => { + if (items.length === 0) return + const first = items[0] + const d = first.data as { headline?: string } + if (d.headline && /\d{4}-\d{2}-\d{2}/.test(d.headline)) { + const match = d.headline.match(/(\d{4}-\d{2}-\d{2})/) + const end = new Date(match![1]) + const timer = setInterval(() => { + const diff = end.getTime() - Date.now() + if (diff <= 0) { setCountdown('DROP LIVE'); clearInterval(timer); return } + const days = Math.floor(diff / (1000 * 60 * 60 * 24)) + const hrs = Math.floor((diff % 86400000) / 3600000) + setCountdown(`${days}d ${hrs}h`) + }, 60000) + return () => clearInterval(timer) + } + }, [items]) + + if (loading) return
{d.headline}
} + {d.body &&{d.body}
} + {d.cta_text && ( + + )} +