Push full TGO information in the event stream.

https://github.com/dcs-liberation/dcs_liberation/issues/2263
This commit is contained in:
Raffson
2022-07-06 21:41:58 +02:00
committed by GitHub
parent 0fc2e8872d
commit a20b95bb26
4 changed files with 12 additions and 14 deletions

View File

@@ -1,6 +1,5 @@
import { AppDispatch } from "../app/store";
import { gameUnloaded } from "./actions";
import backend from "./backend";
import Combat from "./combat";
import { endCombat, newCombat, updateCombat } from "./combatSlice";
import { updateControlPoint } from "./controlPointsSlice";
@@ -48,7 +47,7 @@ interface GameUpdateEvents {
deselected_flight: boolean;
updated_front_lines: FrontLine[];
deleted_front_lines: string[];
updated_tgos: string[];
updated_tgos: Tgo[];
updated_control_points: ControlPoint[];
updated_iads: IadsConnection[];
deleted_iads: string[];
@@ -131,11 +130,8 @@ export const handleStreamedEvents = (
dispatch(deleteFrontLine(events.deleted_front_lines));
}
for (const id of events.updated_tgos) {
backend.get(`/tgos/${id}`).then((response) => {
const tgo = response.data as Tgo;
dispatch(updateTgo(tgo));
});
if (events.updated_tgos.length > 0) {
dispatch(updateTgo(events.updated_tgos));
}
if (events.updated_control_points.length > 0) {

View File

@@ -15,9 +15,10 @@ export const tgosSlice = createSlice({
name: "tgos",
initialState,
reducers: {
updateTgo: (state, action: PayloadAction<Tgo>) => {
const tgo = action.payload;
state.tgos[tgo.id] = tgo;
updateTgo: (state, action: PayloadAction<Tgo[]>) => {
for (const tgo of action.payload) {
state.tgos[tgo.id] = tgo;
}
},
},
extraReducers: (builder) => {