-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGames.js
99 lines (92 loc) · 2.35 KB
/
Games.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import React, { Component } from "react";
import {
Grid,
Segment,
Header,
Dimmer,
Loader,
} from "semantic-ui-react";
import TableComp from "./TableComp";
class Games extends Component {
constructor(props) {
super(props);
this.state = {
error: null,
isLoaded: false,
games: [],
players: [],
numOfGames: "10",
header: "Top 10 games",
};
}
fetchData(number) {
fetch("/top-games/" + number)
.then((res) => res.json())
.then(
(result) => {
this.setState({
isLoaded: true,
games: result.games,
players: result.players,
});
},
(error) => {
this.setState({
isLoaded: true,
error,
});
}
);
this.setState({
numOfGames: number,
header: "Top " + number + " games",
});
}
componentDidMount() {
this.fetchData(this.state.numOfGames);
}
render() {
const { error, isLoaded, header } = this.state;
const paragraph =
"Find out which games are played by the largest number of streamers.";
const headers = ["Game", "Number of players"];
if (error) {
return <div>Error: {error.message}</div>;
} else if (!isLoaded) {
return (
<Segment style={{ padding: "8em 0em" }} vertical>
<Dimmer active inverted>
<Loader size="large" inverted>
Getting top games
</Loader>
</Dimmer>
</Segment>
);
} else {
return (
<Segment style={{ padding: "8em 0em" }} vertical>
<Grid container stackable verticalAlign="middle">
<Grid.Row>
<Grid.Column width={8}>
<Header as="h3" style={{ fontSize: "2em" }}>
{header}
</Header>
<p style={{ fontSize: "1.33em" }}>{paragraph}</p>
</Grid.Column>
<Grid.Column floated="right" width={4}>
<TableComp
headers={headers}
column_1={this.state.games}
column_2={this.state.players}
column_1_key="name"
column_2_key="players"
></TableComp>
</Grid.Column>
</Grid.Row>
</Grid>
</Segment>
);
}
}
}
export default Games;