/* eslint-disable jsx-a11y/no-href */ /* eslint import/no-absolute-path: [2, { esmodule: false, commonjs: false, amd: false }] */ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { Router, Switch, Route } from 'react-router-dom'; import { Grid } from 'react-bootstrap'; import { I18nextProvider } from 'react-i18next'; import { Helmet } from 'react-helmet'; import { Meteor } from 'meteor/meteor'; import { withTracker } from 'meteor/react-meteor-data'; import { Roles } from 'meteor/alanning:roles'; // https://github.com/gadicc/meteor-blaze-react-component/ import Blaze from 'meteor/gadicc:blaze-react-component'; // i18n import i18n, { i18nReady } from '/imports/startup/client/i18n'; import '/imports/startup/client/meta'; import '/imports/startup/client/ravenLogger'; import '/imports/startup/client/geolocation'; import '/imports/startup/client/piwik-start.js'; import Reconnect from '../../components/Reconnect/Reconnect'; import Navigation from '../../components/Navigation/Navigation'; import Authenticated from '../../components/Authenticated/Authenticated'; import Public from '../../components/Public/Public'; import Index from '../../pages/Index/Index'; import Subscriptions from '../../pages/Subscriptions/Subscriptions'; import NewSubscription from '../../pages/NewSubscription/NewSubscription'; import ViewSubscription from '../../pages/ViewSubscription/ViewSubscription'; import EditSubscription from '../../pages/EditSubscription/EditSubscription'; import TestError from '../../pages/TestError/TestError'; import Signup from '../../pages/Signup/Signup'; import Auth from '../../pages/Auth/Auth'; import Login from '../../pages/Login/Login'; import Logout from '../../pages/Logout/Logout'; import Status from '../../pages/Status/Status'; import VerifyEmail from '../../pages/VerifyEmail/VerifyEmail'; import RecoverPassword from '../../pages/RecoverPassword/RecoverPassword'; import ResetPassword from '../../pages/ResetPassword/ResetPassword'; import Profile from '../../pages/Profile/Profile'; import NotFound from '../../pages/NotFound/NotFound'; import FiresMap from '../../pages/FiresMap/FiresMap'; import Fires from '../../pages/Fires/Fires'; import Sandbox from '../../pages/Sandbox/Sandbox'; import Terms from '../../pages/Terms/Terms'; import About from '../../pages/About/About'; import Privacy from '../../pages/Privacy/Privacy'; import License from '../../pages/License/License'; import Credits from '../../pages/Credits/Credits'; import ZonesMap from '../../pages/ZonesMap/ZonesMap'; import Footer from '../../components/Footer/Footer'; import Feedback from '../../components/Feedback/Feedback'; import ReSendEmail from '../../components/ReSendEmail/ReSendEmail'; import ErrorBoundary from '../../components/ErrorBoundary/ErrorBoundary'; import history from '../../components/History/History'; import '../../components/NotificationsObserver/NotificationsObserver'; import './App.scss'; class LocationListener extends Component { // https://stackoverflow.com/questions/43512450/react-router-v4-route-onchange-event static contextTypes = { router: PropTypes.object }; componentDidMount() { this.handleLocationChange(this.context.router.history.location); this.unlisten = this.context.router.history.listen(this.handleLocationChange); } componentWillUnmount() { this.unlisten(); } handleLocationChange(location) { // your staff here console.log(`----- location: '${location.pathname}'`); Meteor.Piwik.trackPage(location.pathname); // Meteor.isReadyForSpiderable = true; } render() { return this.props.children; } } const App = props => ( /* https://react.i18next.com/components/i18nextprovider.html */ { !props.loading ?
{i18n.t('AppName')} {/* */} {/* */} {/* } /> */}
: ''}
); App.defaultProps = { userId: '', emailAddress: '' }; App.propTypes = { loading: PropTypes.bool.isRequired, i18nReady: PropTypes.object.isRequired, userId: PropTypes.string, emailAddress: PropTypes.string, emailVerified: PropTypes.bool.isRequired }; const getUserName = name => ({ string: name, object: `${name.first} ${name.last}` }[typeof name]); export default withTracker(() => { const loggingIn = Meteor.loggingIn(); const user = Meteor.user(); const userId = Meteor.userId(); const loading = !Roles.subscription.ready() || !i18nReady.get(); const name = user && user.profile && user.profile.name && getUserName(user.profile.name); const emailAddress = user && user.emails && user.emails[0].address; // console.log(`i18n ready?: ${i18nReady.get()}`); return { loading, loggingIn, i18nReady, authenticated: !loggingIn && !!userId, name: name || emailAddress, roles: !loading && Roles.getRolesForUser(userId), userId, emailAddress, emailVerified: user && user.emails ? user && user.emails && user.emails[0].verified : true }; })(App);