Add websocket handling for selected flights.

This commit is contained in:
Dan Albert
2022-03-01 20:42:59 -08:00
parent 6d29bfdf65
commit 8e8bbe84f3
13 changed files with 190 additions and 13 deletions

View File

@@ -1,3 +1,4 @@
import { Flight } from "../../api/flight";
import FlightPlan from "../flightplan";
import { LayerGroup } from "react-leaflet";
import { selectFlights } from "../../api/flightsSlice";
@@ -10,11 +11,29 @@ interface FlightPlansLayerProps {
export default function FlightPlansLayer(props: FlightPlansLayerProps) {
const atos = useAppSelector(selectFlights);
const flights = props.blue ? atos.blue : atos.red;
const isNotSelected = (flight: Flight) => {
if (atos.selected == null) {
return true;
}
return atos.selected.id !== flight.id;
};
const selectedFlight = atos.selected ? (
<FlightPlan key={atos.selected.id} flight={atos.selected} selected={true} />
) : (
<></>
);
return (
<LayerGroup>
{Object.values(flights).map((flight) => {
return <FlightPlan key={flight.id} flight={flight} selected={false} />;
})}
{Object.values(flights)
.filter(isNotSelected)
.map((flight) => {
return (
<FlightPlan key={flight.id} flight={flight} selected={false} />
);
})}
{selectedFlight}
</LayerGroup>
);
}