'use client'; import { getStat } from '@/services/common/common'; import { LocationsIcon, ServersIcon, UsersIcon } from '@repo/ui/lotties'; import { useQuery } from '@tanstack/react-query'; import { motion } from 'framer-motion'; import { useTranslations } from 'next-intl'; import { useEffect, useState } from 'react'; export function Stats() { const t = useTranslations('index'); const { data } = useQuery({ queryKey: ['getStat'], queryFn: async () => { const { data } = await getStat({ skipErrorHandler: true, }); return data.data; }, refetchOnWindowFocus: false, }); const list = [ { name: t('users'), number: data?.user || 999, icon: , }, { name: t('servers'), number: data?.server || 30, icon: , }, { name: t('locations'), number: data?.country || 10, icon: , }, ]; return ( {list.map((item, index) => (
{item.icon}

+

{item.name}

))}
); } function CountUp({ end, duration = 2000 }: { end: number; duration?: number }) { const [count, setCount] = useState(0); useEffect(() => { let startTime; let animationFrame; const easeOutQuad = (t) => t * (2 - t); const updateCount = (timestamp) => { if (!startTime) startTime = timestamp; const progress = timestamp - startTime; const easedProgress = easeOutQuad(Math.min(progress / duration, 1)); const nextCount = Math.round(easedProgress * end); setCount(nextCount); if (progress < duration) { animationFrame = requestAnimationFrame(updateCount); } }; animationFrame = requestAnimationFrame(updateCount); return () => cancelAnimationFrame(animationFrame); }, [end, duration]); return <>{count.toLocaleString()}; }