diff --git a/src/features/projectsV2/ProjectSnippet/microComponents/ImageSection.tsx b/src/features/projectsV2/ProjectSnippet/microComponents/ImageSection.tsx index cef125a93..e929bf086 100644 --- a/src/features/projectsV2/ProjectSnippet/microComponents/ImageSection.tsx +++ b/src/features/projectsV2/ProjectSnippet/microComponents/ImageSection.tsx @@ -41,9 +41,7 @@ const ImageSection = (props: ImageSectionProps) => { const isEmbed = embed === 'true'; const handleBackButton = () => { - if (setPreventShallowPush) { - setPreventShallowPush(true); - } + if (setPreventShallowPush) setPreventShallowPush(true); const previousPageRoute = sessionStorage.getItem('backNavigationUrl'); const defaultRoute = `/${locale}`; diff --git a/src/features/projectsV2/ProjectsContext.tsx b/src/features/projectsV2/ProjectsContext.tsx index 3bdcc675a..d226cebae 100644 --- a/src/features/projectsV2/ProjectsContext.tsx +++ b/src/features/projectsV2/ProjectsContext.tsx @@ -314,7 +314,8 @@ export const ProjectsProvider: FC = ({ page !== 'project-details' || singleProject === null || selectedSite !== null || - (requestedPlantLocation && requestedSite) + (requestedPlantLocation && requestedSite) || + plantLocations === null ) return; @@ -353,8 +354,10 @@ export const ProjectsProvider: FC = ({ selectedPlantLocation, selectedSite, hasNoSites, + plantLocations, ]); useEffect(() => { + if (requestedPlantLocation && plantLocations === null) return; if ( !router.isReady || page !== 'project-details' || @@ -398,6 +401,7 @@ export const ProjectsProvider: FC = ({ requestedSite, router.isReady, selectedPlantLocation, + plantLocations, preventShallowPush, hasNoSites, ]); diff --git a/src/features/projectsV2/ProjectsMap/SingleProjectView.tsx b/src/features/projectsV2/ProjectsMap/SingleProjectView.tsx index 98d07e376..6702d26cf 100644 --- a/src/features/projectsV2/ProjectsMap/SingleProjectView.tsx +++ b/src/features/projectsV2/ProjectsMap/SingleProjectView.tsx @@ -17,13 +17,13 @@ interface Props { } const SingleProjectView = ({ mapRef }: Props) => { + const router = useRouter(); const { singleProject, selectedSite, selectedPlantLocation, plantLocations } = useProjects(); + const { ploc: requestedPlantLocation, site: requestedSite } = router.query; if (singleProject === null) return null; - const { isSatelliteView, handleViewStateChange, setIsSatelliteView } = useProjectsMap(); - const router = useRouter(); const sitesGeojson = useMemo(() => { return { @@ -34,7 +34,6 @@ const SingleProjectView = ({ mapRef }: Props) => { }, [singleProject?.sites]); const hasNoSites = sitesGeojson.features.length === 0; // Zoom to plant location - useEffect(() => { if (!router.isReady || selectedPlantLocation === null) return; const { geometry } = selectedPlantLocation; @@ -57,11 +56,16 @@ const SingleProjectView = ({ mapRef }: Props) => { zoomToLocation(handleViewStateChange, lon, lat, 20, 4000, mapRef); } } - }, [selectedPlantLocation, router.isReady]); + }, [selectedPlantLocation, router.isReady, requestedPlantLocation]); // Zoom to project site useEffect(() => { - if (!router.isReady || selectedPlantLocation !== null) return; + if ( + !router.isReady || + selectedPlantLocation !== null || + Boolean(requestedPlantLocation) + ) + return; if (sitesGeojson.features.length > 0 && selectedSite !== null) { zoomInToProjectSite( mapRef, @@ -72,6 +76,7 @@ const SingleProjectView = ({ mapRef }: Props) => { ); } else { const { lat: latitude, lon: longitude } = singleProject.coordinates; + if (!(singleProject.sites?.length === 0)) return; if (typeof latitude === 'number' && typeof longitude === 'number') { // Zoom into the project location that has no site @@ -85,9 +90,17 @@ const SingleProjectView = ({ mapRef }: Props) => { ); } } - }, [selectedSite, sitesGeojson, router.isReady, selectedPlantLocation]); + }, [ + selectedSite, + sitesGeojson, + router.isReady, + selectedPlantLocation, + requestedPlantLocation, + requestedSite, + ]); useEffect(() => { + if (plantLocations === null) return; const hasNoPlantLocations = !plantLocations?.length; const isSingleProjectLocation = hasNoPlantLocations && hasNoSites; // Satellite view will be: diff --git a/src/utils/projectV2.ts b/src/utils/projectV2.ts index 099d5d3d5..b1daa38f4 100644 --- a/src/utils/projectV2.ts +++ b/src/utils/projectV2.ts @@ -251,14 +251,12 @@ export const areMapCoordsEqual = ( export const getLocalizedPath = (path: string, locale: string): string => { // Strip query parameters if present const pathWithoutQuery = path.split('?')[0]; - // Remove trailing slash if present const cleanPath = pathWithoutQuery.endsWith('/') ? pathWithoutQuery.slice(0, -1) : pathWithoutQuery; - // Handle root path special case - if (cleanPath === '' || cleanPath === '/') { + if (cleanPath === '' || cleanPath === '/' || cleanPath === `/${locale}`) { return `/${locale}`; }