Skip to content

Commit

Permalink
Update map view only if necessery and add aria-label to each marker
Browse files Browse the repository at this point in the history
  • Loading branch information
sSwiergosz committed Sep 24, 2024
1 parent 1e6e808 commit a9b95f0
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/nursery-nav/src/components/MapPin/MapPin.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { useEffect } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { useNavigate, generatePath } from 'react-router-dom';
import { Marker, useMap } from 'react-leaflet';
import { Crib } from '@mui/icons-material';

import { divIcon } from 'leaflet';
import { renderToStaticMarkup } from 'react-dom/server';
import { Crib } from '@mui/icons-material';

import { InstitutionType } from '../../shared/nursery.interface';
import './MapPin.css';
import { useNavigate, generatePath } from 'react-router-dom';
import PathConstants from '../../shared/pathConstants';

import './MapPin.css';

export interface MapPinProps {
institutionType: InstitutionType;
id: number;
Expand All @@ -20,18 +24,20 @@ export default function MapPin(props: MapPinProps) {
const map = useMap();
const navigate = useNavigate();

if (props.selectedLocationLat !== undefined && props.selectedLocationLon !== undefined) {
map.setView([props.selectedLocationLat, props.selectedLocationLon], 18, {
animate: true
});
}
// Update map view only if necessary
useEffect(() => {
if (props.selectedLocationLat !== undefined && props.selectedLocationLon !== undefined) {
map.setView([props.selectedLocationLat, props.selectedLocationLon], 18, { animate: true });
}
}, [props.selectedLocationLat, props.selectedLocationLon, map]);

const position: [number, number] = [props.latitude, props.longitude];
const institutionType = props.institutionType === InstitutionType.NURSERY ? 'nursery' : 'childclub';
const iconBackgroundColor = `map-pin-icon map-pin-icon-${institutionType}`;

return (
<Marker
aria-label={`Details for ${institutionType} with ID ${props.id}`}
eventHandlers={{
click: () => {
navigate(generatePath(PathConstants.INSTITUTION_DETAILS, { id: props.id }));
Expand Down

0 comments on commit a9b95f0

Please sign in to comment.