diff --git a/components/lottery/LotteryWinnersSection.tsx b/components/lottery/LotteryWinnersSection.tsx index af1ceea..1f08572 100644 --- a/components/lottery/LotteryWinnersSection.tsx +++ b/components/lottery/LotteryWinnersSection.tsx @@ -1,23 +1,52 @@ -'use client'; +"use client"; -import LotteryWinnersList from './winners/LotteryWinnersList'; -import SpinWheel from './spinWheel/SpinWheel'; -import { useState } from 'react'; +import LotteryWinnersList from "./winners/LotteryWinnersList"; +import SpinWheel from "./spinWheel/SpinWheel"; +import { useState, useEffect } from "react"; +import RollingCounterWorking from "./RollingCounter/RollingCounterWorking"; +import { useLotteryAuth } from "@/store/useLotteryAuth"; +import { LotteryWinnerData } from "@/typings/lottery/lottery.types"; const LotteryWinnersSection = () => { - const [winners, setWinners] = useState([1]); + const [winners, setWinners] = useState([]); + + const { lotteryData } = useLotteryAuth(); + + useEffect(() => { + if (lotteryData?.data.winners) { + setWinners(lotteryData.data.winners); + } + + const wsUrl = "https://sms.turkmentv.gov.tm/api/ws/lottery"; + const ws = new WebSocket(wsUrl); + + ws.onmessage = (event) => { + console.log("WebSocket message received:", event.data); + const newWinner = JSON.parse(event.data); + console.log("Parsed WebSocket data:", newWinner); + setWinners((prev) => [...prev, newWinner]); + }; + + return () => { + ws.close(); + }; + }, [lotteryData]); return (
-
- {/* Winners */} - +
+
+ {/* Winners */} + - {/* Sping the wheel */} -
- + {/* Sping the wheel */} +
+ {/* */} +
+ +