import { DEFAULT_LOCATION } from '../utils/constants';

export const currentLocation = (location) => {
  return {
    type: 'CURRENT_LOCATION',
    location,
  }
}

export const nearbyLocations = (data) => {
  return {
    type: 'NEARBY_LOCATIONS',
    data,
  }
}

export const mapCenter = (position) => {
  return {
    type: 'CENTER',
    position
  }
}

export const geolocate = () => {
  return (dispatch) => {

    if ('geolocation' in navigator) {
      navigator.geolocation.getCurrentPosition((position) => {
        const { coords } = position;
        const coordinates = {
          lat: coords.latitude,
          lng: coords.longitude,
        }

        dispatch(currentLocation(coordinates));
      });
    } else {

      dispatch(currentLocation(DEFAULT_LOCATION.coordinates));
    }
  }
}

@@ -698,24 +698,66 @@
 rdinates));%0A
+        dispatch(mapCenter(coordinates));%0A
       %7D);%0A  

fix centering on map