Vulcan/packages/nova-base-components/lib/common/App.jsx

56 lines
1.4 KiB
React
Raw Normal View History

2016-08-08 11:18:21 +09:00
import Telescope from 'meteor/nova:lib';
import React, { PropTypes, Component } from 'react';
2016-06-09 20:45:58 +09:00
import { IntlProvider, intlShape} from 'react-intl';
import Events from "meteor/nova:events";
import { withApp } from 'meteor/nova:base-containers';
class App extends Component {
2016-03-24 18:17:35 +09:00
2016-06-09 17:42:20 +09:00
getLocale() {
2016-06-09 20:45:58 +09:00
return Telescope.settings.get("locale", "en");
2016-06-09 17:42:20 +09:00
}
getChildContext() {
2016-06-09 17:42:20 +09:00
2016-06-09 20:45:58 +09:00
const messages = Telescope.strings[this.getLocale()] || {};
const intlProvider = new IntlProvider({locale: this.getLocale()}, messages);
2016-06-09 17:42:20 +09:00
const {intl} = intlProvider.getChildContext();
2016-03-24 18:17:35 +09:00
return {
currentUser: this.props.currentUser,
actions: {call: Meteor.call},
events: Events,
2016-06-09 17:42:20 +09:00
intl: intl
2016-03-24 18:17:35 +09:00
};
}
render() {
return (
<IntlProvider locale={this.getLocale()} messages={Telescope.strings[this.getLocale()]}>
{
this.props.loading ?
<Telescope.components.AppLoading /> :
<Telescope.components.Layout>{this.props.children}</Telescope.components.Layout>
}
</IntlProvider>
)
}
}
App.propTypes = {
loading: React.PropTypes.bool,
currentUser: React.PropTypes.object,
actions: React.PropTypes.object,
events: React.PropTypes.object,
}
App.childContextTypes = {
currentUser: React.PropTypes.object,
actions: React.PropTypes.object,
events: React.PropTypes.object,
intl: intlShape,
}
module.exports = withApp(App);