Skip to content

Commit

Permalink
Update useDefaultMapOverlay.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
tcaiger committed Oct 18, 2024
1 parent aa59c07 commit 1bded11
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
};

0 comments on commit 1bded11

Please sign in to comment.