This repository was archived by the owner on Sep 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplicationStatus.tsx
70 lines (61 loc) · 1.92 KB
/
ApplicationStatus.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import * as React from 'react'
import { Api } from '../api/Api'
import { ExecutableStatus } from '../api/rules/ExecutableStatus'
type CheckStatus = 'Idle' | // check has not begun yet
'Checking' | // check is running
'Completed' | // check is complete, results are in the other state variables
'ErrorWhileChecking'; // there was a problem checking something, should not happen. NOTE that is is not the same as a negative result on one of the checks
interface State {
checkStatus: CheckStatus;
serverReachable: boolean;
errors: Array<string>;
}
export class ApplicationStatus extends React.Component<{}, State> {
constructor() {
super(null)
this.state = {
checkStatus: 'Idle',
serverReachable: false,
errors: [],
}
}
componentDidMount() {
this.startCheck()
}
private pushError(error: any) {
this.setState((prev, _props) => {
prev.errors.push(error)
return prev
})
}
private updateCheckStatus(newStatus: CheckStatus): void {
this.setState({ checkStatus: newStatus })
}
startCheck(): void {
this.updateCheckStatus('Checking')
this.checkServer().then(result => {
this.setState({ serverReachable: result })
this.updateCheckStatus('Completed')
}).catch(error => {
this.pushError('Error while checking: ' + error)
this.updateCheckStatus('ErrorWhileChecking')
})
}
checkServer(): Promise<boolean> {
console.log('checking server')
return Api.getGameManager().getGameServerStatus().then(serverInfo => {
if (serverInfo.status != ExecutableStatus.Status.RUNNING) {
this.pushError(serverInfo)
return false
} else {
return true
}
})
}
render() {
return (
<div>Pruefung durchgefuehrt: {this.state.checkStatus}<p>Server
reachable: {this.state.serverReachable.toString()}</p><p>{this.state.errors.join(' ')}</p></div>
)
}
}