-
Notifications
You must be signed in to change notification settings - Fork 160
/
index.tsx
87 lines (84 loc) · 2.55 KB
/
index.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
75
76
77
78
79
80
81
82
83
84
85
86
87
import { FC, PropsWithChildren, useEffect } from "react";
import { useAntdTheme } from "@lepton-dashboard/hooks/use-antd-theme";
import { css } from "@emotion/react";
import styled from "@emotion/styled";
import { useInject } from "@lepton-libs/di";
import { RefreshService } from "@lepton-dashboard/services/refresh.service";
import { useLocation } from "react-router-dom";
import { InitializerService } from "@lepton-dashboard/services/initializer.service";
import { useStateFromBehaviorSubject } from "@lepton-libs/hooks/use-state-from-observable";
import { App } from "antd";
import axios from "axios";
import { Loading } from "@lepton-dashboard/components/loading";
import { useMonaco } from "@monaco-editor/react";
const Container = styled.div`
height: 100%;
`;
export const Root: FC<PropsWithChildren> = ({ children }) => {
const theme = useAntdTheme();
const { notification } = App.useApp();
const monaco = useMonaco();
useEffect(() => {
if (monaco) {
monaco.editor.defineTheme("lepton", {
base: "vs-dark",
inherit: true,
rules: [],
colors: {
"editor.background": "#1e1f29",
},
});
}
}, [monaco]);
useEffect(() => {
const interceptor = axios.interceptors.response.use(
function (response) {
return response;
},
function (error) {
if (error.response?.data?.message) {
const message = error.response.data.code;
notification.error({
message,
description: error.response.data.message,
});
} else {
notification.error({
message: error.code,
description: error.message,
});
}
return Promise.reject(error);
}
);
return () => {
axios.interceptors.response.eject(interceptor);
};
}, [notification]);
const refreshService = useInject(RefreshService);
const location = useLocation();
useEffect(() => {
refreshService.integrateWithRouter(location.pathname);
}, [location.pathname, refreshService]);
const initializerService = useInject(InitializerService);
const initialized = useStateFromBehaviorSubject(
initializerService.initialized$
);
useEffect(() => {
initializerService.bootstrap();
}, [initializerService]);
return initialized ? (
<Container
css={css`
background: ${theme.colorBgLayout};
font-family: ${theme.fontFamily};
color: ${theme.colorText};
font-size: ${theme.fontSize}px;
`}
>
{children}
</Container>
) : (
<Loading />
);
};