diff --git a/client/main.html b/client/main.html index 99e51f8..2b1deb3 100644 --- a/client/main.html +++ b/client/main.html @@ -6,6 +6,10 @@ + + + + diff --git a/imports/startup/client/Gkeys.js b/imports/startup/client/Gkeys.js index 12a48a5..672a573 100644 --- a/imports/startup/client/Gkeys.js +++ b/imports/startup/client/Gkeys.js @@ -1,47 +1,52 @@ -import React from 'react'; import { Meteor } from 'meteor/meteor'; +import { ReactiveVar } from 'meteor/reactive-var'; import i18n from 'i18next'; - -const gmapkey = new ReactiveVar(); - -Meteor.startup(function() { - Meteor.call('getMapKey', function (error, key) { - if (typeof key !== 'undefined') { - // console.log(key); - gmapkey.set(key); - } else { - callback(error, null) - } - }) -}); +import { Tracker } from 'meteor/tracker'; class GkeysC { constructor() { - this.state = { init: false }; + this.gmapkey = new ReactiveVar(null); + const self = this; + this.callbacks = []; + Meteor.startup(() => { + Meteor.call('getMapKey', (error, key) => { + const script = document.createElement('script'); + script.type = 'text/javascript'; + script.onload = () => { + self.gmapkey.set(key); + console.log('GMaps script just loaded'); + self.doCallbacks(key); + }; + // https://stackoverflow.com/questions/28130114/google-maps-places-autocomplete-language-output + script.src = `https://maps.googleapis.com/maps/api/js?key=${key}&libraries=places&language=${i18n.language}`; + document.body.appendChild(script); + }); + }); + } + + doCallbacks(key) { + for (let i = 0; i < this.callbacks.length; i += 1) { + this.callbacks[i](null, key); + } + this.callbacks = []; } load(callback) { - if (this.state.init) { - // already loaded - callback(null, gmapkey.get()); - } else { - this.state.init = true; - Meteor.autorun(function() { - var key = gmapkey.get(); - if (typeof key !== 'undefined') { - var script = document.createElement('script'); - script.type = 'text/javascript'; - script.onload = function () { - // console.log(key); - callback(null, key); - }.bind(this); - // https://stackoverflow.com/questions/28130114/google-maps-places-autocomplete-language-output - script.src = `https://maps.googleapis.com/maps/api/js?key=${key}&libraries=places&language=${i18n.language}` - document.body.appendChild(script); - } - }.bind(this)); - } + this.callbacks.push(callback); + Tracker.autorun((computation) => { + const key = this.gmapkey.get(); + if (key) { + // already loaded + console.log(`GMaps already loaded: ${key}`); + this.doCallbacks(key); + computation.stop(); + } else { + console.log('Waiting for the gkey'); + } + }); } } -export let Gkeys = new GkeysC(); +const Gkeys = new GkeysC(); + +export default Gkeys; diff --git a/imports/startup/client/i18n.js b/imports/startup/client/i18n.js index 3bd05a6..a96010e 100644 --- a/imports/startup/client/i18n.js +++ b/imports/startup/client/i18n.js @@ -37,7 +37,8 @@ const cacheOptions = { i18nOpts.cache = cacheOptions; i18nOpts.detection = detectorOptions; i18nOpts.react = { - wait: true + wait: true, + defaultTransParent: 'span' // https://react.i18next.com/components/i18next-instance.ht /* bindI18n: 'languageChanged loaded', bindStore: 'added removed', diff --git a/imports/ui/components/AuthenticatedNavigation/AuthenticatedNavigation.js b/imports/ui/components/AuthenticatedNavigation/AuthenticatedNavigation.js index b7a4c2e..8d10033 100644 --- a/imports/ui/components/AuthenticatedNavigation/AuthenticatedNavigation.js +++ b/imports/ui/components/AuthenticatedNavigation/AuthenticatedNavigation.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { withRouter } from 'react-router-dom'; import { LinkContainer } from 'react-router-bootstrap'; -import { Nav, NavDropdown } from 'react-bootstrap'; +/* import { Nav, NavDropdown } from 'react-bootstrap'; */ import { translate, Trans } from 'react-i18next'; /* FIXME: @@ -13,26 +13,25 @@ import { translate, Trans } from 'react-i18next'; */ import NavItem from '../NavItem/NavItem'; -import { Meteor } from 'meteor/meteor'; - const AuthenticatedNavigation = ({ name, history, props }) => ( -