-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
59 lines (53 loc) · 1.26 KB
/
App.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
import React, { Component } from 'react';
import DataStreamer, { ServerRespond } from './DataStreamer';
import Graph from './Graph';
import './App.css';
interface IState {
data: ServerRespond[],
showGraph: boolean,
}
class App extends Component<{}, IState> {
constructor(props: {}) {
super(props);
this.state = {
data: [],
showGraph: false,
};
}
renderGraph() {
if (this.state.showGraph) {
return (<Graph data={this.state.data}/>)
}
}
getDataFromServer() {
let x = 0;
const interval = setInterval(() => {
DataStreamer.getData((serverResponds: ServerRespond[]) => {
this.setState({
data: serverResponds,
showGraph: true,
});
});
x++;
if (x > 1000) {
clearInterval(interval);
}
}, 100);
}
render() {
return (
<div className="App">
<header className="App-header">
Bank Merge & Co Task 3
</header>
<div className="App-content">
<button className="btn btn-primary Stream-button" onClick={() => {this.getDataFromServer()}}>Start Streaming Data</button>
<div className="Graph">
{this.renderGraph()}
</div>
</div>
</div>
)
}
}
export default App;