From 6f92f2192fbe2a0479d364db41d79c81010a9291 Mon Sep 17 00:00:00 2001 From: Kakabay <2kakabayashyrberdyew@gmail.com> Date: Wed, 18 Dec 2024 18:30:13 +0500 Subject: [PATCH] counter started --- app/(main)/lottery/active/page.tsx | 17 +++-- app/globals.css | 4 ++ .../lottery/RollingCounter/RollingCounter.tsx | 70 +++++++++++++++++++ 3 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 components/lottery/RollingCounter/RollingCounter.tsx diff --git a/app/(main)/lottery/active/page.tsx b/app/(main)/lottery/active/page.tsx index 7e37220..81e0be2 100644 --- a/app/(main)/lottery/active/page.tsx +++ b/app/(main)/lottery/active/page.tsx @@ -3,6 +3,7 @@ import { Queries } from '@/api/queries'; import Loader from '@/components/Loader'; import LotteryWinnersSection from '@/components/lottery/LotteryWinnersSection'; +import RollingCounter from '@/components/lottery/RollingCounter/RollingCounter'; import LotteryCountDown from '@/components/lottery/countDown/LotteryCountDown'; import LotteryCountDownAllert from '@/components/lottery/countDown/countDownAllert/LotteryCountDownAllert'; import LotteryForm from '@/components/lottery/form/LotteryForm'; @@ -26,16 +27,18 @@ const page = () => { .finally(() => setIsLoading(false)); }, []); - if (isLoading) { - return ( -
- -
- ); - } + // if (isLoading) { + // return ( + //
+ // + //
+ // ); + // } return (
+ + {data && (
diff --git a/app/globals.css b/app/globals.css index 9cb0ba6..4a60b39 100644 --- a/app/globals.css +++ b/app/globals.css @@ -252,6 +252,10 @@ big { @apply font-roboto text-[60px] leading-[70px] -tracking-[1%]; } +.numeric-display-1 { + @apply text-[80px] leading-[88px] -tracking-[1%] text-center font-normal font-roboto; +} + .wheel-circle { background: url('/wheel-circle.svg'); background-position: center; diff --git a/components/lottery/RollingCounter/RollingCounter.tsx b/components/lottery/RollingCounter/RollingCounter.tsx new file mode 100644 index 0000000..79b5e24 --- /dev/null +++ b/components/lottery/RollingCounter/RollingCounter.tsx @@ -0,0 +1,70 @@ +'use client'; +import { motion } from 'framer-motion'; +import { useEffect, useState } from 'react'; + +interface RollingCounterProps { + numberString: string; // A 10-character string, e.g., "05-12-34-56-78" +} + +const RollingCounter: React.FC = ({ numberString }) => { + const [rollingValues, setRollingValues] = useState([]); + const [isStopped, setIsStopped] = useState([]); // Track stopped numbers + + useEffect(() => { + // Parse input string into an array of numbers, removing hyphens + const targetNumbers = numberString + .replace(/-/g, '') + .split('') + .map((char) => parseInt(char, 10)); + setRollingValues(targetNumbers); + setIsStopped(new Array(targetNumbers.length).fill(false)); + }, [numberString]); + + const getNumbers = () => Array.from({ length: 10 }, (_, i) => i); + + return ( +
+ {rollingValues.map((targetValue, index) => ( +
+ {/* Container to display numbers */} +
+ { + // Mark this number as stopped + setIsStopped((prev) => { + const newStatus = [...prev]; + newStatus[index] = true; + return newStatus; + }); + }} + className="absolute top-1/2 -translate-y-1/2 flex flex-col -mt-[52px]"> + {getNumbers().map((num) => ( +
+ {num} +
+ ))} +
+
+ {/* Add a hyphen every two digits */} + {(index + 1) % 2 === 0 && index !== rollingValues.length - 1 && ( +
+ )} +
+ ))} +
+ ); +}; + +export default RollingCounter;