Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/components/App.tsx
7461 views
1
import React, { lazy } from 'react';
2
import { hot } from 'react-hot-loader/root';
3
import { Route, Router, Switch } from 'react-router-dom';
4
import { StoreProvider } from 'easy-peasy';
5
import { store } from '@/state';
6
import { SiteSettings } from '@/state/settings';
7
import ProgressBar from '@/components/elements/ProgressBar';
8
import { NotFound } from '@/components/elements/ScreenBlock';
9
import tw from 'twin.macro';
10
import GlobalStylesheet from '@/assets/css/GlobalStylesheet';
11
import { history } from '@/components/history';
12
import { setupInterceptors } from '@/api/interceptors';
13
import AuthenticatedRoute from '@/components/elements/AuthenticatedRoute';
14
import { ServerContext } from '@/state/server';
15
import '@/assets/tailwind.css';
16
import Spinner from '@/components/elements/Spinner';
17
18
const DashboardRouter = lazy(() => import(/* webpackChunkName: "dashboard" */ '@/routers/DashboardRouter'));
19
const ServerRouter = lazy(() => import(/* webpackChunkName: "server" */ '@/routers/ServerRouter'));
20
const AuthenticationRouter = lazy(() => import(/* webpackChunkName: "auth" */ '@/routers/AuthenticationRouter'));
21
22
interface ExtendedWindow extends Window {
23
SiteConfiguration?: SiteSettings;
24
PterodactylUser?: {
25
uuid: string;
26
username: string;
27
email: string;
28
/* eslint-disable camelcase */
29
root_admin: boolean;
30
use_totp: boolean;
31
language: string;
32
updated_at: string;
33
created_at: string;
34
/* eslint-enable camelcase */
35
};
36
}
37
38
setupInterceptors(history);
39
40
const App = () => {
41
const { PterodactylUser, SiteConfiguration } = window as ExtendedWindow;
42
if (PterodactylUser && !store.getState().user.data) {
43
store.getActions().user.setUserData({
44
uuid: PterodactylUser.uuid,
45
username: PterodactylUser.username,
46
email: PterodactylUser.email,
47
language: PterodactylUser.language,
48
rootAdmin: PterodactylUser.root_admin,
49
useTotp: PterodactylUser.use_totp,
50
createdAt: new Date(PterodactylUser.created_at),
51
updatedAt: new Date(PterodactylUser.updated_at),
52
});
53
}
54
55
if (!store.getState().settings.data) {
56
store.getActions().settings.setSettings(SiteConfiguration!);
57
}
58
59
return (
60
<>
61
<GlobalStylesheet />
62
<StoreProvider store={store}>
63
<ProgressBar />
64
<div css={tw`mx-auto w-auto`}>
65
<Router history={history}>
66
<Switch>
67
<Route path={'/auth'}>
68
<Spinner.Suspense>
69
<AuthenticationRouter />
70
</Spinner.Suspense>
71
</Route>
72
<AuthenticatedRoute path={'/server/:id'}>
73
<Spinner.Suspense>
74
<ServerContext.Provider>
75
<ServerRouter />
76
</ServerContext.Provider>
77
</Spinner.Suspense>
78
</AuthenticatedRoute>
79
<AuthenticatedRoute path={'/'}>
80
<Spinner.Suspense>
81
<DashboardRouter />
82
</Spinner.Suspense>
83
</AuthenticatedRoute>
84
<Route path={'*'}>
85
<NotFound />
86
</Route>
87
</Switch>
88
</Router>
89
</div>
90
</StoreProvider>
91
</>
92
);
93
};
94
95
export default hot(App);
96
97