From 26ea7607280963c645db78526ced3decbba65722 Mon Sep 17 00:00:00 2001 From: "Karen A. Salamy" Date: Wed, 11 Feb 2026 12:20:02 -0800 Subject: [PATCH] Fix duplicate Leaflet map controls on Overview and Deployment pages - Map.tsx: Merge duplicate top-left Control blocks (Paintbrush, TrackDB, Layers, Center, Fit bounds, Add markers) into a single control group - index.tsx: Add useIsDesktop so only one layout (desktop or mobile) renders - [...deployment].tsx: Add useIsDesktop for same layout fix on Deployment page Prevents duplicate map controls when both desktop and mobile layouts mount. --- apps/lrauv-dash2/pages/index.tsx | 105 +++++---- .../pages/vehicle/[...deployment].tsx | 54 +++-- packages/react-ui/src/Map/Map.tsx | 211 +++++++++--------- 3 files changed, 198 insertions(+), 172 deletions(-) diff --git a/apps/lrauv-dash2/pages/index.tsx b/apps/lrauv-dash2/pages/index.tsx index b79cd7c0..2bcdd6bf 100644 --- a/apps/lrauv-dash2/pages/index.tsx +++ b/apps/lrauv-dash2/pages/index.tsx @@ -725,6 +725,19 @@ const OverViewMap: React.FC<{ type MobileView = 'map' | 'list' +// xl breakpoint = 1280px (matches Tailwind xl:) +const useIsDesktop = () => { + const [isDesktop, setIsDesktop] = useState(true) + useEffect(() => { + const mq = window.matchMedia('(min-width: 1280px)') + setIsDesktop(mq.matches) + const handler = (e: MediaQueryListEvent) => setIsDesktop(e.matches) + mq.addEventListener('change', handler) + return () => mq.removeEventListener('change', handler) + }, []) + return isDesktop +} + // OverviewPage: NextPage const OverviewPage: NextPage = () => { const { mapsLoaded } = useGoogleMaps() @@ -733,6 +746,7 @@ const OverviewPage: NextPage = () => { const mounted = useRef(false) const { setGlobalModalId } = useGlobalModalId() const [mobileView, setMobileView] = useState('map') + const isDesktop = useIsDesktop() useEffect(() => { if (!mounted.current) { @@ -781,54 +795,55 @@ const OverviewPage: NextPage = () => { className={styles.content} data-testid="vehicle-dashboard" > - {/* Desktop view (keep existing Allotment layout) */} -
- - {primarySection} - - {secondarySection} - - -
- - {/* Mobile view (toggle between map and list) */} -
-
- - + {primarySection} + + {secondarySection} + +
- -
- {mobileView === 'map' - ? primarySection - : secondarySection} + ) : ( +
+
+ + +
+ +
+ {mobileView === 'map' + ? primarySection + : secondarySection} +
-
+ )}
) : ( diff --git a/apps/lrauv-dash2/pages/vehicle/[...deployment].tsx b/apps/lrauv-dash2/pages/vehicle/[...deployment].tsx index bf228d0a..03e753a1 100644 --- a/apps/lrauv-dash2/pages/vehicle/[...deployment].tsx +++ b/apps/lrauv-dash2/pages/vehicle/[...deployment].tsx @@ -74,6 +74,18 @@ const DeploymentMap = dynamic(() => import('../../components/DeploymentMap'), { type AvailableTab = 'vehicle' | 'depth' | null type MobileView = 'main' | 'sidebar' +const useIsDesktop = () => { + const [isDesktop, setIsDesktop] = useState(true) + useEffect(() => { + const mq = window.matchMedia('(min-width: 1280px)') + setIsDesktop(mq.matches) + const handler = (e: MediaQueryListEvent) => setIsDesktop(e.matches) + mq.addEventListener('change', handler) + return () => mq.removeEventListener('change', handler) + }, []) + return isDesktop +} + const Vehicle: NextPage = () => { const { authenticated } = useTethysApiContext() const { mapsLoaded } = useGoogleMaps() @@ -94,6 +106,7 @@ const Vehicle: NextPage = () => { } const [mobileView, setMobileView] = useState('main') + const isDesktop = useIsDesktop() const params = (router.query?.deployment ?? []) as string[] const vehicleName = params[0] @@ -452,27 +465,26 @@ const Vehicle: NextPage = () => { authenticated={authenticated} /> - {/* Desktop view */} -
-
- - - {primarySection} - - - {secondarySection} - - + {/* Single map instance: render one layout to avoid duplicate controls */} + {isDesktop ? ( +
+
+ + + {primarySection} + + + {secondarySection} + + +
-
- - {/* Mobile view (toggle between main and sidebar) */} -
-
+ ) : ( +
-
+ )}
diff --git a/packages/react-ui/src/Map/Map.tsx b/packages/react-ui/src/Map/Map.tsx index 4bd36d2c..4c939282 100644 --- a/packages/react-ui/src/Map/Map.tsx +++ b/packages/react-ui/src/Map/Map.tsx @@ -862,7 +862,7 @@ const Map = React.forwardRef( {children} - {/* TRACKDB/STATIONS CONTROLS - Now in separate Control component */} + {/* Single consolidated topleft control: TrackDB/Layers + Center/FitBounds/Markers */} ( Layers - - - {/* COORDINATE CONTROLS */} - {onRequestCoordinate || onRequestFitBounds || onToggleMarkerMode ? ( - - {onRequestCoordinate && ( - <> - + )} + {onRequestCoordinate && ( + <> + + - -
- - )} + + +
+
+ + )} - {onRequestFitBounds && ( - <> - + + - -
- - )} + + +
+
+ + )} - {onToggleMarkerMode && ( - <> - + + - -
- - )} -
- ) : null} + + + +
+ + )} + {/* MEASUREMENT CONTROLS - In a separate Control component */}