From 833ec40da4c2cc9e8df11e617c271329096a737b Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Mon, 5 Dec 2022 17:33:39 +0530 Subject: [PATCH 1/2] feature: add view query param to visit satellite view --- pages/[p].tsx | 2 +- .../projects/components/maps/ProjectTabs.tsx | 33 ++++++++++++++++--- .../projects/screens/SingleProjectDetails.tsx | 1 - 3 files changed, 30 insertions(+), 6 deletions(-) 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..dbc69fb1c3 100644 --- a/src/features/projects/components/maps/ProjectTabs.tsx +++ b/src/features/projects/components/maps/ProjectTabs.tsx @@ -1,5 +1,5 @@ import React, { ReactElement } from 'react'; -import { useRouter } from 'next/router'; +import { Router, useRouter } from 'next/router'; import { useTranslation } from 'next-i18next'; import LocationIcon from '../../../../../public/assets/images/icons/LocationIcon'; import ResearchIcon from '../../../../../public/assets/images/icons/ResearchIcon'; @@ -12,10 +12,29 @@ 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 { + setSelectedMode('location'); + } + } + }, [plantLocations, query.view]); const containerClasses = embed !== 'true' @@ -29,6 +48,9 @@ export default function ProjectTabs({}: Props): ReactElement {