v2.0.5 #141
@@ -2,7 +2,7 @@ import { Marker, Polyline, useMap } from "react-leaflet";
|
|||||||
import { DivIcon, Marker as LMarker, Popup as LPopup } from "leaflet";
|
import { DivIcon, Marker as LMarker, Popup as LPopup } from "leaflet";
|
||||||
import { useMapStore } from "_store/mapStore";
|
import { useMapStore } from "_store/mapStore";
|
||||||
import { Fragment, useCallback, useEffect, useRef, useState, useMemo } from "react";
|
import { Fragment, useCallback, useEffect, useRef, useState, useMemo } from "react";
|
||||||
import { cn } from "@repo/shared-components";
|
import { checkSimulatorConnected, cn } from "@repo/shared-components";
|
||||||
import { ChevronsRightLeft, House, MessageSquareText, Minimize2 } from "lucide-react";
|
import { ChevronsRightLeft, House, MessageSquareText, Minimize2 } from "lucide-react";
|
||||||
import { SmartPopup, calculateAnchor, useSmartPopup } from "_components/SmartPopup";
|
import { SmartPopup, calculateAnchor, useSmartPopup } from "_components/SmartPopup";
|
||||||
import FMSStatusHistory, {
|
import FMSStatusHistory, {
|
||||||
@@ -396,11 +396,27 @@ const AircraftMarker = ({ aircraft }: { aircraft: ConnectedAircraft & { Station:
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const AircraftLayer = () => {
|
export const AircraftLayer = () => {
|
||||||
const { data: aircrafts } = useQuery({
|
const [aircrafts, setAircrafts] = useState<(ConnectedAircraft & { Station: Station })[]>([]);
|
||||||
queryKey: ["aircrafts-map"],
|
|
||||||
queryFn: () => getConnectedAircraftsAPI(),
|
useEffect(() => {
|
||||||
refetchInterval: 10_000,
|
const fetchAircrafts = async () => {
|
||||||
});
|
try {
|
||||||
|
const res = await fetch("/api/aircrafts");
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error("Failed to fetch aircrafts");
|
||||||
|
}
|
||||||
|
const data: (ConnectedAircraft & { Station: Station })[] = await res.json();
|
||||||
|
setAircrafts(data.filter((a) => checkSimulatorConnected(a)));
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch aircrafts:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchAircrafts();
|
||||||
|
const interval = setInterval(fetchAircrafts, 10_000);
|
||||||
|
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, []);
|
||||||
const { setMap } = useMapStore((state) => state);
|
const { setMap } = useMapStore((state) => state);
|
||||||
const map = useMap();
|
const map = useMap();
|
||||||
const {
|
const {
|
||||||
|
|||||||
Reference in New Issue
Block a user