Skip to content

Commit 0fa90dd

Browse files
committed
Add listener for install start/end
1 parent 874d928 commit 0fa90dd

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import useWebsocketEvent from '@/plugins/useWebsocketEvent';
2+
import { ServerContext } from '@/state/server';
3+
import useServer from '@/plugins/useServer';
4+
5+
const InstallListener = () => {
6+
const server = useServer();
7+
const getServer = ServerContext.useStoreActions(actions => actions.server.getServer);
8+
const setServer = ServerContext.useStoreActions(actions => actions.server.setServer);
9+
10+
// Listen for the installation completion event and then fire off a request to fetch the updated
11+
// server information. This allows the server to automatically become available to the user if they
12+
// just sit on the page.
13+
useWebsocketEvent('install completed', () => {
14+
getServer(server.uuid).catch(error => console.error(error));
15+
});
16+
17+
// When we see the install started event immediately update the state to indicate such so that the
18+
// screens automatically update.
19+
useWebsocketEvent('install started', () => {
20+
setServer({ ...server, isInstalling: true });
21+
});
22+
23+
return null;
24+
};
25+
26+
export default InstallListener;
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { DependencyList } from 'react';
21
import { ServerContext } from '@/state/server';
32
import { Server } from '@/api/server/getServer';
43

5-
const useServer = (dependencies?: DependencyList): Server => {
6-
return ServerContext.useStoreState(state => state.server.data!, [ dependencies ]);
4+
const useServer = (dependencies?: any[] | undefined): Server => {
5+
return ServerContext.useStoreState(state => state.server.data!, dependencies);
76
};
87

98
export default useServer;

resources/scripts/routers/ServerRouter.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import useServer from '@/plugins/useServer';
2525
import ScreenBlock from '@/components/screens/ScreenBlock';
2626
import SubNavigation from '@/components/elements/SubNavigation';
2727
import NetworkContainer from '@/components/server/network/NetworkContainer';
28+
import InstallListener from '@/components/server/InstallListener';
2829

2930
const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>) => {
3031
const { rootAdmin } = useStoreState(state => state.user.data!);
@@ -98,6 +99,8 @@ const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>)
9899
</div>
99100
</SubNavigation>
100101
</CSSTransition>
102+
<InstallListener/>
103+
<WebsocketHandler/>
101104
{(installing && (!rootAdmin || (rootAdmin && !location.pathname.endsWith(`/server/${server.id}`)))) ?
102105
<ScreenBlock
103106
title={'Your server is installing.'}
@@ -106,7 +109,6 @@ const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>)
106109
/>
107110
:
108111
<>
109-
<WebsocketHandler/>
110112
<TransitionRouter>
111113
<Switch location={location}>
112114
<Route path={`${match.path}`} component={ServerConsole} exact/>

0 commit comments

Comments
 (0)