From 190dfb92caf0fc16b2e12853d2e787f4c336dd2d Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Fri, 24 Oct 2025 21:46:55 -0700 Subject: [PATCH] feat: add socket event for participant removal from queues --- app/routes/api/draft.force-autopick.ts | 10 ++++++++++ app/routes/api/draft.force-manual-pick.ts | 10 ++++++++++ app/routes/api/draft.make-pick.ts | 10 ++++++++++ app/routes/leagues/$leagueId.draft.$seasonId.tsx | 9 +++++++++ server/socket.ts | 1 + 5 files changed, 40 insertions(+) diff --git a/app/routes/api/draft.force-autopick.ts b/app/routes/api/draft.force-autopick.ts index 60f007d..20d8513 100644 --- a/app/routes/api/draft.force-autopick.ts +++ b/app/routes/api/draft.force-autopick.ts @@ -160,6 +160,16 @@ export async function action(args: any) { ) ); + // Notify all clients that this participant was removed from queues + try { + const io = (global as any).__socketIO; + io.to(`draft-${seasonId}`).emit("participant-removed-from-queues", { + participantId: participantToPick.id, + }); + } catch (error) { + console.error("Socket.IO participant-removed-from-queues error:", error); + } + // Emit socket event try { const io = (global as any).__socketIO; diff --git a/app/routes/api/draft.force-manual-pick.ts b/app/routes/api/draft.force-manual-pick.ts index 179906c..83ea7db 100644 --- a/app/routes/api/draft.force-manual-pick.ts +++ b/app/routes/api/draft.force-manual-pick.ts @@ -186,6 +186,16 @@ export async function action(args: any) { ) ); + // Notify all clients that this participant was removed from queues + try { + const io = (global as any).__socketIO; + io.to(`draft-${seasonId}`).emit("participant-removed-from-queues", { + participantId, + }); + } catch (error) { + console.error("Socket.IO participant-removed-from-queues error:", error); + } + // Emit socket event try { const io = (global as any).__socketIO; diff --git a/app/routes/api/draft.make-pick.ts b/app/routes/api/draft.make-pick.ts index 969d69f..ace8453 100644 --- a/app/routes/api/draft.make-pick.ts +++ b/app/routes/api/draft.make-pick.ts @@ -151,6 +151,16 @@ export async function action(args: any) { ) ); + // Notify all clients that this participant was removed from queues + try { + const io = (global as any).__socketIO; + io.to(`draft-${seasonId}`).emit("participant-removed-from-queues", { + participantId, + }); + } catch (error) { + console.error("Socket.IO participant-removed-from-queues error:", error); + } + // Add increment to the team that just picked const currentTimer = await db.query.draftTimers.findFirst({ where: and( diff --git a/app/routes/leagues/$leagueId.draft.$seasonId.tsx b/app/routes/leagues/$leagueId.draft.$seasonId.tsx index 3fc45b2..b6d081f 100644 --- a/app/routes/leagues/$leagueId.draft.$seasonId.tsx +++ b/app/routes/leagues/$leagueId.draft.$seasonId.tsx @@ -406,6 +406,13 @@ export default function DraftRoom() { setConnectedTeams(new Set(data.teamIds)); }; + const handleParticipantRemovedFromQueues = (data: { participantId: string }) => { + console.log("Participant removed from queues:", data.participantId); + setQueue((prev: any) => + prev.filter((item: any) => item.participantId !== data.participantId) + ); + }; + on("pick-made", handlePickMade); on("timer-update", handleTimerUpdate); on("draft-paused", handleDraftPaused); @@ -415,6 +422,7 @@ export default function DraftRoom() { on("team-connected", handleTeamConnected); on("team-disconnected", handleTeamDisconnected); on("connected-teams-list", handleConnectedTeamsList); + on("participant-removed-from-queues", handleParticipantRemovedFromQueues); return () => { off("pick-made", handlePickMade); @@ -426,6 +434,7 @@ export default function DraftRoom() { off("team-connected", handleTeamConnected); off("team-disconnected", handleTeamDisconnected); off("connected-teams-list", handleConnectedTeamsList); + off("participant-removed-from-queues", handleParticipantRemovedFromQueues); }; }, [on, off, currentPick, userTeam]); diff --git a/server/socket.ts b/server/socket.ts index b826450..8d8e197 100644 --- a/server/socket.ts +++ b/server/socket.ts @@ -28,6 +28,7 @@ interface ServerToClientEvents { "connected-teams-list": (data: { teamIds: string[] }) => void; "draft-paused": () => void; "draft-resumed": () => void; + "participant-removed-from-queues": (data: { participantId: string }) => void; } interface ClientToServerEvents {