diff --git a/client/src/api/eventstream.tsx b/client/src/api/eventstream.tsx index ef246983..04615be7 100644 --- a/client/src/api/eventstream.tsx +++ b/client/src/api/eventstream.tsx @@ -11,7 +11,7 @@ import { selectFlight, unregisterFlight, updateFlight, - updateFlightPosition, + updateFlightPositions, } from "./flightsSlice"; import { addFrontLine, @@ -47,11 +47,9 @@ export const handleStreamedEvents = ( dispatch: AppDispatch, events: GameUpdateEvents ) => { - for (const [id, position] of Object.entries( - events.updated_flight_positions - )) { - dispatch(updateFlightPosition([id, position])); - } + dispatch( + updateFlightPositions(Object.entries(events.updated_flight_positions)) + ); for (const combat of events.new_combats) { dispatch(newCombat(combat)); diff --git a/client/src/api/flightsSlice.ts b/client/src/api/flightsSlice.ts index 8057468e..ff4fd2b1 100644 --- a/client/src/api/flightsSlice.ts +++ b/client/src/api/flightsSlice.ts @@ -42,9 +42,13 @@ export const flightsSlice = createSlice({ const id = action.payload; state.selected = state.flights[id]; }, - updateFlightPosition: (state, action: PayloadAction<[string, LatLng]>) => { - const [id, position] = action.payload; - state.flights[id].position = position; + updateFlightPositions: ( + state, + action: PayloadAction<[string, LatLng][]> + ) => { + for (const [id, position] of action.payload) { + state.flights[id].position = position; + } }, }, }); @@ -56,7 +60,7 @@ export const { updateFlight, deselectFlight, selectFlight, - updateFlightPosition, + updateFlightPositions, } = flightsSlice.actions; export const selectFlights = (state: RootState) => state.flights;