-
Notifications
You must be signed in to change notification settings - Fork 323
/
PointSummaries.js
91 lines (82 loc) · 2.1 KB
/
PointSummaries.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
// @flow
import { pointsToLevels, milestoneToPoints, trackIds, totalPointsFromMilestoneMap } from '../constants'
import type { MilestoneMap } from '../constants'
import React from 'react'
type Props = {
milestoneByTrack: MilestoneMap
}
class PointSummaries extends React.Component<Props> {
render() {
const totalPoints = totalPointsFromMilestoneMap(this.props.milestoneByTrack)
let currentLevel, nextLevel
let pointsForCurrentLevel = totalPoints
while (!(currentLevel = pointsToLevels[pointsForCurrentLevel])) {
pointsForCurrentLevel--
}
let pointsToNextLevel = 1
while (!(nextLevel = pointsToLevels[totalPoints + pointsToNextLevel])) {
pointsToNextLevel++
if (pointsToNextLevel > 135) {
pointsToNextLevel = 'N/A'
break
}
}
const blocks = [
{
label: 'Current level',
value: currentLevel
},
{
label: 'Total points',
value: totalPoints
},
{
label: 'Points to next level',
value: pointsToNextLevel
}
]
return (
<table>
<style jsx>{`
table {
border-spacing: 3px;
margin-bottom: 20px;
margin-left: -3px;
}
.point-summary-label {
font-size: 12px;
text-align: center;
font-weight: normal;
width: 120px;
}
.point-summary-value {
width: 120px;
background: #eee;
font-size: 24px;
font-weight: bold;
line-height: 50px;
border-radius: 2px;
text-align: center;
}
`}</style>
<tbody>
<tr>
{blocks.map(({label}, i) => (
<th key={i} className="point-summary-label">
{label}
</th>
))}
</tr>
<tr>
{blocks.map(({value}, i) => (
<td key={i} className="point-summary-value">
{value}
</td>
))}
</tr>
</tbody>
</table>
)
}
}
export default PointSummaries