import React from 'react'; import { Modal, ModalBody } from 'reactstrap'; import { Map, TileLayer, Marker, Popup } from 'react-leaflet'; import { prop } from 'ramda'; import * as PropTypes from 'prop-types'; import './MapModal.scss'; const propTypes = { toggle: PropTypes.func, isOpen: PropTypes.bool, title: PropTypes.string, locations: PropTypes.arrayOf(PropTypes.shape({ cityName: PropTypes.string.isRequired, latLong: PropTypes.arrayOf(PropTypes.number).isRequired, count: PropTypes.number.isRequired, })), }; const defaultProps = { locations: [], }; const OpenStreetMapTile = () => ( ); const calculateMapProps = (locations) => { if (locations.length > 1) { return { bounds: locations.map(prop('latLong')) }; } // When there's only one location, an error is thrown if trying to calculate the bounds. // When that happens, we use zoom and center as a workaround const [{ latLong: center }] = locations; return { zoom: '10', center }; }; const MapModal = ({ toggle, isOpen, title, locations }) => (

{title}

{locations.map(({ cityName, latLong, count }, index) => ( {count} visit{count > 1 ? 's' : ''} from {cityName} ))}
); MapModal.propTypes = propTypes; MapModal.defaultProps = defaultProps; export default MapModal;