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