site: refactor, simplify code

This commit is contained in:
Benjy Cui 2016-07-26 17:40:08 +08:00
parent b79fd5a540
commit 54ad570475
3 changed files with 23 additions and 25 deletions

View File

@ -25,25 +25,25 @@ module.exports = {
component: './template/Layout/index',
indexRoute: { component: './template/Home/index' },
childRoutes: [{
path: '/docs/practice/:children',
path: 'docs/practice/:children',
component: contentTmpl,
}, {
path: '/docs/pattern/:children',
path: 'docs/pattern/:children',
component: contentTmpl,
}, {
path: '/docs/react/:children',
path: 'docs/react/:children',
component: contentTmpl,
}, {
path: '/changelog',
path: 'changelog',
component: contentTmpl,
}, {
path: '/components/:children',
path: 'components/:children',
component: contentTmpl,
}, {
path: '/docs/spec/:children',
path: 'docs/spec/:children',
component: contentTmpl,
}, {
path: '/docs/resource/:children',
path: 'docs/resource/:children',
component: contentTmpl,
}],
},

View File

@ -6,7 +6,6 @@ import ComponentDoc from './ComponentDoc';
import * as utils from '../utils';
import config from '../../';
const SubMenu = Menu.SubMenu;
let firstMounted = false;
export default class MainContent extends React.Component {
static contextTypes = {
@ -14,15 +13,17 @@ export default class MainContent extends React.Component {
}
componentDidMount() {
this.componentDidUpdate();
this.timer = setTimeout(() => {
document.getElementById(decodeURI(location.hash.replace('#', ''))).scrollIntoView();
}, 10);
}
componentDidUpdate() {
if (!location.hash) {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
} else if (!firstMounted) {
this.timer = setTimeout(() => {
document.getElementById(decodeURI(location.hash.replace('#', ''))).scrollIntoView();
}, 10);
}
firstMounted = true;
}
componentWillUnmount() {

View File

@ -17,7 +17,6 @@ window.antd = require('antd');
// Polyfill
const areIntlLocalesSupported = require('intl-locales-supported');
const localesMyAppSupports = ['zh-CN', 'en-US'];
if (global.Intl) {
// Determine if the built-in `Intl` has the locale data we need.
if (!areIntlLocalesSupported(localesMyAppSupports)) {
@ -49,26 +48,24 @@ export function collect(nextProps, callback) {
.then((list) => callback(null, { ...nextProps, components: list }));
}
let gaListenerSetted = false;
export default class Layout extends React.Component {
static contextTypes = {
router: React.PropTypes.object.isRequired,
}
componentDidMount() {
if (typeof ga !== 'undefined' && !gaListenerSetted) {
if (typeof ga !== 'undefined') {
this.context.router.listen((loc) => {
window.ga('send', 'pageview', loc.pathname + loc.search);
});
gaListenerSetted = true;
}
const loadingNode = document.getElementById('ant-site-loading');
if (!loadingNode) {
return;
if (loadingNode) {
this.timer = setTimeout(() => {
loadingNode.parentNode.removeChild(loadingNode);
}, 450);
}
this.timer = setTimeout(() => {
loadingNode.parentNode.removeChild(loadingNode);
}, 450);
}
componentWillUnmount() {
@ -76,12 +73,12 @@ export default class Layout extends React.Component {
}
render() {
const props = this.props;
const { children, ...restProps } = this.props;
return (
<IntlProvider locale={appLocale.locale} messages={appLocale.messages}>
<div className="page-wrapper">
<Header {...props} />
{props.children}
<Header {...restProps} />
{children}
<Footer />
</div>
</IntlProvider>