diff --git a/components/common/Confetti.tsx b/components/common/Confetti.tsx index 431f436..39ce9d0 100644 --- a/components/common/Confetti.tsx +++ b/components/common/Confetti.tsx @@ -3,7 +3,13 @@ import ReactConfetti from 'react-confetti'; import { useWindowSize } from 'react-use'; -const Confetti = () => { +const Confetti = ({ + infinite = true, + numberOfPieces = 200, +}: { + infinite?: boolean; + numberOfPieces?: number; +}) => { const { width, height } = useWindowSize(); const colors = [ 'linear-gradient(45deg, #5D5D72, #8589DE)', @@ -19,9 +25,9 @@ const Confetti = () => { diff --git a/components/lottery/LotteryWinnersSection.tsx b/components/lottery/LotteryWinnersSection.tsx index cb161bf..abb660e 100644 --- a/components/lottery/LotteryWinnersSection.tsx +++ b/components/lottery/LotteryWinnersSection.tsx @@ -1,21 +1,18 @@ -import { useState, useEffect } from "react"; -import { useLotteryAuth } from "@/store/useLotteryAuth"; -import { LotteryWinnerDataSimplified } from "@/typings/lottery/lottery.types"; -import LotteryWinnersList from "./winners/LotteryWinnersList"; -import LotterySlotCounter from "./slotCounter/LotterySlotCounter"; -import ReactConfetti from "react-confetti"; -import { useWindowSize } from "react-use"; -import AnimatedText from "@/components/common/AnimatedText"; -import { useWebsocketLottery } from "@/hooks/useWebSocketLottery"; +import { useState, useEffect } from 'react'; +import { useLotteryAuth } from '@/store/useLotteryAuth'; +import { LotteryWinnerDataSimplified } from '@/typings/lottery/lottery.types'; +import LotteryWinnersList from './winners/LotteryWinnersList'; +import LotterySlotCounter from './slotCounter/LotterySlotCounter'; +import ReactConfetti from 'react-confetti'; +import { useWindowSize } from 'react-use'; +import AnimatedText from '@/components/common/AnimatedText'; +import { useWebsocketLottery } from '@/hooks/useWebSocketLottery'; +import Confetti from '../common/Confetti'; -const WEBSOCKET_URL = "wss://sms.turkmentv.gov.tm/ws/lottery?dst=0506"; -const SLOT_COUNTER_DURATION = 20000; +const WEBSOCKET_URL = 'wss://sms.turkmentv.gov.tm/ws/lottery?dst=0506'; +const SLOT_COUNTER_DURATION = 100000; -const LotteryWinnersSection = ({ - lotteryStatus, -}: { - lotteryStatus: string; -}) => { +const LotteryWinnersSection = ({ lotteryStatus }: { lotteryStatus: string }) => { const [winners, setWinners] = useState([]); const [currentNumber, setCurrentNumber] = useState(); const [isConfettiActive, setIsConfettiActive] = useState(false); @@ -23,40 +20,39 @@ const LotteryWinnersSection = ({ const { width, height } = useWindowSize(); const { lotteryData } = useLotteryAuth(); const [winnerSelectingStatus, setWinnerSelectingStatus] = useState< - "not-selected" | "is-selecting" | "selected" - >("not-selected"); - const [pendingWinner, setPendingWinner] = - useState(null); - const [displayText, setDisplayText] = useState("..."); - const [winnerText, setWinnerText] = useState(""); + 'not-selected' | 'is-selecting' | 'selected' + >('not-selected'); + const [pendingWinner, setPendingWinner] = useState(null); + const [topText, setTopText] = useState('Ýeňiji saýlanmady'); + const [bottomText, setBottomText] = useState(''); // WebSocket Hook const { wsStatus, subscribeToMessages } = useWebsocketLottery(WEBSOCKET_URL); + console.log(winners); + useEffect(() => { - if (lotteryData?.data.winners) { - const simplifiedWinners = lotteryData.data.winners.map((winner) => ({ - client: winner.client, - winner_no: winner.winner_no, - ticket: winner.ticket, - })); - setWinners(simplifiedWinners); - setCurrentNumber( - lotteryData.data.winners.at(-1)?.ticket || "00-00-00-00-00" - ); + if (lotteryData) { + if (lotteryData?.data.winners.length > 0) { + const simplifiedWinners = lotteryData.data.winners.map((winner) => ({ + client: winner.client, + winner_no: winner.winner_no, + ticket: winner.ticket, + })); + setWinners(simplifiedWinners); + setCurrentNumber(lotteryData.data.winners.at(-1)?.ticket || '00-00-00-00-00'); + setWinnerSelectingStatus('selected'); + setTopText('Ýeniji'); + setBottomText(lotteryData.data.winners.at(-1)?.client || ''); + } } }, [lotteryData]); useEffect(() => { const unsubscribe = subscribeToMessages((event) => { const newWinner = JSON.parse(event.data); - if ( - !newWinner || - !newWinner.phone || - !newWinner.winner_no || - !newWinner.ticket - ) { - console.error("❌ Invalid data format received"); + if (!newWinner || !newWinner.phone || !newWinner.winner_no || !newWinner.ticket) { + console.error('❌ Invalid data format received'); return; } @@ -66,26 +62,23 @@ const LotteryWinnersSection = ({ ticket: newWinner.ticket, }; - setDisplayText(`${winnerData.winner_no}-nji ýeňiji saýlanýar`); - setWinnerSelectingStatus("is-selecting"); + setTopText(`${winnerData.winner_no}-nji(y) ýeňiji saýlanýar`); + setBottomText('...'); + setWinnerSelectingStatus('is-selecting'); setPendingWinner(winnerData); setCurrentNumber(winnerData.ticket); setTimeout(() => { - setDisplayText("The winner is"); - setWinnerText(winnerData.client); - setWinnerSelectingStatus("selected"); + setTopText('Ýeniji'); + setBottomText(winnerData.client); + setWinnerSelectingStatus('selected'); setIsConfettiActive(true); setWinners((prev) => [...prev, winnerData]); - }, SLOT_COUNTER_DURATION); - - setTimeout(() => { - setIsConfettiActive(false); - setWinnerSelectingStatus("not-selected"); - setPendingWinner(null); - setDisplayText("..."); - setWinnerText(""); - }, 10000); + setTimeout(() => { + setIsConfettiActive(false); + // setPendingWinner(null); + }, 5000); + }, SLOT_COUNTER_DURATION + 500); }); return () => { @@ -95,46 +88,31 @@ const LotteryWinnersSection = ({ return (
- {wsStatus === "error" && ( -
- Websocket connection error. -
- )} - {isConfettiActive && ( -
- -
+ {wsStatus === 'error' && ( +
Websocket connection error.
)} + {isConfettiActive && }
+ background: 'linear-gradient(180deg, #F0ECF4 0%, #E1E0FF 43.5%)', + }}>
- {winnerSelectingStatus === "not-selected" || - winnerSelectingStatus === "is-selecting" ? ( + {winnerSelectingStatus === 'not-selected' ? ( ) : (
- {winnerText && ( + {bottomText && ( )} @@ -143,10 +121,7 @@ const LotteryWinnersSection = ({
{currentNumber && ( - + )}
diff --git a/components/lottery/rules/LotteryRulesSection.tsx b/components/lottery/rules/LotteryRulesSection.tsx index d9c699c..ee53d69 100644 --- a/components/lottery/rules/LotteryRulesSection.tsx +++ b/components/lottery/rules/LotteryRulesSection.tsx @@ -1,4 +1,4 @@ -import { useLotteryAuth } from "@/store/useLotteryAuth"; +import { useLotteryAuth } from '@/store/useLotteryAuth'; const LotteryRulesSection = () => { const { lotteryData } = useLotteryAuth(); @@ -8,7 +8,7 @@ const LotteryRulesSection = () => {

- Lotereýanyň duzgunleri: + Bijäniň düzgünleri:

@@ -18,7 +18,7 @@ const LotteryRulesSection = () => {
    {Array(5) - .fill(" ") + .fill(' ') .map((item, i) => (
  • Ilkinji we dogry jogap beren sanawda ilkinji ýeri eýelýär @@ -29,7 +29,7 @@ const LotteryRulesSection = () => {

    - Üns beriň: + Siziň açar sözleriňiz:

      {lotteryData?.user_lottery_numbers.map((item, i) => ( diff --git a/components/lottery/slotCounter/LotterySlotCounter.tsx b/components/lottery/slotCounter/LotterySlotCounter.tsx index 8a0db83..54e032a 100644 --- a/components/lottery/slotCounter/LotterySlotCounter.tsx +++ b/components/lottery/slotCounter/LotterySlotCounter.tsx @@ -1,27 +1,24 @@ -"use client"; -import Image from "next/image"; -import React, { useEffect, useState } from "react"; -import SlotCounter from "react-slot-counter"; -import { useMediaQuery } from "usehooks-ts"; +'use client'; +import Image from 'next/image'; +import React, { useEffect, useState } from 'react'; +import SlotCounter from 'react-slot-counter'; +import { useMediaQuery } from 'usehooks-ts'; interface LotterySlotCounterProps { numberString: string; isAnimating: boolean; } -const LotterySlotCounter = ({ - numberString, - isAnimating, -}: LotterySlotCounterProps) => { +const LotterySlotCounter = ({ numberString, isAnimating }: LotterySlotCounterProps) => { const [formattedNumber, setFormattedNumber] = useState(numberString); useEffect(() => { - const formatted = numberString.replace(/-/g, ","); + const formatted = numberString.replace(/-/g, ','); setFormattedNumber(formatted); }, [numberString]); - const tablet = useMediaQuery("(max-width: 769px)"); - const mobile = useMediaQuery("(max-width: 426px)"); + const tablet = useMediaQuery('(max-width: 769px)'); + const mobile = useMediaQuery('(max-width: 426px)'); return (
      @@ -65,18 +62,16 @@ const LotterySlotCounter = ({ className="flex items-center h-fit md:max-w-[1132px] sm:max-w-[640px] max-w-[324px] w-full justify-center text-white md:py-4 md:px-6 rounded-full overflow-y-hidden overflow-x-visible relative border-4 border-lightPrimary" style={{ background: - "linear-gradient(180deg, #454673 0%, #575992 10.5%, #575992 90%, #454673 100%)", - boxShadow: "0px 4px 4px 0px #00000040", - }} - > + 'linear-gradient(180deg, #454673 0%, #575992 10.5%, #575992 90%, #454673 100%)', + boxShadow: '0px 4px 4px 0px #00000040', + }}> {/* Highlight */}
      + 'linear-gradient(180deg, rgba(87, 89, 146, 0) 0%, #7274AB 50%, rgba(87, 89, 146, 0) 100%)', + }}>
      { animate={{ opacity: 1, translateY: 0 }} exit={{ opacity: 0, translateY: -20 }} transition={{ duration: 0.5 }} - className="flex flex-col gap-2 md:pb-4 pb-3 border-b w-full border-[#CECCFF]" - > + className="flex flex-col gap-2 md:pb-4 pb-3 border-b w-full border-[#CECCFF]">

      - The winner of the {winnerNumber} stage: + {/* The winner of the {winnerNumber} stage: */} + {winnerNumber} + {' - nji(y) ýeňiji'}

      {phone}

      diff --git a/components/lottery/winners/LotteryWinnersList.tsx b/components/lottery/winners/LotteryWinnersList.tsx index f1e1fef..ea0c57f 100644 --- a/components/lottery/winners/LotteryWinnersList.tsx +++ b/components/lottery/winners/LotteryWinnersList.tsx @@ -7,7 +7,7 @@ const LotteryWinnersList = ({ winners }: { winners: LotteryWinnerDataSimplified[ return (
      -

      Results

      +

      Ýeňijiler

      The results after each stage will be shown here.