Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions src/features/common/Layout/ProjectPropsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export const ProjectPropsContext = React.createContext({
setPlantLocations: (value: []) => {},
selectedPl: {},
setSelectedPl: (value: {}) => {},
samplePlantLocation: {},
setSamplePlantLocation: (value: {}) => {},
Comment thread
mohitb35 marked this conversation as resolved.
zoomLevel: 1,
setZoomLevel: (value: number) => {},
satellite: false,
Expand Down Expand Up @@ -88,6 +90,7 @@ function ProjectPropsProvider({ children }: any): ReactElement {
const [project, setProject] = React.useState(null);
const [plantLocations, setPlantLocations] = React.useState(null);
const [selectedPl, setSelectedPl] = React.useState(null);
const [samplePlantLocation, setSamplePlantLocation] = React.useState(null);
const [zoomLevel, setZoomLevel] = React.useState(1);
const [showProjects, setShowProjects] = React.useState(true);
const [showSingleProject, setShowSingleProject] = React.useState(false);
Expand Down Expand Up @@ -281,6 +284,8 @@ function ProjectPropsProvider({ children }: any): ReactElement {
setPlantLocations,
selectedPl,
setSelectedPl,
samplePlantLocation,
setSamplePlantLocation,
zoomLevel,
setZoomLevel,
satellite,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ interface Props {
export default function PlantLocationDetails({
plantLocation,
}: Props): ReactElement {
const { setSelectedPl, plantLocations } =
React.useContext(ProjectPropsContext);
const {
setSelectedPl,
plantLocations,
setSamplePlantLocation,
setHoveredPl,
} = React.useContext(ProjectPropsContext);
const { t, i18n } = useTranslation(['maps']);
const [treeCount, setTreeCount] = React.useState(1);
const [plantationArea, setPlantationArea] = React.useState(0);
Expand Down Expand Up @@ -93,6 +97,7 @@ export default function PlantLocationDetails({
}, [plantLocation]);

const openSampleTree = (id: any) => {
setHoveredPl(null);
if (plantLocation && plantLocation.samplePlantLocations) {
for (const key in plantLocation.samplePlantLocations) {
if (
Expand All @@ -102,7 +107,8 @@ export default function PlantLocationDetails({
)
) {
const element = plantLocation.samplePlantLocations[key];
if (element.id === id) setSelectedPl(element);

if (element.id === id) setSamplePlantLocation(element);
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/features/projects/components/ProjectsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export default function ProjectsMap(): ReactElement {
hoveredPl,
setIsPolygonMenuOpen,
setFilterOpen,
setSamplePlantLocation,
samplePlantLocation,
Comment thread
mohitb35 marked this conversation as resolved.
} = React.useContext(ProjectPropsContext);

const { t } = useTranslation(['maps']);
Expand Down Expand Up @@ -92,8 +94,7 @@ export default function ProjectsMap(): ReactElement {
};

const onMapClick = (e: MapEvent) => {
setSelectedPl(null);
setHoveredPl(null);
setSamplePlantLocation(null);
setPopupData({ ...popupData, show: false });
setIsPolygonMenuOpen(false);
setFilterOpen(false);
Expand Down Expand Up @@ -167,7 +168,7 @@ export default function ProjectsMap(): ReactElement {
onViewportChange={_onViewportChange}
onStateChange={_onStateChange}
onClick={onMapClick}
onHover={plIds ? onMapHover : undefined}
onHover={onMapHover}
onLoad={() => setLoaded(true)}
interactiveLayerIds={plIds ? plIds : undefined}
>
Expand Down Expand Up @@ -204,7 +205,11 @@ export default function ProjectsMap(): ReactElement {
offsetTop={-5}
tipSize={0}
>
<div className={styles.clickForDetails}>{t('clickForDetails')}</div>
{hoveredPl?.hid && selectedPl?.hid !== hoveredPl?.hid && (
<div className={styles.clickForDetails}>
{t('clickForDetails')}
</div>
)}
</Popup>
)}
</MapGL>
Expand Down
2 changes: 1 addition & 1 deletion src/features/projects/components/maps/Location.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Layer, Marker, Source } from 'react-map-gl';
import { Marker } from 'react-map-gl';
import styles from '../../styles/ProjectsMap.module.scss';
import ProjectPolygon from './ProjectPolygon';

Expand Down
8 changes: 4 additions & 4 deletions src/features/projects/components/maps/PlantLocations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { ReactElement } from 'react';
import { Layer, Marker } from 'react-map-gl';
import { Source } from 'react-map-gl';
import { ProjectPropsContext } from '../../../common/Layout/ProjectPropsContext';
import { useRouter } from 'next/router';
import styles from '../../styles/PlantLocation.module.scss';
import * as turf from '@turf/turf';
import { localizedAbbreviatedNumber } from '../../../../utils/getFormattedNumber';
Expand All @@ -11,7 +10,6 @@ import { useTranslation } from 'next-i18next';
interface Props {}

export default function PlantLocations({}: Props): ReactElement {
const router = useRouter();
const {
plantLocations,
hoveredPl,
Expand All @@ -20,12 +18,14 @@ export default function PlantLocations({}: Props): ReactElement {
setHoveredPl,
viewport,
satellite,
setSamplePlantLocation,
samplePlantLocation,
} = React.useContext(ProjectPropsContext);

const { i18n, t } = useTranslation(['maps', 'common']);

const openPl = (pl: any) => {
setSelectedPl(pl);
setSamplePlantLocation(pl);
};

const onHover = (pl: Object) => {
Expand Down Expand Up @@ -186,7 +186,7 @@ export default function PlantLocations({}: Props): ReactElement {
<div
key={`${spl.id}-marker`}
className={`${styles.single} ${
spl.id === selectedPl?.id
spl.hid === samplePlantLocation?.hid
? styles.singleSelected
: ''
}`}
Expand Down
12 changes: 8 additions & 4 deletions src/features/projects/components/maps/Project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function Project({
setRasterData,
isMobile,
setSiteViewPort,
samplePlantLocation,
Comment thread
mohitb35 marked this conversation as resolved.
} = React.useContext(ProjectPropsContext);

const { handleError } = React.useContext(ErrorHandlingContext);
Expand All @@ -52,13 +53,15 @@ export default function Project({
}

React.useEffect(() => {
if (plantLocations && selectedPl) {
setPlantPolygonCoordinates(selectedPl?.geometry.coordinates[0]);
if (!selectedPl?.parent) {
Comment thread
mohitb35 marked this conversation as resolved.
if (plantLocations && selectedPl) {
setPlantPolygonCoordinates(selectedPl?.geometry.coordinates[0]);
}
}
}, [router, selectedPl, plantLocations]);
}, [selectedPl]);

React.useEffect(() => {
if (selectedPl && plantPolygonCoordinates) {
if (selectedPl && plantPolygonCoordinates && !selectedPl?.parent) {
router.push(`/${project.slug}?ploc=${selectedPl?.hid}`);
}
}, [selectedPl, plantPolygonCoordinates]);
Expand All @@ -78,6 +81,7 @@ export default function Project({
4000
);
} else if (
!selectedPl?.parent &&
plantPolygonCoordinates &&
plantLocations &&
router.query.ploc &&
Expand Down
7 changes: 6 additions & 1 deletion src/features/projects/screens/SingleProjectDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function SingleProjectDetails({}: Props): ReactElement {
selectedPl,
setHoveredPl,
setSelectedPl,
samplePlantLocation,
} = useContext(ProjectPropsContext);
const screenWidth = window.innerWidth;
const screenHeight = window.innerHeight;
Expand Down Expand Up @@ -82,7 +83,11 @@ function SingleProjectDetails({}: Props): ReactElement {
};

const ProjectProps = {
plantLocation: hoveredPl ? hoveredPl : selectedPl,
plantLocation: hoveredPl
? hoveredPl
: samplePlantLocation
? samplePlantLocation
: selectedPl,
};

const goBack = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/features/projects/styles/PlantLocation.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
position: absolute;
z-index: 1;
&.singleSelected {
background-color: rgba(0, 122, 73, 1);
background-color: rgba(0, 122, 73, 1);
}
}

Expand Down