From 0a3066d3986051775269cabdc895717d9f8b2945 Mon Sep 17 00:00:00 2001 From: Kakabay <2kakabayashyrberdyew@gmail.com> Date: Wed, 11 Dec 2024 18:14:14 +0500 Subject: [PATCH] LotteryCountDown reafactored --- .../lottery/countDown/LotteryCountDown.tsx | 101 ++++++++---------- 1 file changed, 46 insertions(+), 55 deletions(-) diff --git a/components/lottery/countDown/LotteryCountDown.tsx b/components/lottery/countDown/LotteryCountDown.tsx index 22d1bf4..5c21de3 100644 --- a/components/lottery/countDown/LotteryCountDown.tsx +++ b/components/lottery/countDown/LotteryCountDown.tsx @@ -1,5 +1,6 @@ 'use client'; +import { calculateTimeLeft } from '@/lib/hooks/useCalculateTimeLeft'; import React, { useState, useEffect, Dispatch, SetStateAction } from 'react'; interface LotteryCountDownProps { @@ -21,22 +22,6 @@ const LotteryCountDown: React.FC = ({ seconds: 0, }); - const calculateTimeLeft = (targetDate: string) => { - const now = new Date(); - const eventDate = new Date(targetDate); // Parse target date directly - const timeDifference = eventDate.getTime() - now.getTime(); - - if (timeDifference <= 0) { - return { hours: 0, minutes: 0, seconds: 0 }; // Countdown finished - } - - const hours = Math.floor(timeDifference / (1000 * 60 * 60)); - const minutes = Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60)); - const seconds = Math.floor((timeDifference % (1000 * 60)) / 1000); - - return { hours, minutes, seconds }; - }; - useEffect(() => { const timer = setInterval(() => { if (lotteryStatus === 'not-started') { @@ -60,57 +45,63 @@ const LotteryCountDown: React.FC = ({ }, [startDate, endDate, lotteryStatus, setLotteryStatus]); return ( -
+
+

+ {lotteryStatus === 'started' + ? 'Bije dowam edýär' + : lotteryStatus === 'ended' + ? 'Bije tamamlandy' + : 'Bije'} +

{/* LotteryCountDown */} -
-
-

- {timeLeft.hours} -

-

- hours -

-
+ {lotteryStatus === 'not-started' && ( +
+
+

+ {timeLeft.hours} +

+

+ hours +

+
-
-
-
-
+
+
+
+
-
-

- {timeLeft.minutes} -

-

- minutes -

-
+
+

+ {timeLeft.minutes} +

+

+ minutes +

+
-
-
-
-
+
+
+
+
-
-

- {timeLeft.seconds} -

-

- seconds -

+
+

+ {timeLeft.seconds} +

+

+ seconds +

+
-
- - {/* Separator */} -
+ )}
{lotteryStatus === 'not-started' ? '- den başlar' : lotteryStatus === 'started' - ? '- den gutatar' - : 'gutardy'} + ? 'girmek üçin aşakda kodyňyzy giriziň' + : 'netijeleri görmek üçin aşakda kodyňyzy giriziň'}