Un-split the flight data by coalition.

This made one callsite cleaner at the expense of the others and the
state management.
This commit is contained in:
Dan Albert
2022-03-04 19:48:42 -08:00
parent 59f734dd07
commit b6457ae434
3 changed files with 26 additions and 39 deletions

View File

@@ -4,13 +4,10 @@ import Aircraft from "../aircraft";
import { LayerGroup } from "react-leaflet";
export default function AircraftLayer() {
const atos = useAppSelector(selectFlights);
const flights = useAppSelector(selectFlights).flights;
return (
<LayerGroup>
{Object.values(atos.blue).map((flight) => {
return <Aircraft key={flight.id} flight={flight} />;
})}
{Object.values(atos.red).map((flight) => {
{Object.values(flights).map((flight) => {
return <Aircraft key={flight.id} flight={flight} />;
})}
</LayerGroup>

View File

@@ -9,25 +9,30 @@ interface FlightPlansLayerProps {
}
export default function FlightPlansLayer(props: FlightPlansLayerProps) {
const atos = useAppSelector(selectFlights);
const flights = props.blue ? atos.blue : atos.red;
const flightData = useAppSelector(selectFlights);
const isNotSelected = (flight: Flight) => {
if (atos.selected == null) {
if (flightData.selected == null) {
return true;
}
return atos.selected.id !== flight.id;
return flightData.selected.id !== flight.id;
};
const selectedFlight = atos.selected ? (
<FlightPlan key={atos.selected.id} flight={atos.selected} selected={true} />
) : (
<></>
);
const selectedFlight =
flightData.selected && flightData.selected.blue === props.blue ? (
<FlightPlan
key={flightData.selected.id}
flight={flightData.selected}
selected={true}
/>
) : (
<></>
);
return (
<LayerGroup>
{Object.values(flights)
{Object.values(flightData.flights)
.filter(isNotSelected)
.filter((flight) => props.blue === flight.blue)
.map((flight) => {
return (
<FlightPlan key={flight.id} flight={flight} selected={false} />