Reinit project

This commit is contained in:
Limo Saplf
2019-08-31 20:44:15 +08:00
commit b51ae824c7
115 changed files with 20955 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
import 'jest';
import BasicLayout from '..';
import React from 'react';
import renderer, { ReactTestInstance, ReactTestRenderer } from 'react-test-renderer';
describe('Layout: BasicLayout', () => {
it('Render correctly', () => {
const wrapper: ReactTestRenderer = renderer.create(<BasicLayout />);
expect(wrapper.root.children.length).toBe(1);
const outerLayer = wrapper.root.children[0] as ReactTestInstance;
expect(outerLayer.type).toBe('div');
const title = outerLayer.children[0] as ReactTestInstance;
expect(title.type).toBe('h1');
expect(title.children[0]).toBe('Yay! Welcome to umi!');
});
});

24
src/layouts/index.css Normal file
View File

@@ -0,0 +1,24 @@
.normal {
height: 100%;
}
.splash {
height: 100%;
display: flex;
flex-direction: column;
}
.centered {
flex-grow: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: 1.6rem;
}
.bottom {
padding: 40px;
text-align: center;
}

37
src/layouts/index.tsx Normal file
View File

@@ -0,0 +1,37 @@
import React, { useEffect } from 'react';
import { useTimeout } from 'react-use';
import { formatMessage } from 'umi-plugin-locale';
import { isDev } from '@/utils/utils';
import splash from '@/assets/splash.png';
import styles from './index.css';
const BasicLayout: React.FC = props => {
const [isReady, cancel] = useTimeout(isDev ? 100 : 1500);
useEffect(() => {
return () => {
if (!isReady()) cancel();
};
}, []);
if (!isReady()) {
return (
<div className={styles.splash}>
<div className={styles.centered}>
<span>{formatMessage({ id: 'index.start1' })}</span>
<span>{formatMessage({ id: 'index.start2' })}</span>
</div>
<span className={styles.bottom}>{formatMessage({ id: 'app.name' })}</span>
</div>
);
}
return (
<div className={styles.normal}>
{props.children}
</div>
);
};
export default BasicLayout;