From 26e7966e1975b31314e12a6aca4bde286a297eed Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Thu, 24 Jul 2025 16:47:02 -0700 Subject: [PATCH] cleanup openMarkerSettings --- .../customToasts/StationStatusToast.tsx | 20 ++++--------- .../app/_components/map/AircraftMarker.tsx | 30 ++++++------------- .../app/_components/map/MissionMarkers.tsx | 30 ++++++------------- .../app/_components/map/openCloseMarker.ts | 0 apps/dispatch/app/_store/mapStore.ts | 22 ++++++++++---- 5 files changed, 40 insertions(+), 62 deletions(-) create mode 100644 apps/dispatch/app/_components/map/openCloseMarker.ts diff --git a/apps/dispatch/app/_components/customToasts/StationStatusToast.tsx b/apps/dispatch/app/_components/customToasts/StationStatusToast.tsx index e85f2094..ce66b81a 100644 --- a/apps/dispatch/app/_components/customToasts/StationStatusToast.tsx +++ b/apps/dispatch/app/_components/customToasts/StationStatusToast.tsx @@ -48,9 +48,7 @@ export const StatusToast = ({ event, t }: { event: StationStatus; t: Toast }) => }, []); const [aircraftDataAcurate, setAircraftDataAccurate] = useState(false); //const mapStore = useMapStore((s) => s); - const { openAircraftMarker, setOpenAircraftMarker, userSettings, setMap } = useMapStore( - (store) => store, - ); + const { setOpenAircraftMarker, setMap } = useMapStore((store) => store); const { data: connectedAircrafts } = useQuery({ queryKey: ["aircrafts"], @@ -132,17 +130,11 @@ export const StatusToast = ({ event, t }: { event: StationStatus; t: Toast }) => className="mr-1 cursor-pointer font-bold underline" onClick={() => { if (!connectedAircraft.posLat || !connectedAircraft.posLng) return; - if (userSettings.settingsAutoCloseMapPopup) { - setOpenAircraftMarker({ - open: [{ id: connectedAircraft.id, tab: "fms" }], - close: openAircraftMarker?.map((m) => m.id) || [], - }); - } else { - setOpenAircraftMarker({ - open: [{ id: connectedAircraft.id, tab: "fms" }], - close: [], - }); - } + + setOpenAircraftMarker({ + open: [{ id: connectedAircraft.id, tab: "fms" }], + close: [], + }); setMap({ center: [connectedAircraft.posLat, connectedAircraft.posLng], zoom: 14, diff --git a/apps/dispatch/app/_components/map/AircraftMarker.tsx b/apps/dispatch/app/_components/map/AircraftMarker.tsx index f90c8119..371565de 100644 --- a/apps/dispatch/app/_components/map/AircraftMarker.tsx +++ b/apps/dispatch/app/_components/map/AircraftMarker.tsx @@ -250,27 +250,15 @@ const AircraftMarker = ({ aircraft }: { aircraft: ConnectedAircraft & { Station: close: [aircraft.id], }); } else { - if (userSettings.settingsAutoCloseMapPopup) { - setOpenAircraftMarker({ - open: [ - { - id: aircraft.id, - tab: "home", - }, - ], - close: openAircraftMarker?.map((m) => m.id) || [], - }); - } else { - setOpenAircraftMarker({ - open: [ - { - id: aircraft.id, - tab: "home", - }, - ], - close: [], - }); - } + setOpenAircraftMarker({ + open: [ + { + id: aircraft.id, + tab: "home", + }, + ], + close: [], + }); } }; const marker = markerRef.current; diff --git a/apps/dispatch/app/_components/map/MissionMarkers.tsx b/apps/dispatch/app/_components/map/MissionMarkers.tsx index 25a7d34b..a748bc69 100644 --- a/apps/dispatch/app/_components/map/MissionMarkers.tsx +++ b/apps/dispatch/app/_components/map/MissionMarkers.tsx @@ -246,27 +246,15 @@ const MissionMarker = ({ close: [mission.id], }); } else { - if (userSettings.settingsAutoCloseMapPopup) { - setOpenMissionMarker({ - open: [ - { - id: mission.id, - tab: "home", - }, - ], - close: openMissionMarker?.map((m) => m.id) || [], - }); - } else { - setOpenMissionMarker({ - open: [ - { - id: mission.id, - tab: "home", - }, - ], - close: [], - }); - } + setOpenMissionMarker({ + open: [ + { + id: mission.id, + tab: "home", + }, + ], + close: openMissionMarker?.map((m) => m.id) || [], + }); } }; const markerCopy = markerRef.current; diff --git a/apps/dispatch/app/_components/map/openCloseMarker.ts b/apps/dispatch/app/_components/map/openCloseMarker.ts new file mode 100644 index 00000000..e69de29b diff --git a/apps/dispatch/app/_store/mapStore.ts b/apps/dispatch/app/_store/mapStore.ts index 7733d603..d48bbdbb 100644 --- a/apps/dispatch/app/_store/mapStore.ts +++ b/apps/dispatch/app/_store/mapStore.ts @@ -48,18 +48,28 @@ export interface MapStore { export const useMapStore = create((set, get) => ({ openMissionMarker: [], setOpenMissionMarker: ({ open, close }) => { - const oldMarkers = get().openMissionMarker.filter( - (m) => !close.includes(m.id) && !open.find((o) => o.id === m.id), - ); + const { settingsAutoCloseMapPopup } = get().userSettings; + + const oldMarkers = + settingsAutoCloseMapPopup && open.length > 0 + ? [] // If auto-close is enabled and opening a new popup, close all others + : get().openMissionMarker.filter( + (m) => !close.includes(m.id) && !open.find((o) => o.id === m.id), + ); set(() => ({ openMissionMarker: [...oldMarkers, ...open], })); }, openAircraftMarker: [], setOpenAircraftMarker: ({ open, close }) => { - const oldMarkers = get().openAircraftMarker.filter( - (m) => !close.includes(m.id) && !open.find((o) => o.id === m.id), - ); + const { settingsAutoCloseMapPopup } = get().userSettings; + + const oldMarkers = + settingsAutoCloseMapPopup && open.length > 0 + ? [] // If auto-close is enabled and opening a new popup, close all others + : get().openAircraftMarker.filter( + (m) => !close.includes(m.id) && !open.find((o) => o.id === m.id), + ); set(() => ({ openAircraftMarker: [...oldMarkers, ...open], }));