Push full front line information in the event stream.

https://github.com/dcs-liberation/dcs_liberation/issues/2263
This commit is contained in:
Raffson
2022-06-25 23:13:10 +02:00
committed by GitHub
parent d578e763c0
commit da90a40bc4
5 changed files with 20 additions and 37 deletions

View File

@@ -13,7 +13,6 @@ import {
updateFlightPositions,
} from "./flightsSlice";
import {
addFrontLine,
deleteFrontLine,
updateFrontLine,
} from "./frontLinesSlice";
@@ -47,8 +46,7 @@ interface GameUpdateEvents {
deleted_flights: string[];
selected_flight: string | null;
deselected_flight: boolean;
new_front_lines: FrontLine[];
updated_front_lines: string[];
updated_front_lines: FrontLine[];
deleted_front_lines: string[];
updated_tgos: string[];
updated_control_points: number[];
@@ -123,19 +121,12 @@ export const handleStreamedEvents = (
dispatch(selectFlight(events.selected_flight));
}
for (const front of events.new_front_lines) {
dispatch(addFrontLine(front));
if (events.updated_front_lines.length > 0) {
dispatch(updateFrontLine(events.updated_front_lines));
}
for (const id of events.updated_front_lines) {
backend.get(`/front-lines/${id}`).then((response) => {
const front = response.data as FrontLine;
dispatch(updateFrontLine(front));
});
}
for (const id of events.deleted_front_lines) {
dispatch(deleteFrontLine(id));
if (events.deleted_front_lines.length > 0) {
dispatch(deleteFrontLine(events.deleted_front_lines));
}
for (const id of events.updated_tgos) {

View File

@@ -15,16 +15,15 @@ export const frontLinesSlice = createSlice({
name: "frontLines",
initialState,
reducers: {
addFrontLine: (state, action: PayloadAction<FrontLine>) => {
const front = action.payload;
state.fronts[front.id] = front;
updateFrontLine: (state, action: PayloadAction<FrontLine[]>) => {
for (const front of action.payload) {
state.fronts[front.id] = front;
}
},
updateFrontLine: (state, action: PayloadAction<FrontLine>) => {
const front = action.payload;
state.fronts[front.id] = front;
},
deleteFrontLine: (state, action: PayloadAction<string>) => {
delete state.fronts[action.payload];
deleteFrontLine: (state, action: PayloadAction<string[]>) => {
for (const uid of action.payload) {
delete state.fronts[uid];
}
},
},
extraReducers: (builder) => {
@@ -43,7 +42,7 @@ export const frontLinesSlice = createSlice({
},
});
export const { addFrontLine, updateFrontLine, deleteFrontLine } =
export const { updateFrontLine, deleteFrontLine } =
frontLinesSlice.actions;
export const selectFrontLines = (state: RootState) => state.frontLines;