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 {
{ + push( + `/${project.slug}/?site=${geoJson.features[selectedSite].properties.id}&view=field-data` + ); setSelectedMode('location'); }} style={ @@ -47,6 +69,9 @@ export default function ProjectTabs({}: Props): ReactElement {
{ + push( + `/${project.slug}/?site=${geoJson.features[selectedSite].properties.id}&view=time-travel` + ); setSelectedMode('imagery'); }} 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, From dd7cd510a7fbc548c771607bfafd90f1b2e238a9 Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Thu, 5 Jan 2023 15:07:36 +0530 Subject: [PATCH 2/2] feature: vegetation value in query param --- src/features/projects/components/maps/ProjectTabs.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/features/projects/components/maps/ProjectTabs.tsx b/src/features/projects/components/maps/ProjectTabs.tsx index dbc69fb1c3..93f517bec1 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 { Router, useRouter } from 'next/router'; +import { 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'; @@ -30,6 +30,8 @@ export default function ProjectTabs({}: Props): ReactElement { setSelectedMode('location'); } else if (query.view === 'time-travel') { setSelectedMode('imagery'); + } else if (query.view === 'vegetation') { + setSelectedMode('vegetation'); } else { setSelectedMode('location'); } @@ -94,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={