2019-06-10 00:29:10 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
import { hot } from 'react-hot-loader/root';
|
2019-06-29 05:17:29 +00:00
|
|
|
import { BrowserRouter, BrowserRouter as Router, Route, Switch } from 'react-router-dom';
|
2019-06-22 23:45:51 +00:00
|
|
|
import { StoreProvider } from 'easy-peasy';
|
|
|
|
import { store } from '@/state';
|
2019-06-26 04:28:56 +00:00
|
|
|
import DashboardRouter from '@/routers/DashboardRouter';
|
2019-06-29 05:17:29 +00:00
|
|
|
import ServerRouter from '@/routers/ServerRouter';
|
|
|
|
import AuthenticationRouter from '@/routers/AuthenticationRouter';
|
2019-06-30 01:28:23 +00:00
|
|
|
import { Provider } from 'react-redux';
|
2019-12-16 02:05:44 +00:00
|
|
|
import { SiteSettings } from '@/state/settings';
|
2019-12-23 01:03:44 +00:00
|
|
|
import { DefaultTheme, ThemeProvider } from 'styled-components';
|
2019-06-10 00:29:10 +00:00
|
|
|
|
2019-12-16 02:05:44 +00:00
|
|
|
interface ExtendedWindow extends Window {
|
|
|
|
SiteConfiguration?: SiteSettings;
|
2019-06-23 00:07:28 +00:00
|
|
|
PterodactylUser?: {
|
|
|
|
uuid: string;
|
|
|
|
username: string;
|
|
|
|
email: string;
|
|
|
|
root_admin: boolean;
|
|
|
|
use_totp: boolean;
|
|
|
|
language: string;
|
|
|
|
updated_at: string;
|
|
|
|
created_at: string;
|
|
|
|
};
|
|
|
|
}
|
2019-06-22 23:45:51 +00:00
|
|
|
|
2019-12-23 01:03:44 +00:00
|
|
|
const theme: DefaultTheme = {
|
|
|
|
breakpoints: {
|
|
|
|
xs: 0,
|
|
|
|
sm: 576,
|
|
|
|
md: 768,
|
|
|
|
lg: 992,
|
|
|
|
xl: 1200,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-06-23 00:07:28 +00:00
|
|
|
const App = () => {
|
2019-12-16 02:05:44 +00:00
|
|
|
const { PterodactylUser, SiteConfiguration } = (window as ExtendedWindow);
|
|
|
|
if (PterodactylUser && !store.getState().user.data) {
|
2019-06-23 00:07:28 +00:00
|
|
|
store.getActions().user.setUserData({
|
2019-12-16 02:05:44 +00:00
|
|
|
uuid: PterodactylUser.uuid,
|
|
|
|
username: PterodactylUser.username,
|
|
|
|
email: PterodactylUser.email,
|
|
|
|
language: PterodactylUser.language,
|
|
|
|
rootAdmin: PterodactylUser.root_admin,
|
|
|
|
useTotp: PterodactylUser.use_totp,
|
|
|
|
createdAt: new Date(PterodactylUser.created_at),
|
|
|
|
updatedAt: new Date(PterodactylUser.updated_at),
|
2019-06-23 00:07:28 +00:00
|
|
|
});
|
2019-06-12 06:12:03 +00:00
|
|
|
}
|
|
|
|
|
2019-12-16 02:05:44 +00:00
|
|
|
if (!store.getState().settings.data) {
|
|
|
|
store.getActions().settings.setSettings(SiteConfiguration!);
|
|
|
|
}
|
|
|
|
|
2019-06-23 00:07:28 +00:00
|
|
|
return (
|
2019-12-23 01:03:44 +00:00
|
|
|
<ThemeProvider theme={theme}>
|
|
|
|
<StoreProvider store={store}>
|
|
|
|
<Provider store={store}>
|
|
|
|
<Router basename={'/'}>
|
|
|
|
<div className={'mx-auto w-auto'}>
|
|
|
|
<BrowserRouter basename={'/'}>
|
|
|
|
<Switch>
|
|
|
|
<Route path="/server/:id" component={ServerRouter}/>
|
|
|
|
<Route path="/auth" component={AuthenticationRouter}/>
|
|
|
|
<Route path="/" component={DashboardRouter}/>
|
|
|
|
</Switch>
|
|
|
|
</BrowserRouter>
|
|
|
|
</div>
|
|
|
|
</Router>
|
|
|
|
</Provider>
|
|
|
|
</StoreProvider>
|
|
|
|
</ThemeProvider>
|
2019-06-23 00:07:28 +00:00
|
|
|
);
|
|
|
|
};
|
2019-06-10 00:29:10 +00:00
|
|
|
|
|
|
|
export default hot(App);
|