From 6545b772ed37a7ee5bfa5b69346bdec2cda5a8a7 Mon Sep 17 00:00:00 2001 From: Kakabay <2kakabayashyrberdyew@gmail.com> Date: Wed, 4 Sep 2024 15:34:36 +0500 Subject: [PATCH] commit --- components/vote/ParticipantsList.tsx | 35 +++++++++------------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/components/vote/ParticipantsList.tsx b/components/vote/ParticipantsList.tsx index 276c384..a0c3a63 100644 --- a/components/vote/ParticipantsList.tsx +++ b/components/vote/ParticipantsList.tsx @@ -31,6 +31,8 @@ const ParticipantsList = ({ vote_id }: IParams) => { const [voteStatus, setVoteStatus] = useState(); const [winnersCount, setWinnersCount] = useState(0); + console.log(participantsData); + // States realted to web socket const [smsNumber, setSmsNumber] = useState(null); const [socket, setSocket] = useState(null); @@ -91,7 +93,7 @@ const ParticipantsList = ({ vote_id }: IParams) => { socket.onmessage = (event) => { try { - // console.log('Message received from WebSocket:', event.data); + console.log('Message received from WebSocket:', event.data); const message = JSON.parse(event.data); handleWebSocketMessage(message); } catch (error) { @@ -146,9 +148,7 @@ const ParticipantsList = ({ vote_id }: IParams) => { // Update the corresponding voting item const updatedItems = prevVotingItems.map((item, index) => - item.id === message.voting_item_id - ? { ...item, votes_count: item.votes_count + 10000 } - : item, + item.id === message.voting_item_id ? { ...item, votes_count: item.votes_count + 1 } : item, ); // Sort the updated items array by votes_count in descending order @@ -235,27 +235,14 @@ const ParticipantsList = ({ vote_id }: IParams) => { {participantsData && participantsData[0].votes_count > 0 ? (
{participantsData.map((participant, id) => - participant.votes_count === participantsData[0].votes_count && voteStatus ? ( - participant.url ? ( - - - - ) : ( + participant.votes_count === participantsData[0].votes_count ? ( + { smsNumber={data.data.sms_number} winner={true} /> - ) + ) : null, )}