This repository was archived by the owner on May 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.tsx
More file actions
97 lines (89 loc) · 2.35 KB
/
index.tsx
File metadata and controls
97 lines (89 loc) · 2.35 KB
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
import { Component, h } from 'preact'
import { getAllianceAnalysis, getSchema } from '../../api'
import Analysis from '../../models/analysis'
import Schema from '../../models/schema'
import Resolver from '../../resolver'
import {
camelToTitle,
formatMatchKey,
formatTeamNumber,
toPercentage,
toPrettyNumber
} from '../../utils'
import style from './style.css'
interface PrintProps {
eventId: string
matchId: string
}
interface Props {
redAlliance: Analysis[]
blueAlliance: Analysis[]
schema: Schema
}
interface AllianceProps {
data: Analysis[]
name: string
schema: Schema
}
declare const print: () => void
const Alliance = ({ data, name, schema }: AllianceProps) => (
<div class={style.alliance}>
<h2>{name}</h2>
<table>
<thead>
<td />
{data.map(team => (
<td key={team.team}>{formatTeamNumber(team.team)}</td>
))}
</thead>
{Object.keys(schema).map(stat => {
const isNumber = schema[stat] === 'number'
return (
<tr key={stat}>
<td>{camelToTitle(stat)}</td>
{data.map(team => {
const s = team.stats[stat]
return (
<td key={team}>
{isNumber ? toPrettyNumber(s) : toPercentage(s)}
</td>
)
})}
</tr>
)
})}
</table>
</div>
)
const Print = ({ eventId, matchId }: PrintProps) => (
<Resolver
data={{
redAlliance: getAllianceAnalysis(eventId, matchId, 'red'),
blueAlliance: getAllianceAnalysis(eventId, matchId, 'blue'),
schema: getSchema()
}}
render={
class Print extends Component<Props, {}> {
componentDidUpdate() {
if (!(this.props.redAlliance && this.props.blueAlliance)) return
print()
window.close()
}
render({ redAlliance, blueAlliance, schema }: Props) {
return (
<div class={style.alliances}>
<h1>{formatMatchKey(matchId)}</h1>
{redAlliance !== undefined ? (
<Alliance name="Red" data={redAlliance} schema={schema} />
) : null}
{blueAlliance !== undefined ? (
<Alliance name="Blue" data={blueAlliance} schema={schema} />
) : null}
</div>
)
}
}
}
/>
)
export default Print