Add tabs to aircraft popup
This commit is contained in:
@@ -51,6 +51,13 @@ interface MapStore {
|
|||||||
elementId: number;
|
elementId: number;
|
||||||
} | null;
|
} | null;
|
||||||
setSearchPopup: (popup: MapStore["searchPopup"]) => void;
|
setSearchPopup: (popup: MapStore["searchPopup"]) => void;
|
||||||
|
aircraftTabs: {
|
||||||
|
[aircraftId: string]: "home" | "fms" | "aircraft" | "mission" | "chat";
|
||||||
|
};
|
||||||
|
setAircraftTab: (
|
||||||
|
aircraftId: string,
|
||||||
|
tab: MapStore["aircraftTabs"][string],
|
||||||
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useMapStore = create<MapStore>((set, get) => ({
|
export const useMapStore = create<MapStore>((set, get) => ({
|
||||||
@@ -91,4 +98,12 @@ export const useMapStore = create<MapStore>((set, get) => ({
|
|||||||
set((state) => ({
|
set((state) => ({
|
||||||
searchElements: elements,
|
searchElements: elements,
|
||||||
})),
|
})),
|
||||||
|
aircraftTabs: {},
|
||||||
|
setAircraftTab: (aircraftId, tab) =>
|
||||||
|
set((state) => ({
|
||||||
|
aircraftTabs: {
|
||||||
|
...state.aircraftTabs,
|
||||||
|
[aircraftId]: tab,
|
||||||
|
},
|
||||||
|
})),
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -2,7 +2,14 @@ import { Aircraft, useAircraftsStore } from "_store/aircraftsStore";
|
|||||||
import { Marker, Popup, useMap } from "react-leaflet";
|
import { Marker, Popup, 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 } from "react";
|
import {
|
||||||
|
Fragment,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
useMemo,
|
||||||
|
} from "react";
|
||||||
import { cn } from "helpers/cn";
|
import { cn } from "helpers/cn";
|
||||||
import {
|
import {
|
||||||
ChevronsRightLeft,
|
ChevronsRightLeft,
|
||||||
@@ -41,6 +48,38 @@ export const FMS_STATUS_TEXT_COLORS: { [key: string]: string } = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const AircraftPopupContent = ({ aircraft }: { aircraft: Aircraft }) => {
|
const AircraftPopupContent = ({ aircraft }: { aircraft: Aircraft }) => {
|
||||||
|
const setAircraftTab = useMapStore((state) => state.setAircraftTab);
|
||||||
|
const currentTab = useMapStore(
|
||||||
|
(state) => state.aircraftTabs[aircraft.id] || "home",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Memoize the tab change handler to avoid unnecessary re-renders
|
||||||
|
const handleTabChange = useCallback(
|
||||||
|
(tab: "home" | "fms" | "aircraft" | "mission" | "chat") => {
|
||||||
|
if (currentTab !== tab) {
|
||||||
|
setAircraftTab(aircraft.id, tab);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[currentTab, aircraft.id, setAircraftTab],
|
||||||
|
);
|
||||||
|
|
||||||
|
const renderTabContent = useMemo(() => {
|
||||||
|
switch (currentTab) {
|
||||||
|
case "home":
|
||||||
|
return <div>Home Content</div>;
|
||||||
|
case "fms":
|
||||||
|
return <div>FMS Content</div>;
|
||||||
|
case "aircraft":
|
||||||
|
return <div>Aircraft Content</div>;
|
||||||
|
case "mission":
|
||||||
|
return <div>Mission Content</div>;
|
||||||
|
case "chat":
|
||||||
|
return <div>Chat Content</div>;
|
||||||
|
default:
|
||||||
|
return <div>Default Content</div>;
|
||||||
|
}
|
||||||
|
}, [currentTab]);
|
||||||
|
|
||||||
const setOpenAircraftMarker = useMapStore(
|
const setOpenAircraftMarker = useMapStore(
|
||||||
(state) => state.setOpenAircraftMarker,
|
(state) => state.setOpenAircraftMarker,
|
||||||
);
|
);
|
||||||
@@ -88,15 +127,16 @@ const AircraftPopupContent = ({ aircraft }: { aircraft: Aircraft }) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className="p-2 px-3 flex justify-center items-center"
|
className="p-2 px-3 flex justify-center items-center cursor-pointer"
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: `${FMS_STATUS_COLORS[aircraft.fmsStatus]}`,
|
backgroundColor: `${FMS_STATUS_COLORS[aircraft.fmsStatus]}`,
|
||||||
}}
|
}}
|
||||||
|
onClick={() => handleTabChange("home")}
|
||||||
>
|
>
|
||||||
<House className="text-sm" />
|
<House className="text-sm" />
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className="p-2 px-4 flex justify-center items-center"
|
className="p-2 px-4 flex justify-center items-center cursor-pointer"
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: `${FMS_STATUS_COLORS[aircraft.fmsStatus]}`,
|
backgroundColor: `${FMS_STATUS_COLORS[aircraft.fmsStatus]}`,
|
||||||
}}
|
}}
|
||||||
@@ -104,49 +144,53 @@ const AircraftPopupContent = ({ aircraft }: { aircraft: Aircraft }) => {
|
|||||||
<ChevronsRightLeft className="text-sm" />
|
<ChevronsRightLeft className="text-sm" />
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className="flex justify-center items-center text-5xl font-bold p-2 px-6"
|
className="flex justify-center items-center text-5xl font-bold p-2 px-6 cursor-pointer"
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: `${FMS_STATUS_COLORS[aircraft.fmsStatus]}`,
|
backgroundColor: `${FMS_STATUS_COLORS[aircraft.fmsStatus]}`,
|
||||||
color: `${FMS_STATUS_TEXT_COLORS[aircraft.fmsStatus]}`,
|
color: `${FMS_STATUS_TEXT_COLORS[aircraft.fmsStatus]}`,
|
||||||
}}
|
}}
|
||||||
|
onClick={() => handleTabChange("fms")}
|
||||||
>
|
>
|
||||||
{aircraft.fmsStatus}
|
{aircraft.fmsStatus}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className="p-2 w-100"
|
className="p-2 w-100 cursor-pointer"
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: `${FMS_STATUS_COLORS[aircraft.fmsStatus]}`,
|
backgroundColor: `${FMS_STATUS_COLORS[aircraft.fmsStatus]}`,
|
||||||
whiteSpace: "nowrap",
|
whiteSpace: "nowrap",
|
||||||
}}
|
}}
|
||||||
|
onClick={() => handleTabChange("aircraft")}
|
||||||
>
|
>
|
||||||
<span className="text-white text-base font-medium">
|
<span className="text-white text-base font-medium">
|
||||||
{/* {aircraft.bosName} */} Christophorus 1
|
Christophorus 1
|
||||||
<br />
|
<br />
|
||||||
RTH
|
RTH
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className="p-2 w-150"
|
className="p-2 w-150 cursor-pointer"
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: `${FMS_STATUS_COLORS[aircraft.fmsStatus]}`,
|
backgroundColor: `${FMS_STATUS_COLORS[aircraft.fmsStatus]}`,
|
||||||
whiteSpace: "nowrap",
|
whiteSpace: "nowrap",
|
||||||
}}
|
}}
|
||||||
|
onClick={() => handleTabChange("mission")}
|
||||||
>
|
>
|
||||||
<span className="text-white text-base font-medium">Einsatz</span>
|
<span className="text-white text-base font-medium">Einsatz</span>
|
||||||
<br />
|
<br />
|
||||||
<span className="text-white text-sm font-medium">__202504161</span>
|
<span className="text-white text-sm font-medium">__202504161</span>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className="p-2 px-4 flex justify-center items-center"
|
className="p-2 px-4 flex justify-center items-center cursor-pointer"
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: `${FMS_STATUS_COLORS[aircraft.fmsStatus]}`,
|
backgroundColor: `${FMS_STATUS_COLORS[aircraft.fmsStatus]}`,
|
||||||
}}
|
}}
|
||||||
|
onClick={() => handleTabChange("chat")}
|
||||||
>
|
>
|
||||||
<MessageSquareText className="text-sm" />
|
<MessageSquareText className="text-sm" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>test</div>
|
<div>{renderTabContent}</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user