Skip to content

Commit

Permalink
Merge pull request #327 from Code-4-Community/SK.add-map-to-tree-page
Browse files Browse the repository at this point in the history
Sk.add map to tree page
  • Loading branch information
SurabhiKeesara authored Mar 24, 2024
2 parents a9c31c3 + e816c2f commit 504ca79
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface SelectorMapDisplayProps {
readonly onMove: (pos: google.maps.LatLng) => void;
readonly site?: SiteProps;
readonly setMarker: (marker: google.maps.Marker) => void;
readonly mapHeight?: string;
}

const SelectorMapDisplay: React.FC<SelectorMapDisplayProps> = ({
Expand All @@ -29,6 +30,7 @@ const SelectorMapDisplay: React.FC<SelectorMapDisplayProps> = ({
onMove,
site,
setMarker,
mapHeight = '100%',
}) => (
<>
{asyncRequestIsComplete(neighborhoods) && asyncRequestIsComplete(sites) && (
Expand All @@ -38,6 +40,7 @@ const SelectorMapDisplay: React.FC<SelectorMapDisplayProps> = ({
onMove={onMove}
site={site}
setMarker={setMarker}
mapHeight={mapHeight}
/>
)}
{(asyncRequestIsFailed(neighborhoods) || asyncRequestIsFailed(sites)) && (
Expand Down
8 changes: 5 additions & 3 deletions src/components/mapComponents/maps/mapWithPopup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const StyledSearch = styled(Input.Search)`
}
`;

const MapDiv = styled.div`
height: 100%;
const MapDiv = styled.div<{ height: string }>`
height: ${(props) => props.height || 0};
`;

interface MapWithPopupProps {
Expand All @@ -40,6 +40,7 @@ interface MapWithPopupProps {
readonly lng: number;
readonly initMap: (mapData: InitMapData) => ReturnMapData;
readonly defaultActiveTree: BasicTreeInfo;
readonly mapHeight?: string;
}

let map: google.maps.Map;
Expand All @@ -51,6 +52,7 @@ const MapWithPopup: React.FC<PropsWithChildren<MapWithPopupProps>> = ({
lat,
lng,
initMap,
mapHeight = '100%',
defaultActiveTree,
children,
}) => {
Expand Down Expand Up @@ -222,7 +224,7 @@ const MapWithPopup: React.FC<PropsWithChildren<MapWithPopupProps>> = ({
onChange={(event) => setSearchInput(event.target.value)}
/>
</div>
<MapDiv id="map" ref={mapRef} />
<MapDiv id="map" ref={mapRef} height={mapHeight} />
<TreePopup treeInfo={activeTreeInfo} popRef={treePopupRef} />
{children}
</>
Expand Down
3 changes: 3 additions & 0 deletions src/components/mapComponents/maps/selectorMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface SelectorMapProps {
readonly onMove: (pos: google.maps.LatLng) => void;
readonly site?: SiteProps;
readonly setMarker: (marker: google.maps.Marker) => void;
readonly mapHeight?: string;
}

const SelectorMap: React.FC<SelectorMapProps> = ({
Expand All @@ -28,6 +29,7 @@ const SelectorMap: React.FC<SelectorMapProps> = ({
onMove,
site,
setMarker,
mapHeight = '100%',
}) => {
const defaultZoom = STREET_ZOOM;

Expand Down Expand Up @@ -98,6 +100,7 @@ const SelectorMap: React.FC<SelectorMapProps> = ({
lat={defaultCenter.lat}
lng={defaultCenter.lng}
initMap={setSearchMarkerAndInitSiteMap}
mapHeight={mapHeight}
defaultActiveTree={basicSite}
/>
);
Expand Down
23 changes: 22 additions & 1 deletion src/containers/treePage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import { useLocation } from 'react-router-dom';
import PageLayout from '../../components/pageLayout';
Expand Down Expand Up @@ -52,6 +52,10 @@ import { Trans, useTranslation } from 'react-i18next';
import { site } from '../../constants';
import { n } from '../../utils/stringFormat';
import TreeBenefits from '../../components/treePage/treeBenefits';
import SelectorMapDisplay from '../../components/mapComponents/mapDisplays/selectorMapDisplay';
import { round } from 'lodash';
import { LAT_LNG_PRECISION } from '../../components/forms/constants';
import { MapGeoDataReducerState } from '../../components/mapComponents/ducks/types';

const TreePageContainer = styled.div`
width: 90vw;
Expand Down Expand Up @@ -105,6 +109,8 @@ const TreePlantingRequestContainer = styled.div`
`;

interface TreeProps {
readonly neighborhoods: MapGeoDataReducerState['neighborhoodGeoData'];
readonly sites: MapGeoDataReducerState['siteGeoData'];
readonly tokens: UserAuthenticationReducerState['tokens'];
readonly siteData: SiteReducerState['siteData'];
readonly stewardship: TreeCare[];
Expand All @@ -117,6 +123,8 @@ export interface TreeParams {
}

const TreePage: React.FC<TreeProps> = ({
sites,
neighborhoods,
siteData,
stewardship,
monthYearOptions,
Expand Down Expand Up @@ -326,6 +334,17 @@ const TreePage: React.FC<TreeProps> = ({

<SiteImageCarousel />

<SelectorMapDisplay
neighborhoods={neighborhoods}
sites={sites}
// eslint-disable-next-line @typescript-eslint/no-empty-function
onMove={() => {}}
site={siteData.result}
// eslint-disable-next-line @typescript-eslint/no-empty-function
setMarker={() => {}}
mapHeight={'50%'}
/>

<TreeBenefits />
</HalfWidthContainer>
</Flex>
Expand Down Expand Up @@ -453,6 +472,8 @@ const TreePlantingRequest: React.FC = () => {

const mapStateToProps = (state: C4CState): TreeProps => {
return {
neighborhoods: state.mapGeoDataState.neighborhoodGeoData,
sites: state.mapGeoDataState.siteGeoData,
tokens: state.authenticationState.tokens,
siteData: state.siteState.siteData,
stewardship: mapStewardshipToTreeCare(
Expand Down

0 comments on commit 504ca79

Please sign in to comment.