misc_pterodactyl-panel/resources/scripts/routers/ServerRouter.tsx

88 lines
4.6 KiB
TypeScript
Raw Normal View History

import React, { lazy, useEffect } from 'react';
import { NavLink, Route, RouteComponentProps, Switch } from 'react-router-dom';
import NavigationBar from '@/components/NavigationBar';
import ServerConsole from '@/components/server/ServerConsole';
import TransitionRouter from '@/TransitionRouter';
import Spinner from '@/components/elements/Spinner';
import WebsocketHandler from '@/components/server/WebsocketHandler';
import { ServerContext } from '@/state/server';
import { Provider } from 'react-redux';
import DatabasesContainer from '@/components/server/databases/DatabasesContainer';
2019-07-28 03:23:44 +00:00
import FileManagerContainer from '@/components/server/files/FileManagerContainer';
import { CSSTransition } from 'react-transition-group';
import SuspenseSpinner from '@/components/elements/SuspenseSpinner';
2019-10-19 22:31:02 +00:00
import FileEditContainer from '@/components/server/files/FileEditContainer';
2019-11-03 20:20:11 +00:00
import UsersContainer from '@/components/server/users/UsersContainer';
2019-12-07 23:58:37 +00:00
import ScheduleContainer from '@/components/server/schedules/ScheduleContainer';
import SettingsContainer from '@/components/server/settings/SettingsContainer';
const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>) => {
const server = ServerContext.useStoreState(state => state.server.data);
const getServer = ServerContext.useStoreActions(actions => actions.server.getServer);
const clearServerState = ServerContext.useStoreActions(actions => actions.clearServerState);
if (!server) {
getServer(match.params.id);
}
2019-10-19 22:31:02 +00:00
useEffect(() => () => clearServerState(), [ clearServerState ]);
return (
<React.Fragment>
<NavigationBar/>
2019-07-28 03:23:44 +00:00
<CSSTransition timeout={250} classNames={'fade'} appear={true} in={true}>
<div id={'sub-navigation'}>
<div className={'mx-auto'} style={{ maxWidth: '1200px' }}>
<div className={'items'}>
<NavLink to={`${match.url}`} exact>Console</NavLink>
<NavLink to={`${match.url}/files`}>File Manager</NavLink>
<NavLink to={`${match.url}/databases`}>Databases</NavLink>
{/* <NavLink to={`${match.url}/users`}>User Management</NavLink> */}
{/* <NavLink to={`${match.url}/schedules`}>Schedules</NavLink> */}
2019-12-07 23:58:37 +00:00
<NavLink to={`${match.url}/settings`}>Settings</NavLink>
2019-07-28 03:23:44 +00:00
</div>
</div>
</div>
2019-07-28 03:23:44 +00:00
</CSSTransition>
<Provider store={ServerContext.useStore()}>
<WebsocketHandler/>
<TransitionRouter>
<div className={'w-full mx-auto px-3'} style={{ maxWidth: '1200px' }}>
{!server ?
<div className={'flex justify-center m-20'}>
<Spinner size={'large'}/>
</div>
:
<React.Fragment>
<Switch location={location}>
<Route path={`${match.path}`} component={ServerConsole} exact/>
2019-07-28 03:23:44 +00:00
<Route path={`${match.path}/files`} component={FileManagerContainer} exact/>
<Route
path={`${match.path}/files/edit`}
render={props => (
<SuspenseSpinner>
2019-10-19 22:31:02 +00:00
<FileEditContainer {...props as any}/>
</SuspenseSpinner>
)}
exact
/>
2019-11-03 20:20:11 +00:00
<Route path={`${match.path}/databases`} component={DatabasesContainer} exact/>
{/* <Route path={`${match.path}/users`} component={UsersContainer} exact/> */}
{/* <Route path={`${match.path}/schedules`} component={ScheduleContainer} exact/> */}
2019-12-07 23:58:37 +00:00
<Route path={`${match.path}/settings`} component={SettingsContainer} exact/>
</Switch>
</React.Fragment>
}
</div>
</TransitionRouter>
</Provider>
</React.Fragment>
);
};
export default (props: RouteComponentProps<any>) => (
<ServerContext.Provider>
<ServerRouter {...props}/>
</ServerContext.Provider>
);