diff --git a/pages/[p].tsx b/pages/[p].tsx index 5feb78e8f9..cc4d3c0a0d 100644 --- a/pages/[p].tsx +++ b/pages/[p].tsx @@ -118,7 +118,7 @@ export default function Donate({ React.useEffect(() => { if (geoJson && !router.query.site && !router.query.ploc) { router.push( - `/${project.slug}?site=${geoJson.features[0].properties.id}`, + `/${project?.slug}?site=${geoJson.features[0].properties.id}&view=site-data`, undefined, { shallow: true } ); diff --git a/src/features/projects/components/maps/ProjectTabs.tsx b/src/features/projects/components/maps/ProjectTabs.tsx index 37ef4e6985..93f517bec1 100644 --- a/src/features/projects/components/maps/ProjectTabs.tsx +++ b/src/features/projects/components/maps/ProjectTabs.tsx @@ -12,10 +12,31 @@ interface Props {} export default function ProjectTabs({}: Props): ReactElement { const { embed, showProjectDetails } = React.useContext(ParamsContext); - const { pathname } = useRouter(); + const { pathname, query, push } = useRouter(); const { t } = useTranslation(['maps']); - const { selectedMode, setSelectedMode, rasterData } = - React.useContext(ProjectPropsContext); + const { + selectedMode, + setSelectedMode, + rasterData, + selectedSite, + project, + geoJson, + plantLocations, + } = React.useContext(ProjectPropsContext); + + React.useEffect(() => { + if (plantLocations) { + if (query.view === 'field-data') { + setSelectedMode('location'); + } else if (query.view === 'time-travel') { + setSelectedMode('imagery'); + } else if (query.view === 'vegetation') { + setSelectedMode('vegetation'); + } else { + setSelectedMode('location'); + } + } + }, [plantLocations, query.view]); const containerClasses = embed !== 'true' @@ -29,6 +50,9 @@ export default function ProjectTabs({}: Props): ReactElement {
{ + push( + `/${project.slug}/?site=${geoJson.features[selectedSite].properties.id}&view=field-data` + ); setSelectedMode('location'); }} style={ @@ -47,6 +71,9 @@ export default function ProjectTabs({}: Props): ReactElement {
{ + push( + `/${project.slug}/?site=${geoJson.features[selectedSite].properties.id}&view=time-travel` + ); setSelectedMode('imagery'); }} style={ @@ -69,6 +96,9 @@ export default function ProjectTabs({}: Props): ReactElement { {rasterData.evi ? (
{ + push( + `/${project.slug}/?site=${geoJson.features[selectedSite].properties.id}&view=vegetation` + ); setSelectedMode('vegetation'); }} style={ diff --git a/src/features/projects/screens/SingleProjectDetails.tsx b/src/features/projects/screens/SingleProjectDetails.tsx index 603184aa04..547a70cda1 100644 --- a/src/features/projects/screens/SingleProjectDetails.tsx +++ b/src/features/projects/screens/SingleProjectDetails.tsx @@ -44,7 +44,6 @@ function SingleProjectDetails({}: Props): ReactElement { project, geoJson, rasterData, - selectedMode, hoveredPl, selectedPl, setHoveredPl,