Skip to content

Commit

Permalink
Merge pull request stakwork#718 from MahtabBukhari/Update-the-onmessa…
Browse files Browse the repository at this point in the history
…ge-on-Phase-planner-to-process

Update the 'onmessage' on Phase planner to process an update of the ticket store with the latest ticket details
  • Loading branch information
humansinstitute authored Dec 5, 2024
2 parents 429341a + ff63cd1 commit 1b7a610
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/people/widgetViews/PhasePlannerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ const PhasePlannerView: React.FC = () => {
console.log('Socket connected in Phase Planner');
};

const refreshSingleTicket = async (ticketUuid: string) => {
try {
const ticket = await main.getTicketDetails(ticketUuid);

phaseTicketStore.updateTicket(ticket.uuid, ticket);
} catch (error) {
console.error('Error on refreshing ticket:', error);
}
};

socket.onmessage = (event: MessageEvent) => {
try {
const data = JSON.parse(event.data);
Expand All @@ -71,14 +81,21 @@ const PhasePlannerView: React.FC = () => {
}

const ticketMessage = data as TicketMessage;
if (ticketMessage.action === 'message') {
console.log('Received ticket message:', ticketMessage.message);
console.log('Ticket details:', {
broadcastType: ticketMessage.broadcastType,
sourceSessionID: ticketMessage.sourceSessionID,
action: ticketMessage.action,
ticketDetails: ticketMessage.ticketDetails
});
switch (ticketMessage.action) {
case 'message':
console.log('Received ticket message:', ticketMessage.message);
console.log('Ticket details:', {
broadcastType: ticketMessage.broadcastType,
sourceSessionID: ticketMessage.sourceSessionID,
action: ticketMessage.action,
ticketDetails: ticketMessage.ticketDetails
});
break;

case 'process':
console.log('Processing ticket update:', ticketMessage.ticketDetails.uuid);
refreshSingleTicket(ticketMessage.ticketDetails.uuid);
break;
}
} catch (error) {
console.error('Error processing websocket message:', error);
Expand All @@ -94,7 +111,7 @@ const PhasePlannerView: React.FC = () => {
socket.close();
}
};
}, []);
}, [main]);

const getFeatureData = useCallback(async () => {
if (!feature_uuid) return;
Expand Down

0 comments on commit 1b7a610

Please sign in to comment.