Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add view query param to visit satellite view #1631

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pages/[p].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
);
Expand Down
33 changes: 29 additions & 4 deletions src/features/projects/components/maps/ProjectTabs.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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'
Expand All @@ -29,6 +48,9 @@ export default function ProjectTabs({}: Props): ReactElement {
<div className={containerClasses}>
<div
onClick={() => {
push(
`/${project.slug}/?site=${geoJson.features[selectedSite].properties.id}&view=field-data`
);
setSelectedMode('location');
}}
style={
Expand All @@ -47,6 +69,9 @@ export default function ProjectTabs({}: Props): ReactElement {
</div>
<div
onClick={() => {
push(
`/${project.slug}/?site=${geoJson.features[selectedSite].properties.id}&view=time-travel`
);
setSelectedMode('imagery');
}}
style={
Expand Down
1 change: 0 additions & 1 deletion src/features/projects/screens/SingleProjectDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ function SingleProjectDetails({}: Props): ReactElement {
project,
geoJson,
rasterData,
selectedMode,
hoveredPl,
selectedPl,
setHoveredPl,
Expand Down