-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathApp.tsx
74 lines (67 loc) · 1.76 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React, { useContext, useEffect } from 'react';
import './App.css';
import 'antd/dist/antd.less';
import Annotation from './Annotation';
import ProjectPlatform from './ProjectPlatform';
import { AnnotationContext } from './store';
import { EStore } from './constant/store';
import { useLocale } from './store/locale';
import { ConfigProvider } from 'antd';
import i18n from './i18n';
import zhCN from 'antd/lib/locale/zh_CN';
import enUS from 'antd/lib/locale/en_US';
const App = () => {
const {
state: { fileList, currentProjectInfo },
dispatch,
} = useContext(AnnotationContext);
const locale = useLocale();
useEffect(() => {
i18n.on('languageChanged', function (lang: string) {
// 更改内部 antd 的国际化
switch (lang) {
case 'cn':
locale.dispatch({
type: 'UPDATE_LOCALE',
payload: {
locale: zhCN,
},
});
break;
case 'en':
locale.dispatch({
type: 'UPDATE_LOCALE',
payload: {
locale: enUS,
},
});
break;
}
});
}, []);
useEffect(() => {
try {
const projectListString = localStorage.getItem(EStore.LOCAL_PROJECT_LIST) || '[]';
const projectList = JSON.parse(projectListString);
if (projectList.length > 0) {
dispatch({
type: 'UPDATE_PROJECT_LIST',
payload: {
projectList,
},
});
}
} catch {}
}, [dispatch]);
if (currentProjectInfo && fileList.length > 0) {
return <Annotation />;
}
return (
<ConfigProvider locale={locale.state.locale}>
<div className='App'>
<ProjectPlatform />
</div>
</ConfigProvider>
);
};
export default App;