Skip to content

Commit

Permalink
Merge branch 'feat/show-wind-points-on-map' into add-lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ericboucher authored Dec 8, 2024
2 parents 80b31c5 + e05b74b commit 72874c7
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AAStormLandfallPopup component renders as expected 1`] = `
<div>
<div
class="makeStyles-itemsContainer-2"
>
<mock-typography
classname="makeStyles-text-4 makeStyles-title-5"
variant="body1"
>
Report date:
2024-03-01 6p.m.
</mock-typography>
<div
class="makeStyles-itemContainer-3"
>
<mock-typography
classname="makeStyles-text-4"
variant="body1"
>
landfall
<span
class="makeStyles-block-1"
>
estimated time
</span>
</mock-typography>
<mock-typography
classname="makeStyles-text-4 makeStyles-textAlignRight-6"
variant="body1"
>
12-03-2025
<span
class="makeStyles-block-1"
>
06:00 - 12:00
</span>
</mock-typography>
</div>
<div
class="makeStyles-itemContainer-3"
>
<mock-typography
classname="makeStyles-text-4"
variant="body1"
>
landfall estimated
<span
class="makeStyles-block-1"
>
leadtime
</span>
</mock-typography>
<mock-typography
classname="makeStyles-text-4 makeStyles-textAlignRight-6"
variant="body1"
>
8 - 12 hrs
</mock-typography>
</div>
<div
class="makeStyles-itemContainer-3"
>
<mock-typography
classname="makeStyles-text-4"
variant="body1"
>
District impacted
<span
class="makeStyles-block-1"
>
by landfall
</span>
</mock-typography>
<mock-typography
classname="makeStyles-text-4 makeStyles-textAlignRight-6"
variant="body1"
>
Inhassoro
</mock-typography>
</div>
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { render } from '@testing-library/react';
import PopupContent from '.';

describe('AAStormLandfallPopup component', () => {
it('renders as expected', () => {
const reportDate = '2024-03-01 6p.m.';
const landfallInfo = {
landfall_time: ['2024-03-12 00:00:00', '2024-03-12 06:00:00'],
landfall_impact_district: 'Inhassoro',
landfall_impact_intensity: [
'severe tropical storm',
'moderate tropical storm',
],
};
const { container } = render(
<PopupContent reportDate={reportDate} landfallInfo={landfallInfo} />,
);
expect(container).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { createStyles, makeStyles, Typography } from '@material-ui/core';

function PopupContent({ landfallInfo, reportDate }: PopupContentProps) {
const classes = useStyles();

return (
<div className={classes.itemsContainer}>
<Typography
variant="body1"
className={`${classes.text} ${classes.title}`}
>
Report date: {reportDate}
</Typography>
<div className={classes.itemContainer}>
<Typography variant="body1" className={classes.text}>
landfall <span className={classes.block}>estimated time</span>
</Typography>
<Typography
variant="body1"
className={`${classes.text} ${classes.textAlignRight}`}
>
12-03-2025
<span className={classes.block}>06:00 - 12:00</span>
</Typography>
</div>
<div className={classes.itemContainer}>
<Typography variant="body1" className={classes.text}>
landfall estimated
<span className={classes.block}>leadtime</span>
</Typography>
<Typography
variant="body1"
className={`${classes.text} ${classes.textAlignRight}`}
>
8 - 12 hrs
</Typography>
</div>
<div className={classes.itemContainer}>
<Typography variant="body1" className={classes.text}>
District impacted
<span className={classes.block}>by landfall</span>
</Typography>
<Typography
variant="body1"
className={`${classes.text} ${classes.textAlignRight}`}
>
{landfallInfo.landfall_impact_district}
</Typography>
</div>
</div>
);
}

const useStyles = makeStyles(() =>
createStyles({
block: {
display: 'block',
},
itemsContainer: {
display: 'flex',
flexDirection: 'column',
gap: '2px',
},
itemContainer: {
display: 'flex',
justifyContent: 'space-between',
padding: '8px',
background: '#FFFFFF',
},
text: {
fontSize: '14px',
lineHeight: '18px',
fontWeight: 400,
},
title: {
fontWeight: 700,
padding: '2px 0px 2px 8px',
},
textAlignRight: {
textAlign: 'right',
},
}),
);

export interface LandfallInfo {
landfall_time: string[];
landfall_impact_district: string;
landfall_impact_intensity: string[];
}

interface PopupContentProps {
landfallInfo: LandfallInfo;
reportDate: string;
}

export default PopupContent;
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { createStyles, makeStyles, Typography } from '@material-ui/core';
import { createStyles, makeStyles } from '@material-ui/core';
import { Point } from 'geojson';
import { Popup } from 'react-map-gl/maplibre';
import PopupContent, { LandfallInfo } from './PopupContent';

function AAStormLandfallPopup({
reportDate,
point,
landfallInfo,
onClose,
landfallInfo,
reportDate,
}: AAStormLandfallPopupProps) {
const classes = useStyles();

Expand All @@ -25,59 +26,11 @@ function AAStormLandfallPopup({
className={classes.popup}
maxWidth="280px"
>
<div className={classes.itemsContainer}>
<Typography
variant="body1"
className={`${classes.text} ${classes.title}`}
>
Report date: {reportDate}
</Typography>
<div className={classes.itemContainer}>
<Typography variant="body1" className={classes.text}>
landfall <span className={classes.block}>estimated time</span>
</Typography>
<Typography
variant="body1"
className={`${classes.text} ${classes.textAlignRight}`}
>
12-03-2025
<span className={classes.block}>06:00 - 12:00</span>
</Typography>
</div>
<div className={classes.itemContainer}>
<Typography variant="body1" className={classes.text}>
landfall estimated
<span className={classes.block}>leadtime</span>
</Typography>
<Typography
variant="body1"
className={`${classes.text} ${classes.textAlignRight}`}
>
8 - 12 hrs
</Typography>
</div>
<div className={classes.itemContainer}>
<Typography variant="body1" className={classes.text}>
District impacted
<span className={classes.block}>by landfall</span>
</Typography>
<Typography
variant="body1"
className={`${classes.text} ${classes.textAlignRight}`}
>
{landfallInfo.landfall_impact_district}
</Typography>
</div>
</div>
<PopupContent landfallInfo={landfallInfo} reportDate={reportDate} />
</Popup>
);
}

interface LandfallInfo {
landfall_time: string[];
landfall_impact_district: string;
landfall_impact_intensity: string[];
}
interface AAStormLandfallPopupProps {
point: Point;
landfallInfo: LandfallInfo;
Expand All @@ -100,32 +53,7 @@ const useStyles = makeStyles(() =>
borderRightWidth: '8px',
},
},
block: {
display: 'block',
},
itemsContainer: {
display: 'flex',
flexDirection: 'column',
gap: '2px',
},
itemContainer: {
display: 'flex',
justifyContent: 'space-between',
padding: '8px',
background: '#FFFFFF',
},
text: {
fontSize: '14px',
lineHeight: '18px',
fontWeight: 400,
},
title: {
fontWeight: 700,
padding: '2px 0px 2px 8px',
},
textAlignRight: {
textAlign: 'right',
},
}),
);

export default AAStormLandfallPopup;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { AnticipatoryActionLayerProps } from 'config/types';
import { useDefaultDate } from 'utils/useDefaultDate';
import {
Expand All @@ -16,7 +16,7 @@ import moderateStorm from '../../../../../public/images/anticipatory-action-stor
import overland from '../../../../../public/images/anticipatory-action-storm/overland.png';
import severeTropicalStorm from '../../../../../public/images/anticipatory-action-storm/severe-tropical-storm.png';
import tropicalCyclone from '../../../../../public/images/anticipatory-action-storm/tropical-cyclone.png';
// import intensiveCyclone from '../../../../../public/images/anticipatory-action-storm/very-intensive-tropical-cycloone.png';
import veryIntensiveCyclone from '../../../../../public/images/anticipatory-action-storm/very-intensive-tropical-cyclone.png';

const AnticipatoryActionStormLayer = React.memo(
({ layer, mapRef }: AnticipatoryActionStormLayerProps) => {
Expand Down Expand Up @@ -102,7 +102,7 @@ const AnticipatoryActionStormLayer = React.memo(
setSelectedFeature(null);
}

function loadImages() {
const loadImages = useCallback(() => {
const map = mapRef.getMap();

const loadImage = (url: string, name: string) => {
Expand All @@ -120,19 +120,20 @@ const AnticipatoryActionStormLayer = React.memo(
loadImage(severeTropicalStorm, 'severe-tropical-storm');
loadImage(tropicalCyclone, 'tropical-cyclone');
loadImage(overland, 'overland');
}
loadImage(veryIntensiveCyclone, 'very-intensive-tropical-cyclone');
}, [mapRef]);

useEffect(() => {
loadImages();
});
}, [loadImages]);

// Display a pointer cursor when hovering over the wind points
useEffect(() => {
const map = mapRef.getMap();

const handleMouseEnter = () => {
// eslint-disable-next-line fp/no-mutation
map.getCanvas().style.cursor = 'pointer';
map.getCanvas().style.cursor = 'cursor';
};

const handleMouseLeave = () => {
Expand All @@ -149,7 +150,7 @@ const AnticipatoryActionStormLayer = React.memo(
map.off('mouseleave', 'aa-storm-wind-points-layer', handleMouseLeave);
map.off('click', 'aa-storm-wind-points-layer', onWindPointsClicked);
};
});
}, [mapRef]);

return (
<>
Expand Down

0 comments on commit 72874c7

Please sign in to comment.