import { useRef, useState } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faMapMarkedAlt as mapIcon } from '@fortawesome/free-solid-svg-icons'; import { Dropdown, DropdownItem, DropdownMenu, UncontrolledTooltip } from 'reactstrap'; import { useToggle } from '../../utils/helpers/hooks'; import { CityStats } from '../types'; import MapModal from './MapModal'; import './OpenMapModalBtn.scss'; interface OpenMapModalBtnProps { modalTitle: string; activeCities: string[]; locations?: CityStats[]; } const OpenMapModalBtn = ({ modalTitle, activeCities, locations = [] }: OpenMapModalBtnProps) => { const [ mapIsOpened, , openMap, closeMap ] = useToggle(); const [ dropdownIsOpened, toggleDropdown, openDropdown ] = useToggle(); const [ locationsToShow, setLocationsToShow ] = useState([]); const buttonRef = useRef(); const filterLocations = (cities: CityStats[]) => cities.filter(({ cityName }) => activeCities.includes(cityName)); const onClick = () => { if (!activeCities) { setLocationsToShow(locations); openMap(); return; } openDropdown(); }; const openMapWithLocations = (filtered: boolean) => () => { setLocationsToShow(filtered ? filterLocations(locations) : locations); openMap(); }; return ( <> buttonRef.current) as any}>Show in map Show all locations Show locations in current page ); }; export default OpenMapModalBtn;