You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.2 KiB

import React, { cloneElement } from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import { addLocaleData, IntlProvider } from 'react-intl';
import { LocaleProvider } from 'antd';
import enUS from 'antd/lib/locale-provider/en_US';
import Header from './Header';
import Footer from './Footer';
import enLocale from '../../en-US';
import cnLocale from '../../zh-CN';
import * as utils from '../utils';
if (typeof window !== 'undefined') {
/* eslint-disable global-require */
require('../../static/style');
// Expose to iframe
window.react = React;
window['react-dom'] = ReactDOM;
window.antd = require('antd');
/* eslint-enable global-require */
}
9 years ago
export default class Layout extends React.Component {
static contextTypes = {
router: PropTypes.object.isRequired,
9 years ago
}
constructor(props) {
super(props);
const pathname = props.location.pathname;
const appLocale = utils.isZhCN(pathname) ? cnLocale : enLocale;
addLocaleData(appLocale.data);
this.state = {
isFirstScreen: true,
appLocale,
};
}
9 years ago
componentDidMount() {
if (typeof window.ga !== 'undefined') {
9 years ago
this.context.router.listen((loc) => {
window.ga('send', 'pageview', loc.pathname + loc.search);
});
}
const nprogressHiddenStyle = document.getElementById('nprogress-style');
if (nprogressHiddenStyle) {
this.timer = setTimeout(() => {
nprogressHiddenStyle.parentNode.removeChild(nprogressHiddenStyle);
}, 0);
}
}
componentWillUnmount() {
clearTimeout(this.timer);
9 years ago
}
onEnterChange = (mode) => {
this.setState({
isFirstScreen: mode === 'enter',
});
}
9 years ago
render() {
const { children, ...restProps } = this.props;
const { appLocale, isFirstScreen } = this.state;
9 years ago
return (
<IntlProvider locale={appLocale.locale} messages={appLocale.messages}>
<LocaleProvider locale={enUS}>
<div className="page-wrapper">
<Header {...restProps} isFirstScreen={isFirstScreen} />
{cloneElement(children, { onEnterChange: this.onEnterChange })}
<Footer {...restProps} />
</div>
</LocaleProvider>
9 years ago
</IntlProvider>
);
}
}