2019-06-29 23:14:32 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2019-06-29 05:49:08 +00:00
|
|
|
import { NavLink, Route, RouteComponentProps, Switch } from 'react-router-dom';
|
2019-06-29 05:17:29 +00:00
|
|
|
import NavigationBar from '@/components/NavigationBar';
|
|
|
|
import ServerConsole from '@/components/server/ServerConsole';
|
|
|
|
import TransitionRouter from '@/TransitionRouter';
|
2019-06-29 23:14:32 +00:00
|
|
|
import Spinner from '@/components/elements/Spinner';
|
|
|
|
import WebsocketHandler from '@/components/server/WebsocketHandler';
|
2019-07-10 04:25:57 +00:00
|
|
|
import { ServerContext } from '@/state/server';
|
|
|
|
import { Provider } from 'react-redux';
|
2019-07-10 05:00:29 +00:00
|
|
|
import DatabasesContainer from '@/components/server/databases/DatabasesContainer';
|
2019-06-29 05:17:29 +00:00
|
|
|
|
2019-07-10 04:25:57 +00:00
|
|
|
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);
|
2019-06-29 23:14:32 +00:00
|
|
|
|
|
|
|
if (!server) {
|
|
|
|
getServer(match.params.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => () => clearServerState(), []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<NavigationBar/>
|
|
|
|
<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>
|
|
|
|
</div>
|
2019-06-29 05:49:08 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-07-10 04:25:57 +00:00
|
|
|
<Provider store={ServerContext.useStore()}>
|
|
|
|
<TransitionRouter>
|
|
|
|
<div className={'w-full mx-auto'} style={{ maxWidth: '1200px' }}>
|
|
|
|
{!server ?
|
|
|
|
<div className={'flex justify-center m-20'}>
|
|
|
|
<Spinner large={true}/>
|
|
|
|
</div>
|
|
|
|
:
|
|
|
|
<React.Fragment>
|
|
|
|
<WebsocketHandler/>
|
|
|
|
<Switch location={location}>
|
|
|
|
<Route path={`${match.path}`} component={ServerConsole} exact/>
|
2019-07-10 05:00:29 +00:00
|
|
|
<Route path={`${match.path}/databases`} component={DatabasesContainer}/>
|
2019-07-10 04:25:57 +00:00
|
|
|
</Switch>
|
|
|
|
</React.Fragment>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</TransitionRouter>
|
|
|
|
</Provider>
|
2019-06-29 23:14:32 +00:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
};
|
2019-07-10 04:25:57 +00:00
|
|
|
|
|
|
|
export default (props: RouteComponentProps<any>) => (
|
|
|
|
<ServerContext.Provider>
|
|
|
|
<ServerRouter {...props}/>
|
|
|
|
</ServerContext.Provider>
|
|
|
|
);
|