Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created event for ScheduledTimeChanged and added snackbars based on that #897

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
23 changes: 18 additions & 5 deletions apps/backend/src/websocket/handlers/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ export const handleUpdateMatchTeams = async (
callback({ ok: false, error: `Match ${matchId} is not editable!` });
return;
}

console.log(`🖊️ Updating teams for match ${matchId} in division ${divisionId}`);

console.log(`🖊️ Updating teams for match ${matchId} in division ${divisionId}`);

for (const newTeam of newTeams) {
const participantIndex = match.participants.findIndex(
for (const newTeam of newTeams) {
const participantIndex = match.participants.findIndex(
p => p.tableId.toString() === newTeam.tableId
);
);
await db.updateMatch(
{ _id: match._id },
{
Expand All @@ -220,8 +220,21 @@ 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) {
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 handleSwitchMatchTeams = async (
Expand Down
2 changes: 2 additions & 0 deletions apps/backend/src/websocket/handlers/judging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ 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);
namespace.to('judging').emit('judgingSessionTeamUpdated', session);
};

export const handleUpdateSession = async (
Expand Down
8 changes: 7 additions & 1 deletion apps/frontend/pages/lems/field-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Team,
DivisionWithEvent,
JudgingSession,
JudgingRoom,
RobotGameMatchParticipant
} from '@lems/types';
import Layout from '../../components/layout';
Expand Down Expand Up @@ -89,6 +90,10 @@ const Page: NextPage<Props> = ({
if (newDivisionState) setDivisionState(newDivisionState);
};

const handleScheduleTimeChange = (match: WithId<RobotGameMatch>, updatedParticipant: RobotGameMatchParticipant) => {
enqueueSnackbar(`קבוצה במקצה ${match.number} בשולחן ${updatedParticipant.tableName} עודכנה`, { variant: 'info' });
};

const { socket, connectionStatus } = useWebsocket(
division._id.toString(),
['field', 'judging', 'pit-admin', 'audience-display'],
Expand All @@ -103,7 +108,8 @@ const Page: NextPage<Props> = ({
{ name: 'judgingSessionStarted', handler: handleSessionEvent },
{ name: 'judgingSessionCompleted', handler: handleSessionEvent },
{ name: 'judgingSessionAborted', handler: handleSessionEvent },
{ name: 'judgingSessionUpdated', handler: handleSessionEvent }
{ name: 'judgingSessionUpdated', handler: handleSessionEvent },
{ name: 'matchParticipantTeamUpdated', handler: handleScheduleTimeChange },
]
);

Expand Down
18 changes: 16 additions & 2 deletions apps/frontend/pages/lems/judge-advisor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -32,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<SafeUser>;
Expand Down Expand Up @@ -130,6 +133,16 @@ const Page: NextPage<Props> = ({
});
};

const handleScheduleTimeChange = (session: WithId<JudgingSession>) => {
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(),
['judging', 'pit-admin', 'audience-display'],
Expand Down Expand Up @@ -164,7 +177,8 @@ const Page: NextPage<Props> = ({
}
},
{ name: 'presentationUpdated', handler: setDivisionState },
{ name: 'leadJudgeCalled', handler: handleLeadJudgeCalled }
{ name: 'leadJudgeCalled', handler: handleLeadJudgeCalled },
{ name: 'judgingSessionTeamUpdated', handler: handleScheduleTimeChange }
]
);

Expand Down
5 changes: 5 additions & 0 deletions libs/types/src/lib/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export interface WSServerEmittedEvents {
presentationUpdated: (divisionState: DivisionState) => void;

awardsUpdated: (awards: Array<WithId<Award>>) => void;

matchParticipantTeamUpdated : (match: RobotGameMatch, participants: RobotGameMatchParticipant) => void;

judgingSessionTeamUpdated : (session: JudgingSession) => void;

}

export interface WSClientEmittedEvents {
Expand Down