Merge pull request #773 from sharetribe/fix-missing-googlelib-on-maps

Remove throw error when google lib is missing
This commit is contained in:
Vesa Luusua 2018-03-21 16:30:42 +02:00 committed by GitHub
commit e604234760
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 16 deletions

View file

@ -1,6 +1,9 @@
@import '../../marketplace.css';
.root {
width: 100%;
height: 100%;
background-color: var(--matterColorNegative);
}
.mapRoot {

View file

@ -55,13 +55,6 @@ const MapWithGoogleMap = withGoogleMap(props => {
});
export class Map extends Component {
componentDidMount() {
const mapsLibLoaded = window.google && window.google.maps;
if (!mapsLibLoaded) {
throw new Error('Google Maps API must be loaded for the Map component');
}
}
render() {
const {
className,
@ -88,7 +81,9 @@ export class Map extends Component {
const location = coordinatesConfig.fuzzy ? obfuscatedCenter : center;
const centerLocationForGoogleMap = { lat: location.lat, lng: location.lng };
return (
const isMapsLibLoaded = window.google && window.google.maps;
return isMapsLibLoaded ? (
<MapWithGoogleMap
containerElement={<div className={classes} onClick={this.onMapClicked} />}
mapElement={<div className={mapClasses} />}
@ -97,6 +92,8 @@ export class Map extends Component {
address={address}
coordinatesConfig={coordinatesConfig}
/>
) : (
<div className={classes} />
);
}
}

View file

@ -3,6 +3,7 @@
.root {
width: 100%;
height: 100%;
background-color: var(--matterColorNegative);
}
.mapRoot {

View file

@ -186,13 +186,6 @@ export class SearchMapComponent extends Component {
this.onMapLoadHandler = this.onMapLoadHandler.bind(this);
}
componentDidMount() {
const mapsLibLoaded = window.google && window.google.maps;
if (!mapsLibLoaded) {
throw new Error('Google Maps API must be loaded for the SearchMap component');
}
}
componentWillReceiveProps(nextProps) {
if (this.googleMap) {
const currentBounds = googleBoundsToSDKBounds(this.googleMap.getBounds());
@ -254,9 +247,11 @@ export class SearchMapComponent extends Component {
? withCoordinatesObfuscated(listingsWithLocation)
: listingsWithLocation;
const isMapsLibLoaded = window.google && window.google.maps;
// container element listens clicks so that opened SearchMapInfoCard can be closed
/* eslint-disable jsx-a11y/no-static-element-interactions */
return (
return isMapsLibLoaded ? (
<MapWithGoogleMap
containerElement={<div className={classes} onClick={this.onMapClicked} />}
mapElement={<div className={mapClasses} />}
@ -279,6 +274,8 @@ export class SearchMapComponent extends Component {
}}
zoom={zoom}
/>
) : (
<div className={classes} />
);
/* eslint-enable jsx-a11y/no-static-element-interactions */
}