From 0992d702d1d47bda4aa71cd29cdb4872f8b5e71d Mon Sep 17 00:00:00 2001 From: TheCommandCat Date: Tue, 31 Dec 2024 22:48:12 +0200 Subject: [PATCH 1/6] Created event for ScheduledTimeChanged and added snackbars based on that --- apps/backend/src/websocket/handlers/field.ts | 4 ++++ apps/backend/src/websocket/handlers/judging.ts | 3 +++ apps/frontend/pages/lems/field-manager.tsx | 7 ++++++- apps/frontend/pages/lems/judge-advisor.tsx | 7 ++++++- libs/types/src/lib/websocket.ts | 2 ++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/apps/backend/src/websocket/handlers/field.ts b/apps/backend/src/websocket/handlers/field.ts index cf171f41..f2bb7b82 100644 --- a/apps/backend/src/websocket/handlers/field.ts +++ b/apps/backend/src/websocket/handlers/field.ts @@ -220,8 +220,12 @@ export const handleUpdateMatchTeams = async ( }); callback({ ok: true }); + + const oldMatch = match; match = await db.getMatch({ _id: new ObjectId(matchId) }); namespace.to('field').emit('matchUpdated', match); + if (match.scheduledTime != oldMatch.scheduledTime) + namespace.to('field').emit('ScheduledTimeChanged'); }; export const handleUpdateMatchParticipant = async ( diff --git a/apps/backend/src/websocket/handlers/judging.ts b/apps/backend/src/websocket/handlers/judging.ts index 63fd361a..a3ee46bf 100644 --- a/apps/backend/src/websocket/handlers/judging.ts +++ b/apps/backend/src/websocket/handlers/judging.ts @@ -124,8 +124,11 @@ export const handleUpdateSessionTeam = async ( await db.updateSession({ _id: session._id }, { teamId: teamId ? new ObjectId(teamId) : null }); callback({ ok: true }); + const oldSession = { ...session }; session = await db.getSession({ _id: new ObjectId(sessionId) }); namespace.to('judging').emit('judgingSessionUpdated', session); + if (session.scheduledTime !== oldSession.scheduledTime) + namespace.to('judging').emit('ScheduledTimeChanged'); }; export const handleUpdateSession = async ( diff --git a/apps/frontend/pages/lems/field-manager.tsx b/apps/frontend/pages/lems/field-manager.tsx index ada8bb94..729d9ba8 100644 --- a/apps/frontend/pages/lems/field-manager.tsx +++ b/apps/frontend/pages/lems/field-manager.tsx @@ -90,6 +90,10 @@ const Page: NextPage = ({ if (newDivisionState) setDivisionState(newDivisionState); }; + const handleScheduleTimeChange = (match: WithId) => { + enqueueSnackbar('הלוז עודכן.', { variant: 'info' }); + }; + const { socket, connectionStatus } = useWebsocket( division._id.toString(), ['field', 'pit-admin', 'audience-display'], @@ -104,7 +108,8 @@ const Page: NextPage = ({ { name: 'judgingSessionStarted', handler: handleSessionEvent }, { name: 'judgingSessionCompleted', handler: handleSessionEvent }, { name: 'judgingSessionAborted', handler: handleSessionEvent }, - { name: 'judgingSessionUpdated', handler: handleSessionEvent } + { name: 'judgingSessionUpdated', handler: handleSessionEvent }, + { name: 'ScheduledTimeChanged', handler: handleScheduleTimeChange }, ] ); diff --git a/apps/frontend/pages/lems/judge-advisor.tsx b/apps/frontend/pages/lems/judge-advisor.tsx index aad94028..8d096488 100644 --- a/apps/frontend/pages/lems/judge-advisor.tsx +++ b/apps/frontend/pages/lems/judge-advisor.tsx @@ -130,6 +130,10 @@ const Page: NextPage = ({ }); }; + const handleScheduleTimeChange = () => { + enqueueSnackbar('הלוז עודכן.', { variant: 'info' }); + }; + const { socket, connectionStatus } = useWebsocket( division._id.toString(), ['judging', 'pit-admin', 'audience-display'], @@ -162,7 +166,8 @@ const Page: NextPage = ({ } }, { name: 'presentationUpdated', handler: setDivisionState }, - { name: 'leadJudgeCalled', handler: handleLeadJudgeCalled } + { name: 'leadJudgeCalled', handler: handleLeadJudgeCalled }, + { name: 'ScheduledTimeChanged', handler: handleScheduleTimeChange } ] ); diff --git a/libs/types/src/lib/websocket.ts b/libs/types/src/lib/websocket.ts index 7289395f..5225c424 100644 --- a/libs/types/src/lib/websocket.ts +++ b/libs/types/src/lib/websocket.ts @@ -79,6 +79,8 @@ export interface WSServerEmittedEvents { presentationUpdated: (divisionState: DivisionState) => void; awardsUpdated: (awards: Array>) => void; + + ScheduledTimeChanged: () => void; } export interface WSClientEmittedEvents { From d9e72c4065c321e299b5770938c15a600059cfac Mon Sep 17 00:00:00 2001 From: TheCommandCat Date: Wed, 1 Jan 2025 18:33:51 +0200 Subject: [PATCH 2/6] used spread operation to get value and not the object --- apps/backend/src/websocket/handlers/field.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/backend/src/websocket/handlers/field.ts b/apps/backend/src/websocket/handlers/field.ts index f2bb7b82..9d7972ad 100644 --- a/apps/backend/src/websocket/handlers/field.ts +++ b/apps/backend/src/websocket/handlers/field.ts @@ -221,7 +221,7 @@ export const handleUpdateMatchTeams = async ( callback({ ok: true }); - const oldMatch = match; + const oldMatch = {...match}; match = await db.getMatch({ _id: new ObjectId(matchId) }); namespace.to('field').emit('matchUpdated', match); if (match.scheduledTime != oldMatch.scheduledTime) From a7bfbc352f8e34c9ada951704902ca798160b833 Mon Sep 17 00:00:00 2001 From: TheCommandCat Date: Wed, 1 Jan 2025 20:28:50 +0200 Subject: [PATCH 3/6] split the ScheduledTimeChanged to seprateed events for judgingSession and matchParticipant --- apps/frontend/pages/lems/field-manager.tsx | 2 +- apps/frontend/pages/lems/judge-advisor.tsx | 2 +- libs/types/src/lib/websocket.ts | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/frontend/pages/lems/field-manager.tsx b/apps/frontend/pages/lems/field-manager.tsx index 729d9ba8..fd06b8ae 100644 --- a/apps/frontend/pages/lems/field-manager.tsx +++ b/apps/frontend/pages/lems/field-manager.tsx @@ -109,7 +109,7 @@ const Page: NextPage = ({ { name: 'judgingSessionCompleted', handler: handleSessionEvent }, { name: 'judgingSessionAborted', handler: handleSessionEvent }, { name: 'judgingSessionUpdated', handler: handleSessionEvent }, - { name: 'ScheduledTimeChanged', handler: handleScheduleTimeChange }, + { name: 'matchParticipantTeamUpdated', handler: handleScheduleTimeChange }, ] ); diff --git a/apps/frontend/pages/lems/judge-advisor.tsx b/apps/frontend/pages/lems/judge-advisor.tsx index 8d096488..91bd9bd9 100644 --- a/apps/frontend/pages/lems/judge-advisor.tsx +++ b/apps/frontend/pages/lems/judge-advisor.tsx @@ -167,7 +167,7 @@ const Page: NextPage = ({ }, { name: 'presentationUpdated', handler: setDivisionState }, { name: 'leadJudgeCalled', handler: handleLeadJudgeCalled }, - { name: 'ScheduledTimeChanged', handler: handleScheduleTimeChange } + { name: 'judgingSessionTeamUpdated', handler: handleScheduleTimeChange } ] ); diff --git a/libs/types/src/lib/websocket.ts b/libs/types/src/lib/websocket.ts index 5225c424..97da923e 100644 --- a/libs/types/src/lib/websocket.ts +++ b/libs/types/src/lib/websocket.ts @@ -80,7 +80,10 @@ export interface WSServerEmittedEvents { awardsUpdated: (awards: Array>) => void; - ScheduledTimeChanged: () => void; + matchParticipantTeamUpdated : (match: RobotGameMatch, participants: RobotGameMatchParticipant) => void; + + judgingSessionTeamUpdated : (session: JudgingSession) => void; + } export interface WSClientEmittedEvents { From 8c22d8405da11097373afc5e9c4e3d187b312cd5 Mon Sep 17 00:00:00 2001 From: TheCommandCat Date: Wed, 1 Jan 2025 20:32:26 +0200 Subject: [PATCH 4/6] Added info to field schedule update snackbar --- apps/backend/src/websocket/handlers/field.ts | 17 +++++++++++++---- apps/frontend/pages/lems/field-manager.tsx | 7 ++++--- apps/frontend/pages/lems/judge-advisor.tsx | 10 ++++++---- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/apps/backend/src/websocket/handlers/field.ts b/apps/backend/src/websocket/handlers/field.ts index 9d7972ad..f27f4126 100644 --- a/apps/backend/src/websocket/handlers/field.ts +++ b/apps/backend/src/websocket/handlers/field.ts @@ -204,11 +204,11 @@ export const handleUpdateMatchTeams = async ( } console.log(`🖊️ Updating teams for match ${matchId} in division ${divisionId}`); - + newTeams.forEach(async newTeam => { const participantIndex = match.participants.findIndex( p => p.tableId.toString() === newTeam.tableId - ); + ); await db.updateMatch( { _id: match._id }, { @@ -224,8 +224,17 @@ export const handleUpdateMatchTeams = async ( const oldMatch = {...match}; match = await db.getMatch({ _id: new ObjectId(matchId) }); namespace.to('field').emit('matchUpdated', match); - if (match.scheduledTime != oldMatch.scheduledTime) - namespace.to('field').emit('ScheduledTimeChanged'); + if (match.scheduledTime != oldMatch.scheduledTime) { + const updatedParticipants = match.participants.filter((participant, index) => { + const oldParticipant = oldMatch.participants[index]; + if (!participant.teamId || !oldParticipant.teamId) return false; + return participant.teamId.toString() !== oldParticipant.teamId.toString(); + }); + + updatedParticipants.forEach(participant => { + namespace.to('field').emit('matchParticipantTeamUpdated', match, participant); + }); + } }; export const handleUpdateMatchParticipant = async ( diff --git a/apps/frontend/pages/lems/field-manager.tsx b/apps/frontend/pages/lems/field-manager.tsx index fd06b8ae..c1d416b6 100644 --- a/apps/frontend/pages/lems/field-manager.tsx +++ b/apps/frontend/pages/lems/field-manager.tsx @@ -11,7 +11,8 @@ import { Team, DivisionWithEvent, JudgingSession, - JudgingRoom + JudgingRoom, + RobotGameMatchParticipant } from '@lems/types'; import Layout from '../../components/layout'; import { RoleAuthorizer } from '../../components/role-authorizer'; @@ -90,8 +91,8 @@ const Page: NextPage = ({ if (newDivisionState) setDivisionState(newDivisionState); }; - const handleScheduleTimeChange = (match: WithId) => { - enqueueSnackbar('הלוז עודכן.', { variant: 'info' }); + const handleScheduleTimeChange = (match: WithId, updatedParticipant: RobotGameMatchParticipant) => { + enqueueSnackbar(`קבוצה במקצה ${match.number} בשולחן ${updatedParticipant.tableName} עודכנה`, { variant: 'info' }); }; const { socket, connectionStatus } = useWebsocket( diff --git a/apps/frontend/pages/lems/judge-advisor.tsx b/apps/frontend/pages/lems/judge-advisor.tsx index 91bd9bd9..7da18b17 100644 --- a/apps/frontend/pages/lems/judge-advisor.tsx +++ b/apps/frontend/pages/lems/judge-advisor.tsx @@ -18,7 +18,9 @@ import { CoreValuesForm, DivisionState, JudgingDeliberation, - Award + Award, + RobotGameMatch, + RobotGameMatchParticipant } from '@lems/types'; import { RoleAuthorizer } from '../../components/role-authorizer'; import { getUserAndDivision, serverSideGetRequests } from '../../lib/utils/fetch'; @@ -130,9 +132,9 @@ const Page: NextPage = ({ }); }; - const handleScheduleTimeChange = () => { - enqueueSnackbar('הלוז עודכן.', { variant: 'info' }); - }; + const handleScheduleTimeChange = (match: WithId, updatedParticipant: RobotGameMatchParticipant) => { + enqueueSnackbar(`קבוצה במקצה ${match.number} בשולחן ${updatedParticipant.tableName} עודכנה`, { variant: 'info' }); + }; const { socket, connectionStatus } = useWebsocket( division._id.toString(), From ae4747f73900b7a4b5c65d43ae756b60cdf9cff4 Mon Sep 17 00:00:00 2001 From: TheCommandCat Date: Wed, 1 Jan 2025 20:33:04 +0200 Subject: [PATCH 5/6] removed unnecessary if statement --- apps/backend/src/websocket/handlers/judging.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/backend/src/websocket/handlers/judging.ts b/apps/backend/src/websocket/handlers/judging.ts index a3ee46bf..ca58fcfd 100644 --- a/apps/backend/src/websocket/handlers/judging.ts +++ b/apps/backend/src/websocket/handlers/judging.ts @@ -127,8 +127,7 @@ export const handleUpdateSessionTeam = async ( const oldSession = { ...session }; session = await db.getSession({ _id: new ObjectId(sessionId) }); namespace.to('judging').emit('judgingSessionUpdated', session); - if (session.scheduledTime !== oldSession.scheduledTime) - namespace.to('judging').emit('ScheduledTimeChanged'); + namespace.to('judging').emit('judgingSessionTeamUpdated', session); }; export const handleUpdateSession = async ( From bfaf2912644c0e0b704dd5a5413341643ae10214 Mon Sep 17 00:00:00 2001 From: TheCommandCat Date: Thu, 9 Jan 2025 19:06:44 +0200 Subject: [PATCH 6/6] fixed a mistake from the field code that been copied --- apps/frontend/pages/lems/judge-advisor.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/frontend/pages/lems/judge-advisor.tsx b/apps/frontend/pages/lems/judge-advisor.tsx index 7da18b17..1b13f3fd 100644 --- a/apps/frontend/pages/lems/judge-advisor.tsx +++ b/apps/frontend/pages/lems/judge-advisor.tsx @@ -34,6 +34,7 @@ import CVFormCard from '../../components/cv-form/cv-form-card'; import BadgeTab from '../../components/general/badge-tab'; import { localizeDivisionTitle } from '../../localization/event'; import { useQueryParam } from '../../hooks/use-query-param'; +import dayjs from 'dayjs'; interface Props { user: WithId; @@ -132,9 +133,15 @@ const Page: NextPage = ({ }); }; - const handleScheduleTimeChange = (match: WithId, updatedParticipant: RobotGameMatchParticipant) => { - enqueueSnackbar(`קבוצה במקצה ${match.number} בשולחן ${updatedParticipant.tableName} עודכנה`, { variant: 'info' }); - }; + const handleScheduleTimeChange = (session: WithId) => { + console.log('session', session); + enqueueSnackbar(`קבוצה בשיפוט בשעה ${dayjs(session.scheduledTime).format('HH:mm')} עודכנה`, { + variant: 'info' + }); + // enqueueSnackbar(`קבוצה בשיפוט בחדר ${session.roomId?} בשעה ${dayjs(session.scheduledTime).format('HH:mm')} עודכנה`, { + // variant: 'info' + // }); + }; const { socket, connectionStatus } = useWebsocket( division._id.toString(),