From 1bded11bfb24bb4d3e24b149f50200aec7c774d0 Mon Sep 17 00:00:00 2001 From: Tom Caiger Date: Fri, 18 Oct 2024 16:40:00 +1300 Subject: [PATCH] Update useDefaultMapOverlay.ts --- .../src/features/Map/utils/useDefaultMapOverlay.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/tupaia-web/src/features/Map/utils/useDefaultMapOverlay.ts b/packages/tupaia-web/src/features/Map/utils/useDefaultMapOverlay.ts index 8b5e684e49..dcc0144c4a 100644 --- a/packages/tupaia-web/src/features/Map/utils/useDefaultMapOverlay.ts +++ b/packages/tupaia-web/src/features/Map/utils/useDefaultMapOverlay.ts @@ -5,7 +5,7 @@ import { useEffect } from 'react'; import { useQueryClient } from '@tanstack/react-query'; -import { useLocation, useNavigate, useSearchParams } from 'react-router-dom'; +import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom'; import { useMapOverlays, useProject } from '../../../api/queries'; import { DEFAULT_MAP_OVERLAY_ID, @@ -18,6 +18,7 @@ import { EntityCode, ProjectCode } from '../../../types'; export const useDefaultMapOverlay = (projectCode?: ProjectCode, entityCode?: EntityCode) => { const queryClient = useQueryClient(); const navigate = useNavigate(); + const { dashboardName } = useParams(); const location = useLocation(); const [urlSearchParams] = useSearchParams(); const { data: project } = useProject(projectCode); @@ -71,6 +72,7 @@ export const useDefaultMapOverlay = (projectCode?: ProjectCode, entityCode?: Ent } const defaultOverlayCode = getDefaultOverlayCode(); + if (defaultOverlayCode) { urlSearchParams.set(URL_SEARCH_PARAMS.MAP_OVERLAY, defaultOverlayCode as string); } @@ -83,5 +85,6 @@ export const useDefaultMapOverlay = (projectCode?: ProjectCode, entityCode?: Ent ...location, search: urlSearchParams.toString(), }); - }, [JSON.stringify(mapOverlaysByCode), project, selectedMapOverlay]); + }, [JSON.stringify(mapOverlaysByCode), project, selectedMapOverlay, dashboardName]); + // include dashboardName in the dependencies to ensure that the default overlay is updated when the dashboard changes };