2024-01-06 17:07:18 -05:00
|
|
|
import TransferListener from '@/components/server/TransferListener';
|
|
|
|
import React, { useEffect, useState } from 'react';
|
2024-01-30 09:13:17 -05:00
|
|
|
import { useRouteMatch } from 'react-router-dom';
|
2024-01-06 17:07:18 -05:00
|
|
|
import NavigationBar from '@/components/NavigationBar';
|
|
|
|
import WebsocketHandler from '@/components/server/WebsocketHandler';
|
|
|
|
import { ServerContext } from '@/state/server';
|
|
|
|
import { CSSTransition } from 'react-transition-group';
|
|
|
|
import Spinner from '@/components/elements/Spinner';
|
2024-01-30 09:13:17 -05:00
|
|
|
import { ServerError } from '@/components/elements/ScreenBlock';
|
2024-01-06 17:07:18 -05:00
|
|
|
import { httpErrorToHuman } from '@/api/http';
|
|
|
|
import { useStoreState } from 'easy-peasy';
|
|
|
|
import SubNavigation from '@/components/elements/SubNavigation';
|
|
|
|
import InstallListener from '@/components/server/InstallListener';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
import { faExternalLinkAlt } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
|
2024-02-04 09:26:48 -05:00
|
|
|
import { NavigationLinks, NavigationRouter } from '@/blueprint/extends/routers/ServerRouter';
|
2024-09-05 05:17:11 -04:00
|
|
|
import BeforeSubNavigation from '@/blueprint/components/Navigation/SubNavigation/BeforeSubNavigation';
|
|
|
|
import AdditionalServerItems from '@/blueprint/components/Navigation/SubNavigation/AdditionalServerItems';
|
|
|
|
import AfterSubNavigation from '@/blueprint/components/Navigation/SubNavigation/AfterSubNavigation';
|
2024-01-06 17:07:18 -05:00
|
|
|
|
|
|
|
export default () => {
|
|
|
|
const match = useRouteMatch<{ id: string }>();
|
|
|
|
|
|
|
|
const rootAdmin = useStoreState((state) => state.user.data!.rootAdmin);
|
|
|
|
const [error, setError] = useState('');
|
|
|
|
|
|
|
|
const id = ServerContext.useStoreState((state) => state.server.data?.id);
|
|
|
|
const uuid = ServerContext.useStoreState((state) => state.server.data?.uuid);
|
|
|
|
const serverId = ServerContext.useStoreState((state) => state.server.data?.internalId);
|
|
|
|
const getServer = ServerContext.useStoreActions((actions) => actions.server.getServer);
|
|
|
|
const clearServerState = ServerContext.useStoreActions((actions) => actions.clearServerState);
|
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() => () => {
|
|
|
|
clearServerState();
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setError('');
|
|
|
|
|
|
|
|
getServer(match.params.id).catch((error) => {
|
|
|
|
console.error(error);
|
|
|
|
setError(httpErrorToHuman(error));
|
|
|
|
});
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
clearServerState();
|
|
|
|
};
|
|
|
|
}, [match.params.id]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment key={'server-router'}>
|
|
|
|
<NavigationBar />
|
|
|
|
{!uuid || !id ? (
|
|
|
|
error ? (
|
|
|
|
<ServerError message={error} />
|
|
|
|
) : (
|
|
|
|
<Spinner size={'large'} centered />
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<CSSTransition timeout={150} classNames={'fade'} appear in>
|
2024-04-10 14:35:11 -04:00
|
|
|
<SubNavigation id={'SubNavigation'}>
|
2024-02-03 10:41:05 -05:00
|
|
|
<BeforeSubNavigation />
|
2024-01-06 17:07:18 -05:00
|
|
|
<div>
|
2024-01-30 09:13:17 -05:00
|
|
|
<NavigationLinks />
|
2024-01-06 17:07:18 -05:00
|
|
|
<AdditionalServerItems />
|
|
|
|
{rootAdmin && (
|
|
|
|
// eslint-disable-next-line react/jsx-no-target-blank
|
|
|
|
<a href={`/admin/servers/view/${serverId}`} target={'_blank'}>
|
|
|
|
<FontAwesomeIcon icon={faExternalLinkAlt} />
|
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</div>
|
2024-02-03 10:41:05 -05:00
|
|
|
<AfterSubNavigation />
|
2024-01-06 17:07:18 -05:00
|
|
|
</SubNavigation>
|
|
|
|
</CSSTransition>
|
|
|
|
<InstallListener />
|
|
|
|
<TransferListener />
|
|
|
|
<WebsocketHandler />
|
2024-02-04 09:26:48 -05:00
|
|
|
<NavigationRouter />
|
2024-01-06 17:07:18 -05:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
};
|