Reinit project
This commit is contained in:
16
src/layouts/__tests__/index.test.tsx
Normal file
16
src/layouts/__tests__/index.test.tsx
Normal 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
24
src/layouts/index.css
Normal 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
37
src/layouts/index.tsx
Normal 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;
|
||||
Reference in New Issue
Block a user