index.tsx 1.3 KB
Newer Older
1
import React, {FunctionComponent, useEffect} from 'react';
2
import {headerHeight, primaryColor, rem, size} from '~/utils/style';
3

P
Peter Pan 已提交
4 5
import HashLoader from 'react-spinners/HashLoader';
import styled from 'styled-components';
6
import {useHistory} from 'react-router-dom';
P
Peter Pan 已提交
7
import useNavItems from '~/hooks/useNavItems';
8
import {useTranslation} from 'react-i18next';
P
Peter Pan 已提交
9 10 11 12

const Loading = styled.div`
    ${size(`calc(100vh - ${headerHeight})`, '100vw')}
    display: flex;
13
    flex-direction: column;
P
Peter Pan 已提交
14 15 16 17
    justify-content: center;
    align-items: center;
    overscroll-behavior: none;
    cursor: progress;
18 19
    font-size: ${rem(16)};
    line-height: ${rem(60)};
P
Peter Pan 已提交
20
`;
21

22
const IndexPage: FunctionComponent = () => {
P
Peter Pan 已提交
23
    const navItems = useNavItems();
24
    const history = useHistory();
P
Peter Pan 已提交
25

26 27
    const {t} = useTranslation('common');

28
    useEffect(() => {
P
Peter Pan 已提交
29 30
        if (navItems.length) {
            if (navItems[0].path) {
31
                history.replace(navItems[0].path);
P
Peter Pan 已提交
32
            } else if (navItems[0].children?.length && navItems[0].children[0].path) {
33
                history.replace(navItems[0].children[0].path);
P
Peter Pan 已提交
34
            }
P
Peter Pan 已提交
35
        }
36
    }, [navItems, history]);
37

P
Peter Pan 已提交
38 39 40
    return (
        <Loading>
            <HashLoader size="60px" color={primaryColor} />
41
            <span>{t('common:loading')}</span>
P
Peter Pan 已提交
42 43
        </Loading>
    );
44 45
};

46
export default IndexPage;