2017-09-22 12:24:15 +02:00
|
|
|
import { Components, registerComponent, registerSetting, getSetting, Strings } from 'meteor/vulcan:lib';
|
2017-05-19 14:42:43 -06:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-06-01 11:42:30 +09:00
|
|
|
import { IntlProvider, intlShape} from 'meteor/vulcan:i18n';
|
2016-12-21 12:04:43 +01:00
|
|
|
import withCurrentUser from '../containers/withCurrentUser.js';
|
2016-02-14 12:27:20 +09:00
|
|
|
|
2017-05-19 14:42:43 -06:00
|
|
|
class App extends PureComponent {
|
2016-03-24 18:17:35 +09:00
|
|
|
|
2016-06-09 17:42:20 +09:00
|
|
|
getLocale() {
|
2017-05-19 14:42:43 -06:00
|
|
|
return getSetting('locale', 'en');
|
2016-06-09 17:42:20 +09:00
|
|
|
}
|
|
|
|
|
2016-03-27 13:04:21 +09:00
|
|
|
getChildContext() {
|
2016-06-09 17:42:20 +09:00
|
|
|
|
2016-12-12 15:10:53 +09:00
|
|
|
const messages = Strings[this.getLocale()] || {};
|
2016-06-09 20:45:58 +09:00
|
|
|
const intlProvider = new IntlProvider({locale: this.getLocale()}, messages);
|
2017-05-19 14:42:43 -06:00
|
|
|
const { intl } = intlProvider.getChildContext();
|
2016-03-24 18:17:35 +09:00
|
|
|
return {
|
2016-06-09 17:42:20 +09:00
|
|
|
intl: intl
|
2016-03-24 18:17:35 +09:00
|
|
|
};
|
2016-03-27 13:04:21 +09:00
|
|
|
}
|
2016-02-14 12:27:20 +09:00
|
|
|
|
|
|
|
render() {
|
2017-06-14 09:53:42 +09:00
|
|
|
|
|
|
|
const currentRoute = _.last(this.props.routes);
|
|
|
|
const LayoutComponent = currentRoute.layoutName ? Components[currentRoute.layoutName] : Components.Layout;
|
|
|
|
|
2016-06-16 10:43:25 +09:00
|
|
|
return (
|
2016-12-12 15:10:53 +09:00
|
|
|
<IntlProvider locale={this.getLocale()} messages={Strings[this.getLocale()]}>
|
2017-06-14 09:53:42 +09:00
|
|
|
<div>
|
|
|
|
<Components.HeadTags />
|
|
|
|
<LayoutComponent {...this.props} currentRoute={currentRoute}>
|
2017-08-31 12:54:09 +09:00
|
|
|
{ this.props.currentUserLoading ? <Components.Loading /> : (this.props.children ? this.props.children : <Components.Welcome />) }
|
2017-06-14 09:53:42 +09:00
|
|
|
</LayoutComponent>
|
|
|
|
</div>
|
2016-06-16 10:43:25 +09:00
|
|
|
</IntlProvider>
|
2017-05-19 14:42:43 -06:00
|
|
|
);
|
2016-02-14 12:27:20 +09:00
|
|
|
}
|
2016-03-27 13:04:21 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
App.propTypes = {
|
2017-05-23 08:42:28 -06:00
|
|
|
currentUserLoading: PropTypes.bool,
|
2016-03-27 13:04:21 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
App.childContextTypes = {
|
2016-11-03 14:39:27 +09:00
|
|
|
intl: intlShape,
|
2016-03-27 13:04:21 +09:00
|
|
|
}
|
2016-02-16 15:40:37 +09:00
|
|
|
|
2017-01-18 12:51:10 +01:00
|
|
|
App.displayName = 'App';
|
|
|
|
|
2016-12-21 12:04:43 +01:00
|
|
|
registerComponent('App', App, withCurrentUser);
|
2016-11-27 19:12:54 +09:00
|
|
|
|
2016-12-21 12:04:43 +01:00
|
|
|
export default App;
|