This commit is contained in:
nocnico
2025-05-21 18:53:44 +02:00
parent 965a2e737d
commit f52f870eed

View File

@@ -1,6 +1,7 @@
import { ConnectedAircraft, Mission, Station } from "@repo/db";
import { useQuery } from "@tanstack/react-query";
import { SmartPopup, useSmartPopup } from "_components/SmartPopup";
import { useDispatchConnectionStore } from "_store/dispatch/connectionStore";
import { useMapStore } from "_store/mapStore";
import {
FMS_STATUS_COLORS,
@@ -14,7 +15,7 @@ import { cn } from "helpers/cn";
import { checkSimulatorConnected } from "helpers/simulatorConnected";
import { getConnectedAircraftsAPI } from "querys/aircrafts";
import { getMissionsAPI } from "querys/missions";
import { useEffect, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { useMap } from "react-leaflet";
const PopupContent = ({
@@ -149,13 +150,23 @@ export const MarkerCluster = () => {
queryFn: getConnectedAircraftsAPI,
});
const { data: missions } = useQuery({
const dispatcherConnected =
useDispatchConnectionStore((s) => s.status) === "connected";
const { data: missions = [] } = useQuery({
queryKey: ["missions"],
queryFn: () =>
getMissionsAPI({
OR: [{ state: "draft" }, { state: "running" }],
}),
});
const filteredMissions = useMemo(() => {
if (!dispatcherConnected) {
return missions.filter((m: Mission) => m.state === "running");
}
return missions;
}, [missions, dispatcherConnected]);
const [cluster, setCluster] = useState<
{
aircrafts: (ConnectedAircraft & { Station: Station })[];
@@ -201,7 +212,7 @@ export const MarkerCluster = () => {
];
}
});
missions?.forEach((mission) => {
filteredMissions?.forEach((mission) => {
const lat = mission.addressLat;
const lng = mission.addressLng;
const existingClusterIndex = newCluster.findIndex(
@@ -262,7 +273,7 @@ export const MarkerCluster = () => {
return () => {
map.off("zoomend", handleZoom);
};
}, [map, aircrafts, missions]);
}, [map, aircrafts, missions, filteredMissions]);
return (
<>
{cluster.map((c, i) => (