diff --git a/apps/dispatch/app/(app)/dispatch/_components/navbar/_components/Settings.tsx b/apps/dispatch/app/(app)/dispatch/_components/navbar/_components/Settings.tsx index 1ddee742..c83288b8 100644 --- a/apps/dispatch/app/(app)/dispatch/_components/navbar/_components/Settings.tsx +++ b/apps/dispatch/app/(app)/dispatch/_components/navbar/_components/Settings.tsx @@ -8,6 +8,8 @@ import { editUserAPI, getUserAPI } from "_querys/user"; import { useSession } from "next-auth/react"; import { useAudioStore } from "_store/audioStore"; import toast from "react-hot-toast"; +import { useMapStore } from "_store/mapStore"; +import { set } from "date-fns"; export const SettingsBtn = () => { const session = useSession(); @@ -41,6 +43,7 @@ export const SettingsBtn = () => { }); const { setSettings: setAudioSettings } = useAudioStore((state) => state); + const { setUserSettings: setUserSettings } = useMapStore((state) => state); useEffect(() => { if (user) { @@ -56,8 +59,11 @@ export const SettingsBtn = () => { radioVolume: user.settingsRadioVolume || 0.8, autoCloseMapPopup: user.settingsAutoCloseMapPopup || false, }); + setUserSettings({ + settingsAutoCloseMapPopup: user.settingsAutoCloseMapPopup || false, + }); } - }, [user, setSettings, setAudioSettings]); + }, [user, setSettings, setAudioSettings, setUserSettings]); const setSettingsPartial = (newSettings: Partial) => { setSettings((prev) => ({ @@ -178,15 +184,19 @@ export const SettingsBtn = () => {
-
-
- Login options - -
-
+
Disponenten Einstellungen
+
+ +
+ { + setSettingsPartial({ autoCloseMapPopup: e.target.checked }); + }} + /> + Popups automatisch schließen
@@ -213,6 +223,7 @@ export const SettingsBtn = () => { settingsMicDevice: settings.micDeviceId, settingsMicVolume: settings.micVolume, settingsRadioVolume: settings.radioVolume, + settingsAutoCloseMapPopup: settings.autoCloseMapPopup, }, }); setAudioSettings({ @@ -220,6 +231,9 @@ export const SettingsBtn = () => { micVolume: settings.micVolume, radioVolume: settings.radioVolume, }); + setUserSettings({ + settingsAutoCloseMapPopup: settings.autoCloseMapPopup, + }); modalRef.current?.close(); toast.success("Einstellungen gespeichert"); }} diff --git a/apps/dispatch/app/_components/customToasts/HPGnotification.tsx b/apps/dispatch/app/_components/customToasts/HPGnotification.tsx index ccf5593d..52152e65 100644 --- a/apps/dispatch/app/_components/customToasts/HPGnotification.tsx +++ b/apps/dispatch/app/_components/customToasts/HPGnotification.tsx @@ -15,10 +15,19 @@ export const HPGnotificationToast = ({ }) => { const handleClick = () => { toast.dismiss(t.id); - mapStore.setOpenMissionMarker({ - open: [{ id: event.data.mission.id, tab: "home" }], - close: [], - }); + + if (mapStore.userSettings.settingsAutoCloseMapPopup) { + mapStore.setOpenMissionMarker({ + open: [{ id: event.data.mission.id, tab: "home" }], + close: mapStore.openMissionMarker?.map((m) => m.id) || [], + }); + } else { + mapStore.setOpenMissionMarker({ + open: [{ id: event.data.mission.id, tab: "home" }], + close: [], + }); + } + mapStore.setMap({ center: [event.data.mission.addressLat, event.data.mission.addressLng], zoom: 14, @@ -29,7 +38,7 @@ export const HPGnotificationToast = ({ return ( } className="flex flex-row">
-

HPG validierung fehlgeschlagen

+

HPG validierung fehlgeschlagen

{event.message}

@@ -43,7 +52,7 @@ export const HPGnotificationToast = ({ return ( } className="flex flex-row">
-

HPG validierung erfolgreich

+

HPG validierung erfolgreich

{event.message}

diff --git a/apps/dispatch/app/_components/customToasts/MissionAutoClose.tsx b/apps/dispatch/app/_components/customToasts/MissionAutoClose.tsx index af1ef5e9..bc9efc43 100644 --- a/apps/dispatch/app/_components/customToasts/MissionAutoClose.tsx +++ b/apps/dispatch/app/_components/customToasts/MissionAutoClose.tsx @@ -65,15 +65,27 @@ export const MissionAutoCloseToast = ({ lng: mission.addressLng, }, }); - mapStore.setOpenMissionMarker({ - open: [ - { - id: mission.id, - tab: "home", - }, - ], - close: [], - }); + if (mapStore.userSettings.settingsAutoCloseMapPopup) { + mapStore.setOpenMissionMarker({ + open: [ + { + id: mission.id, + tab: "home", + }, + ], + close: mapStore.openMissionMarker?.map((m) => m.id) || [], + }); + } else { + mapStore.setOpenMissionMarker({ + open: [ + { + id: mission.id, + tab: "home", + }, + ], + close: [], + }); + } toast.dismiss(t.id); }} > diff --git a/apps/dispatch/app/_components/customToasts/StationStatusToast.tsx b/apps/dispatch/app/_components/customToasts/StationStatusToast.tsx index dbed6bb3..e85f2094 100644 --- a/apps/dispatch/app/_components/customToasts/StationStatusToast.tsx +++ b/apps/dispatch/app/_components/customToasts/StationStatusToast.tsx @@ -47,7 +47,10 @@ export const StatusToast = ({ event, t }: { event: StationStatus; t: Toast }) => } }, []); const [aircraftDataAcurate, setAircraftDataAccurate] = useState(false); - const mapStore = useMapStore((s) => s); + //const mapStore = useMapStore((s) => s); + const { openAircraftMarker, setOpenAircraftMarker, userSettings, setMap } = useMapStore( + (store) => store, + ); const { data: connectedAircrafts } = useQuery({ queryKey: ["aircrafts"], @@ -129,11 +132,18 @@ export const StatusToast = ({ event, t }: { event: StationStatus; t: Toast }) => className="mr-1 cursor-pointer font-bold underline" onClick={() => { if (!connectedAircraft.posLat || !connectedAircraft.posLng) return; - mapStore.setOpenAircraftMarker({ - open: [{ id: connectedAircraft.id, tab: "fms" }], - close: [], - }); - mapStore.setMap({ + 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: [], + }); + } + setMap({ center: [connectedAircraft.posLat, connectedAircraft.posLng], zoom: 14, }); diff --git a/apps/dispatch/app/_components/left/SituationBoard.tsx b/apps/dispatch/app/_components/left/SituationBoard.tsx index fb2a67da..0f596e9e 100644 --- a/apps/dispatch/app/_components/left/SituationBoard.tsx +++ b/apps/dispatch/app/_components/left/SituationBoard.tsx @@ -54,7 +54,14 @@ export const SituationBoard = () => { queryKey: ["aircrafts"], queryFn: () => getConnectedAircraftsAPI(), }); - const { setOpenAircraftMarker, setOpenMissionMarker, setMap } = useMapStore((state) => state); + const { + setOpenAircraftMarker, + setOpenMissionMarker, + setMap, + userSettings, + openAircraftMarker, + openMissionMarker, + } = useMapStore((state) => state); return (
@@ -112,15 +119,27 @@ export const SituationBoard = () => { mission.state === "draft" && "missionListItem", )} onDoubleClick={() => { - setOpenMissionMarker({ - open: [ - { - id: mission.id, - tab: "home", - }, - ], - close: [], - }); + 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: [], + }); + } setMap({ center: { lat: mission.addressLat, @@ -161,45 +180,57 @@ export const SituationBoard = () => { - {connectedAircrafts?.map((station) => ( + {connectedAircrafts?.map((aircraft) => ( { - setOpenAircraftMarker({ - open: [ - { - id: station.id, - tab: "home", - }, - ], - close: [], - }); - if (station.posLat === null || station.posLng === null) return; + 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: [], + }); + } + if (aircraft.posLat === null || aircraft.posLng === null) return; setMap({ center: { - lat: station.posLat, - lng: station.posLng, + lat: aircraft.posLat, + lng: aircraft.posLng, }, zoom: 14, }); }} > - {station.Station.bosCallsignShort} + {aircraft.Station.bosCallsignShort} - {station.fmsStatus} + {aircraft.fmsStatus} - {station.posLng || !station.posLat ? ( - <>{findLeitstelleForPosition(station.posLng!, station.posLat!)} + {aircraft.posLng || !aircraft.posLat ? ( + <>{findLeitstelleForPosition(aircraft.posLng!, aircraft.posLat!)} ) : ( - station.Station.bosRadioArea + aircraft.Station.bosRadioArea )} diff --git a/apps/dispatch/app/_components/map/AircraftMarker.tsx b/apps/dispatch/app/_components/map/AircraftMarker.tsx index 33d64867..f90c8119 100644 --- a/apps/dispatch/app/_components/map/AircraftMarker.tsx +++ b/apps/dispatch/app/_components/map/AircraftMarker.tsx @@ -17,6 +17,7 @@ import { getConnectedAircraftPositionLogAPI, getConnectedAircraftsAPI } from "_q import { getMissionsAPI } from "_querys/missions"; import { FMS_STATUS_COLORS, FMS_STATUS_TEXT_COLORS } from "_helpers/fmsStatusColors"; import { usePilotConnectionStore } from "_store/pilot/connectionStore"; +import { useSession } from "next-auth/react"; const AircraftPopupContent = ({ aircraft, @@ -72,7 +73,7 @@ const AircraftPopupContent = ({ } }, [currentTab, aircraft, mission]); - const { setOpenAircraftMarker, setMap } = useMapStore((state) => state); + const { setOpenAircraftMarker, setMap, openAircraftMarker } = useMapStore((state) => state); const { anchor } = useSmartPopup(); return ( <> @@ -229,7 +230,7 @@ const AircraftMarker = ({ aircraft }: { aircraft: ConnectedAircraft & { Station: const markerRef = useRef(null); const popupRef = useRef(null); - const { openAircraftMarker, setOpenAircraftMarker } = useMapStore((store) => store); + const { openAircraftMarker, setOpenAircraftMarker, userSettings } = useMapStore((store) => store); const { data: positionLog } = useQuery({ queryKey: ["positionlog", aircraft.id], queryFn: () => @@ -249,15 +250,27 @@ const AircraftMarker = ({ aircraft }: { aircraft: ConnectedAircraft & { Station: close: [aircraft.id], }); } else { - setOpenAircraftMarker({ - open: [ - { - id: aircraft.id, - tab: "home", - }, - ], - close: [], - }); + 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: [], + }); + } } }; const marker = markerRef.current; @@ -265,7 +278,7 @@ const AircraftMarker = ({ aircraft }: { aircraft: ConnectedAircraft & { Station: return () => { marker?.off("click", handleClick); }; - }, [aircraft.id, openAircraftMarker, setOpenAircraftMarker]); + }, [aircraft.id, openAircraftMarker, setOpenAircraftMarker, userSettings]); const [anchor, setAnchor] = useState<"topleft" | "topright" | "bottomleft" | "bottomright">( "topleft", diff --git a/apps/dispatch/app/_components/map/MissionMarkers.tsx b/apps/dispatch/app/_components/map/MissionMarkers.tsx index 667dc88d..25a7d34b 100644 --- a/apps/dispatch/app/_components/map/MissionMarkers.tsx +++ b/apps/dispatch/app/_components/map/MissionMarkers.tsx @@ -230,7 +230,7 @@ const MissionMarker = ({ refetchInterval: 10000, }); - const { openMissionMarker, setOpenMissionMarker } = useMapStore((store) => store); + const { openMissionMarker, setOpenMissionMarker, userSettings } = useMapStore((store) => store); const needsAction = HPGValidationRequired(mission.missionStationIds, aircrafts, mission.hpgMissionString) && @@ -246,15 +246,27 @@ const MissionMarker = ({ close: [mission.id], }); } else { - setOpenMissionMarker({ - open: [ - { - id: mission.id, - tab: "home", - }, - ], - close: [], - }); + 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: [], + }); + } } }; const markerCopy = markerRef.current; @@ -262,7 +274,7 @@ const MissionMarker = ({ return () => { markerCopy?.off("click", handleClick); }; - }, [mission.id, openMissionMarker, setOpenMissionMarker]); + }, [mission.id, openMissionMarker, setOpenMissionMarker, userSettings]); const [anchor, setAnchor] = useState<"topleft" | "topright" | "bottomleft" | "bottomright">( "topleft", diff --git a/apps/dispatch/app/_components/map/_components/MarkerCluster.tsx b/apps/dispatch/app/_components/map/_components/MarkerCluster.tsx index e392dc39..8dbcd078 100644 --- a/apps/dispatch/app/_components/map/_components/MarkerCluster.tsx +++ b/apps/dispatch/app/_components/map/_components/MarkerCluster.tsx @@ -21,7 +21,13 @@ const PopupContent = ({ missions: Mission[]; }) => { const { anchor } = useSmartPopup(); - const { setOpenAircraftMarker, setOpenMissionMarker } = useMapStore((state) => state); + const { + setOpenAircraftMarker, + setOpenMissionMarker, + openAircraftMarker, + openMissionMarker, + userSettings, + } = useMapStore((state) => state); const map = useMap(); let borderColor = ""; @@ -77,15 +83,27 @@ const PopupContent = ({ { - setOpenMissionMarker({ - open: [ - { - id: mission.id, - tab: "home", - }, - ], - close: [], - }); + 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: [], + }); + } map.setView([mission.addressLat, mission.addressLng], 12, { animate: true, }); @@ -104,15 +122,27 @@ const PopupContent = ({ backgroundColor: FMS_STATUS_COLORS[aircraft.fmsStatus], }} onClick={() => { - setOpenAircraftMarker({ - open: [ - { - id: aircraft.id, - tab: "aircraft", - }, - ], - close: [], - }); + 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: [], + }); + } map.setView([aircraft.posLat!, aircraft.posLng!], 12, { animate: true, }); diff --git a/apps/dispatch/app/_store/mapStore.ts b/apps/dispatch/app/_store/mapStore.ts index b6f06493..7733d603 100644 --- a/apps/dispatch/app/_store/mapStore.ts +++ b/apps/dispatch/app/_store/mapStore.ts @@ -39,6 +39,10 @@ export interface MapStore { [aircraftId: string]: "home" | "fms" | "aircraft" | "mission" | "chat"; }; setAircraftTab: (aircraftId: number, tab: MapStore["aircraftTabs"][number]) => void; + userSettings: { + settingsAutoCloseMapPopup: boolean; + }; + setUserSettings: (settings: Partial) => void; } export const useMapStore = create((set, get) => ({ @@ -102,4 +106,14 @@ export const useMapStore = create((set, get) => ({ }, })), missionTabs: {}, + userSettings: { + settingsAutoCloseMapPopup: false, + }, + setUserSettings: (settings) => + set((state) => ({ + userSettings: { + ...state.userSettings, + ...settings, + }, + })), }));