"use client"; import { useWebsocketLottery } from "@/hooks/useWebSocketLottery"; import clsx from "clsx"; import { useEffect, useState } from "react"; interface IProps { show?: boolean; data?: any; } const WEBSOCKET_URL = "wss://sms.turkmentv.gov.tm/ws/lottery?dst="; const LotteryRulesSection = ({ show = true, data }: IProps) => { const [messageQueue, setMessageQueue] = useState([]); // Queue for incoming WebSocket messages const [isProcessing, setIsProcessing] = useState(false); // Track if a message is being processed const { subscribeToMessages } = useWebsocketLottery( `${WEBSOCKET_URL}${data?.data.sms_number}` ); const [totalParticipants, setTotalParticipants] = useState( data ? data?.data?.bije_count : 0 ); // Subscribe to WebSocket messages useEffect(() => { const unsubscribe = subscribeToMessages((event) => { // Add new message to the queue setMessageQueue((prevQueue) => { return [...prevQueue, JSON.parse(event.data)]; }); }); return () => unsubscribe(); }, [subscribeToMessages]); // Process queue when a new message is added useEffect(() => { if (!isProcessing && messageQueue.length > 0) { processQueue(); } }, [messageQueue, isProcessing]); // Process a single message from the queue const processQueue = async () => { if (isProcessing || messageQueue.length === 0) return; setIsProcessing(true); // Lock processing const message = messageQueue[0]; // Get the first message in the queue if (!message?.winner_no) { setTotalParticipants(totalParticipants + 1); } setMessageQueue((prevQueue) => prevQueue.slice(1)); // Remove the processed message from the queue setIsProcessing(false); // Unlock processing }; return (

Düzgünleri:

    {data?.data.rules?.map((item: any, i: number) => (
  • {item.title}
  • ))}

Gatnaşyjylaryň sany:

3 ? "text-[28px] sm:text-[56px] md:text-[80px]" : "text-[24px]" )} > {totalParticipants}

{show && (

Siziň bijeli sanyňyz:

    {data?.user_lottery_numbers.map((item: any, i: number) => (
  • {item}
  • ))}
)}
); }; export default LotteryRulesSection;