lml-main
Version:
This is now a mono repository published into many standalone packages.
51 lines • 1.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
const react_redux_1 = require("react-redux");
const actions_1 = require("../../google/actions");
const MAPS_TAG_ID = 'MAPS_TAG_ID';
class GoogleComponent extends React.Component {
componentDidMount() {
this.registerAuthErrorListener();
if (!this._validateApiKey()) {
this.props.mapsAuthErrorAction();
}
else {
this.createScriptTagIfMissing();
}
}
_validateApiKey() {
const { gmapsKey } = this.props;
return (typeof gmapsKey === 'string') && gmapsKey.length > 32;
}
render() {
return React.createElement("div", null);
}
apiDidLoad() {
this.props.mapsAPILoadedAction();
}
registerAuthErrorListener() {
window.gm_authFailure = (event) => {
this.props.mapsAuthErrorAction();
};
}
createScriptTagIfMissing() {
if (!document.querySelector(`#${MAPS_TAG_ID}`)) {
this.createScriptTag();
}
}
createScriptTag() {
const tag = document.createElement('script');
tag.id = MAPS_TAG_ID;
tag.src = `https://maps.googleapis.com/maps/api/js?key=${this.props.gmapsKey}`;
tag.addEventListener('load', () => this.apiDidLoad());
document.querySelector('body').appendChild(tag);
}
}
const mapStateToProps = (state, ownProps) => ({});
const mapActionsToProps = {
mapsAPILoadedAction: actions_1.mapsAPILoadedAction,
mapsAuthErrorAction: actions_1.mapsAuthErrorAction,
};
exports.Google = react_redux_1.connect(mapStateToProps, mapActionsToProps)(GoogleComponent);
//# sourceMappingURL=google.js.map