Hopefully the last small tweaks and fixes to transfer logs

This commit is contained in:
Matthew Penner 2020-12-16 19:30:12 -07:00
parent 8d297a0918
commit 5668a780e2
3 changed files with 14 additions and 10 deletions

View file

@ -67,6 +67,7 @@ export default () => {
const { connected, instance } = ServerContext.useStoreState(state => state.socket);
const [ canSendCommands ] = usePermissions([ 'control.console' ]);
const serverId = ServerContext.useStoreState(state => state.server.data!.id);
const isTransferring = ServerContext.useStoreState(state => state.server.data!.isTransferring)
const [ history, setHistory ] = usePersistedState<string[]>(`${serverId}:command_history`, []);
const [ historyIndex, setHistoryIndex ] = useState(-1);
@ -165,7 +166,10 @@ export default () => {
useEffect(() => {
if (connected && instance) {
// terminal.clear();
// Do not clear the console if the server is being transferred.
if (!isTransferring) {
terminal.clear();
}
instance.addListener('status', handlePowerChangeEvent);
instance.addListener('console output', handleConsoleOutput);

View file

@ -6,19 +6,23 @@ const TransferListener = () => {
const getServer = ServerContext.useStoreActions(actions => actions.server.getServer);
const setServerFromState = ServerContext.useStoreActions(actions => actions.server.setServerFromState);
// Listen for the installation completion event and then fire off a request to fetch the updated
// server information. This allows the server to automatically become available to the user if they
// just sit on the page.
// Listen for the transfer status event so we can update the state of the server.
useWebsocketEvent('transfer status', (status: string) => {
if (status === 'starting') {
setServerFromState(s => ({ ...s, isTransferring: true }));
return;
}
if (status === 'failure') {
setServerFromState(s => ({ ...s, isTransferring: false }));
return;
}
if (status !== 'success') {
return;
}
// Refresh the server's information as it's node and allocations were just updated.
getServer(uuid).catch(error => console.error(error));
});

View file

@ -53,16 +53,12 @@ export default () => {
return;
}
// Force a reconnection to the websocket which will connect us
// to the target node instead of the source node.
// Close the current websocket connection.
// This code forces a reconnection to the websocket which will connect us to the target node instead of the source node
// in order to be able to receive transfer logs from the target node.
socket.close();
setError('connecting');
setConnectionState(false);
setInstance(null);
connect(uuid);
});