-
Notifications
You must be signed in to change notification settings - Fork 1
/
SillyMeter.jsx
188 lines (167 loc) · 4.68 KB
/
SillyMeter.jsx
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import React, { Component } from "react";
import { Line } from "rc-progress";
import AnimatedNumber from "react-animated-number/build/AnimatedNumber";
import * as timeago from "timeago.js";
import ReactTooltip from "react-tooltip";
class SillyMeter extends Component {
getTeams() {
// first we need to get the data
const { sillyData } = this.props;
// if we're still loading, slap a huge loading for everything
if (sillyData.hp === undefined) {
return "Loading...";
}
// if there's a winner, return the winner instead
if (sillyData.winner !== null) {
return <h5>{sillyData.winner}</h5>;
}
// if it's inactive, show "upcoming teams"
if (sillyData.state === "Inactive") {
return (
<p className="text-muted">
Upcoming teams: {sillyData.rewards[0]}
<br />
{sillyData.rewards[1]}
<br />
{sillyData.rewards[2]}
</p>
);
}
return (
<p>
{sillyData.rewards[0]}
<br />
{sillyData.rewards[1]}
<br />
{sillyData.rewards[2]}
</p>
);
}
getDate() {
// first we need to get the data
const { sillyData } = this.props;
// if we're still loading, slap a huge loading for everything
if (sillyData.hp === undefined) {
return "Loading...";
}
// get the date
const date = new Date(sillyData.nextUpdateTimestamp * 1000);
// get our custom status
if (sillyData.state === "Active") {
return (
<span
data-for="sillymeterETA"
data-tip={"updating in " + date.toLocaleString()}
>
Updating {timeago.format(date)}
<ReactTooltip id="sillymeterETA" place="bottom" effect="solid" />
</span>
);
} else if (sillyData.state === "Reward") {
return (
<span
data-for="sillymeterETA"
data-tip={"ending at " + date.toLocaleString()}
>
Boost ending {timeago.format(date)}
<ReactTooltip id="sillymeterETA" place="bottom" effect="solid" />
</span>
);
} else {
return (
<span
data-for="sillymeterETA"
data-tip={"starting at " + date.toLocaleString()}
>
Starting {timeago.format(date)}
<ReactTooltip id="sillymeterETA" place="bottom" effect="solid" />
</span>
);
}
}
getStatus(arg) {
// first we need to get the data
const { sillyData } = this.props;
// check what we're working with
if (arg === "text") {
// if we're still loading, slap a huge loading for everything
if (sillyData.hp === undefined) {
return "Loading...";
}
return sillyData.state;
}
if (sillyData.state === "Active") {
return "badge badge-success";
} else if (sillyData.state === "Reward") {
return "badge badge-info";
} else {
// this is either if it's inactive or if we're loading
return "badge badge-secondary";
}
}
getColour() {
// first we need to get the data
const { sillyData } = this.props;
if (sillyData.state === "Active") {
return "#38b44a";
} else if (sillyData.state === "Reward") {
return "#17a2b8";
} else {
// this is either if it's inactive or if we're loading
return "#aea79f";
}
}
getPercentage() {
// first we need to get the data
const { sillyData } = this.props;
// if we're still loading, slap a 0 for niceness
if (sillyData.hp === undefined) {
return 0;
}
// if it's inactive, return 0
if (sillyData.state === "Inactive") {
return 0;
}
// get the health
const hp = sillyData.hp;
// do the math and return the health
return Math.floor(hp / 50000);
}
formatValue = value => value.toFixed(0);
duration = 500;
getRawPercentage() {
const { sillyData } = this.props;
// if we're still loading, slap a 0 for niceness
if (sillyData.hp === undefined) {
return 0;
}
return sillyData.hp + " / 5000000";
}
render() {
return (
<div>
<h1>Silly Meter</h1>
<h5>
<span
className={this.getStatus("status")}
data-for="sillymeterETA"
data-tip={this.getRawPercentage()}
>
{this.getStatus("text")}{" "}
<AnimatedNumber
value={this.getPercentage()}
formatValue={this.formatValue}
duration={this.duration}
/>
%
</span>{" "}
{this.getDate()}
</h5>
<Line percent={this.getPercentage()} strokeColor={this.getColour()} />
<br />
{this.getTeams()}
</div>
);
}
}
export default SillyMeter;