playball 3.0.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -0
- package/bin/playball.js +1 -1
- package/dist/cli.js +31 -0
- package/dist/components/AllPlays.js +20 -60
- package/dist/components/App.js +19 -45
- package/dist/components/AtBat.js +8 -33
- package/dist/components/Bases.js +10 -25
- package/dist/components/Count.js +10 -25
- package/dist/components/FinishedGame.js +26 -60
- package/dist/components/Game.js +25 -57
- package/dist/components/GameList.js +32 -83
- package/dist/components/Grid.js +20 -47
- package/dist/components/HelpBar.js +6 -20
- package/dist/components/InningDisplay.js +6 -20
- package/dist/components/LineScore.js +10 -31
- package/dist/components/LiveGame.js +22 -41
- package/dist/components/LoadingSpinner.js +12 -34
- package/dist/components/Matchup.js +11 -29
- package/dist/components/PreviewGame.js +18 -40
- package/dist/components/Standings.js +23 -45
- package/dist/config.js +126 -0
- package/dist/features/games.js +32 -67
- package/dist/features/keys.js +10 -25
- package/dist/features/schedule.js +16 -31
- package/dist/features/standings.js +14 -28
- package/dist/hooks/useKey.js +8 -20
- package/dist/logger.js +9 -20
- package/dist/main.js +20 -28
- package/dist/package.js +5 -0
- package/dist/screen.js +16 -22
- package/dist/store/index.js +14 -27
- package/dist/style/index.js +2 -9
- package/dist/utils.js +8 -0
- package/package.json +14 -6
- package/.eslintrc.json +0 -33
- package/CODE_OF_CONDUCT.md +0 -76
- package/demo.cast +0 -95
- package/demo.gif +0 -0
- package/src/components/AllPlays.jsx +0 -107
- package/src/components/App.jsx +0 -43
- package/src/components/AtBat.jsx +0 -41
- package/src/components/Bases.jsx +0 -22
- package/src/components/Count.jsx +0 -24
- package/src/components/FinishedGame.jsx +0 -76
- package/src/components/Game.jsx +0 -60
- package/src/components/GameList.jsx +0 -166
- package/src/components/Grid.jsx +0 -91
- package/src/components/HelpBar.jsx +0 -19
- package/src/components/InningDisplay.jsx +0 -19
- package/src/components/LineScore.jsx +0 -52
- package/src/components/LiveGame.jsx +0 -47
- package/src/components/LoadingSpinner.jsx +0 -49
- package/src/components/Matchup.jsx +0 -41
- package/src/components/PreviewGame.jsx +0 -54
- package/src/components/Standings.jsx +0 -78
- package/src/features/games.js +0 -165
- package/src/features/keys.js +0 -38
- package/src/features/schedule.js +0 -59
- package/src/features/standings.js +0 -60
- package/src/hooks/useKey.js +0 -13
- package/src/logger.js +0 -16
- package/src/main.js +0 -23
- package/src/screen.js +0 -14
- package/src/store/index.js +0 -18
- package/src/style/index.js +0 -15
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useSelector } from 'react-redux';
|
|
3
|
-
import { selectLineScore, selectTeams, selectDecisions, selectBoxscore, selectGameStatus } from '../features/games';
|
|
4
|
-
import LineScore from './LineScore';
|
|
5
|
-
|
|
6
|
-
const getPlayer = (id, boxscore) => {
|
|
7
|
-
const homePlayer = boxscore.home?.players?.['ID' + id];
|
|
8
|
-
if (homePlayer !== undefined) {
|
|
9
|
-
return homePlayer;
|
|
10
|
-
}
|
|
11
|
-
return boxscore.away?.players['ID' + id];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const formatDecisions = (decisions, boxscore) => {
|
|
15
|
-
if (!decisions) {
|
|
16
|
-
return '';
|
|
17
|
-
}
|
|
18
|
-
const content = [];
|
|
19
|
-
const winner = decisions.winner;
|
|
20
|
-
if (winner) {
|
|
21
|
-
const pitcher = getPlayer(winner.id, boxscore);
|
|
22
|
-
content.push(`Win: ${pitcher.person.fullName} (${pitcher.seasonStats?.pitching?.wins}-${pitcher.seasonStats?.pitching?.losses})`);
|
|
23
|
-
}
|
|
24
|
-
const loser = decisions.loser;
|
|
25
|
-
if (loser) {
|
|
26
|
-
const pitcher = getPlayer(loser.id, boxscore);
|
|
27
|
-
content.push(`Loss: ${pitcher.person.fullName} (${pitcher.seasonStats?.pitching?.wins}-${pitcher.seasonStats?.pitching?.losses})`);
|
|
28
|
-
}
|
|
29
|
-
const save = decisions.save;
|
|
30
|
-
if (save) {
|
|
31
|
-
const pitcher = getPlayer(save.id, boxscore);
|
|
32
|
-
content.push(`Save: ${pitcher.person.fullName} (${pitcher.seasonStats?.pitching.saves})`);
|
|
33
|
-
}
|
|
34
|
-
return content.join('\n');
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const formatScore = (status, linescore) => {
|
|
38
|
-
let display = '';
|
|
39
|
-
if (status.detailedState === 'Postponed') {
|
|
40
|
-
display = status.detailedState;
|
|
41
|
-
if (status.reason) {
|
|
42
|
-
display += '\n' + status.reason;
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
display = `\n${linescore.teams.away.runs} - ${linescore.teams.home.runs}`;
|
|
46
|
-
}
|
|
47
|
-
return display;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
function FinishedGame() {
|
|
51
|
-
const boxscore = useSelector(selectBoxscore);
|
|
52
|
-
const decisions = useSelector(selectDecisions);
|
|
53
|
-
const linescore = useSelector(selectLineScore);
|
|
54
|
-
const status = useSelector(selectGameStatus);
|
|
55
|
-
const teams = useSelector(selectTeams);
|
|
56
|
-
|
|
57
|
-
const awayTeam = `${teams.away.teamName}\n(${teams.away.record.wins}-${teams.away.record.losses})`;
|
|
58
|
-
const homeTeam = `${teams.home.teamName}\n(${teams.home.record.wins}-${teams.home.record.losses})`;
|
|
59
|
-
return (
|
|
60
|
-
<element>
|
|
61
|
-
<element height='60%'>
|
|
62
|
-
<box content={awayTeam} width='33%-1' top='50%' align='center' />
|
|
63
|
-
<box content={formatScore(status, linescore)} width='33%-1' left='33%' top='50%' align='center' />
|
|
64
|
-
<box content={homeTeam} width='34%' top='50%' left='66%' align='center' />
|
|
65
|
-
</element>
|
|
66
|
-
<element top='60%+1' height={3}>
|
|
67
|
-
<LineScore align='center' final />
|
|
68
|
-
</element>
|
|
69
|
-
<element top='60%+5' left='50%-20'>
|
|
70
|
-
<box content={formatDecisions(decisions, boxscore)} />
|
|
71
|
-
</element>
|
|
72
|
-
</element>
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export default FinishedGame;
|
package/src/components/Game.jsx
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from 'react';
|
|
2
|
-
import { useDispatch, useSelector } from 'react-redux';
|
|
3
|
-
|
|
4
|
-
import { fetchGame, selectGame, selectSelectedId, selectFullUpdateRequired } from '../features/games';
|
|
5
|
-
|
|
6
|
-
import PreviewGame from './PreviewGame';
|
|
7
|
-
import LiveGame from './LiveGame';
|
|
8
|
-
import FinishedGame from './FinishedGame';
|
|
9
|
-
|
|
10
|
-
import log from '../logger';
|
|
11
|
-
|
|
12
|
-
function Game() {
|
|
13
|
-
const dispatch = useDispatch();
|
|
14
|
-
const game = useSelector(selectGame);
|
|
15
|
-
const fullUpdateRequired = useSelector(selectFullUpdateRequired);
|
|
16
|
-
const id = useSelector(selectSelectedId);
|
|
17
|
-
const timerRef = useRef(null);
|
|
18
|
-
const timestampRef = useRef();
|
|
19
|
-
timestampRef.current = fullUpdateRequired ? null : game?.metaData?.timeStamp;
|
|
20
|
-
|
|
21
|
-
const updateGameData = () => {
|
|
22
|
-
dispatch(fetchGame({id, start: timestampRef.current}))
|
|
23
|
-
.unwrap()
|
|
24
|
-
.then((result) => {
|
|
25
|
-
const wait = ((result && result.metaData?.wait) || 10) * 1000;
|
|
26
|
-
timerRef.current = setTimeout(updateGameData, wait);
|
|
27
|
-
})
|
|
28
|
-
.catch(err => log.error('UPDATE_GAME_DATA:\n' + JSON.stringify(err) + '\n' + err.stack));
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
updateGameData();
|
|
33
|
-
return () => {
|
|
34
|
-
clearTimeout(timerRef.current);
|
|
35
|
-
};
|
|
36
|
-
}, [id]);
|
|
37
|
-
|
|
38
|
-
if (!game) {
|
|
39
|
-
return <element />;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let Wrapped = null;
|
|
43
|
-
switch (game.gameData?.status?.abstractGameCode) {
|
|
44
|
-
case 'P':
|
|
45
|
-
Wrapped = PreviewGame;
|
|
46
|
-
break;
|
|
47
|
-
case 'L':
|
|
48
|
-
Wrapped = LiveGame;
|
|
49
|
-
break;
|
|
50
|
-
case 'F':
|
|
51
|
-
Wrapped = FinishedGame;
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return (
|
|
56
|
-
<element><Wrapped /></element>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export default Game;
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { useDispatch, useSelector } from 'react-redux';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import { add, format } from 'date-fns';
|
|
5
|
-
import { fetchSchedule, selectData, selectLoading } from '../features/schedule';
|
|
6
|
-
|
|
7
|
-
import Grid from './Grid';
|
|
8
|
-
import useKey from '../hooks/useKey';
|
|
9
|
-
|
|
10
|
-
const formatGame = game => {
|
|
11
|
-
const startTime = format(new Date(game.gameDate), 'p');
|
|
12
|
-
const start = (game.doubleHeader === 'Y' && game.gameNumber > 1) ?
|
|
13
|
-
'Game ' + game.gameNumber :
|
|
14
|
-
startTime;
|
|
15
|
-
const teamName = (team) => `${team.team.teamName} (${team.leagueRecord.wins}-${team.leagueRecord.losses})`.padEnd(20);
|
|
16
|
-
let content = [start, teamName(game.teams.away), teamName(game.teams.home)];
|
|
17
|
-
const gameState = game.status.abstractGameCode;
|
|
18
|
-
const detailedState = game.status.detailedState;
|
|
19
|
-
switch (gameState) {
|
|
20
|
-
case 'P':
|
|
21
|
-
break;
|
|
22
|
-
case 'L':
|
|
23
|
-
if (detailedState === 'Warmup') {
|
|
24
|
-
content[0] = detailedState;
|
|
25
|
-
} else {
|
|
26
|
-
content[0] = game.linescore.inningState + ' ' + game.linescore.currentInningOrdinal;
|
|
27
|
-
if (detailedState !== 'In Progress') {
|
|
28
|
-
content[0] += ' | ' + detailedState;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (game.linescore) {
|
|
32
|
-
content[0] = content[0].padEnd(20) + ' R H E';
|
|
33
|
-
content[1] += game.linescore.teams.away.runs.toString().padStart(2) +
|
|
34
|
-
game.linescore.teams.away.hits.toString().padStart(3) +
|
|
35
|
-
game.linescore.teams.away.errors.toString().padStart(3);
|
|
36
|
-
content[2] += game.linescore.teams.home.runs.toString().padStart(2) +
|
|
37
|
-
game.linescore.teams.home.hits.toString().padStart(3) +
|
|
38
|
-
game.linescore.teams.home.errors.toString().padStart(3);
|
|
39
|
-
}
|
|
40
|
-
break;
|
|
41
|
-
case 'F':
|
|
42
|
-
content[0] = detailedState;
|
|
43
|
-
if (game.status.reason) {
|
|
44
|
-
content[0] += ' | ' + game.status.reason;
|
|
45
|
-
}
|
|
46
|
-
if (game.linescore) {
|
|
47
|
-
if (game.linescore.currentInning !== game.scheduledInnings) {
|
|
48
|
-
content[0] += '/' + game.linescore.currentInning;
|
|
49
|
-
}
|
|
50
|
-
content[0] = content[0].padEnd(20) + ' R H E';
|
|
51
|
-
content[1] += game.linescore.teams.away.runs.toString().padStart(2) +
|
|
52
|
-
game.linescore.teams.away.hits.toString().padStart(3) +
|
|
53
|
-
game.linescore.teams.away.errors.toString().padStart(3);
|
|
54
|
-
content[2] += game.linescore.teams.home.runs.toString().padStart(2) +
|
|
55
|
-
game.linescore.teams.home.hits.toString().padStart(3) +
|
|
56
|
-
game.linescore.teams.home.errors.toString().padStart(3);
|
|
57
|
-
if (game.teams.away.isWinner) {
|
|
58
|
-
content[1] = `{bold}${content[1]}{/bold}`;
|
|
59
|
-
}
|
|
60
|
-
if (game.teams.home.isWinner) {
|
|
61
|
-
content[2] = `{bold}${content[2]}{/bold}`;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
return content.map(s => ' ' + s).join('\n');
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const GAME_STATE_ORDER = {
|
|
70
|
-
L: 0,
|
|
71
|
-
P: 1,
|
|
72
|
-
F: 2,
|
|
73
|
-
};
|
|
74
|
-
function compareGameState(a, b) {
|
|
75
|
-
return GAME_STATE_ORDER[a.status.abstractGameCode] - GAME_STATE_ORDER[b.status.abstractGameCode];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function compareGameInnings(a, b) {
|
|
79
|
-
const inningCompare = b.linescore.currentInning - a.linescore.currentInning;
|
|
80
|
-
if (inningCompare !== 0) {
|
|
81
|
-
return inningCompare;
|
|
82
|
-
}
|
|
83
|
-
if (a.isTopInning && !b.isTopInning) {
|
|
84
|
-
return -1;
|
|
85
|
-
}
|
|
86
|
-
if (b.isTopInning && !a.isTopInning) {
|
|
87
|
-
return 1;
|
|
88
|
-
}
|
|
89
|
-
return 0;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function compareGames(a, b) {
|
|
93
|
-
const stateCompare = compareGameState(a, b);
|
|
94
|
-
if (stateCompare !== 0) {
|
|
95
|
-
return stateCompare;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (a.status.abstractGameCode === 'L') {
|
|
99
|
-
const inningCompare = compareGameInnings(a, b);
|
|
100
|
-
if (inningCompare !== 0) {
|
|
101
|
-
return inningCompare;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return 0;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function GameList({ onGameSelect }) {
|
|
109
|
-
const dispatch = useDispatch();
|
|
110
|
-
const schedule = useSelector(selectData);
|
|
111
|
-
const loading = useSelector(selectLoading);
|
|
112
|
-
const timerRef = useRef(null);
|
|
113
|
-
const [date, setDate] = useState(new Date());
|
|
114
|
-
let games = [];
|
|
115
|
-
if (schedule && schedule.dates.length > 0) {
|
|
116
|
-
games = schedule.dates[0].games.slice().sort(compareGames);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
useEffect(() => {
|
|
120
|
-
dispatch(fetchSchedule(date));
|
|
121
|
-
timerRef.current = setInterval(() => dispatch(fetchSchedule(date)), 30000);
|
|
122
|
-
return () => clearInterval(timerRef.current);
|
|
123
|
-
}, [date]);
|
|
124
|
-
|
|
125
|
-
useKey('p', useCallback(() => setDate(prev => add(prev, { days: -1 })), []), { key: 'P', label: 'Prev Day' });
|
|
126
|
-
useKey('n', useCallback(() => setDate(prev => add(prev, { days: 1 })), []), { key: 'N', label: 'Next Day' });
|
|
127
|
-
useKey('t', useCallback(() => setDate(new Date()), []), { key: 'T', label: 'Today' });
|
|
128
|
-
|
|
129
|
-
const handleGameSelect = (idx) => {
|
|
130
|
-
const selected = games[idx];
|
|
131
|
-
onGameSelect(selected);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const messageStyle = {
|
|
135
|
-
left: 0,
|
|
136
|
-
top: 0,
|
|
137
|
-
height: '100%',
|
|
138
|
-
width: '100%',
|
|
139
|
-
align: 'center',
|
|
140
|
-
valign: 'middle',
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
return (
|
|
144
|
-
<element>
|
|
145
|
-
<box top={0} left={0} width='100%' height={1} align='center' valign='middle' style={{ bg: 'white', fg: 'black' }} content={format(date, 'PPPP')}></box>
|
|
146
|
-
<element top={2} left={0} width='100%' height='100%-2'>
|
|
147
|
-
{(!schedule && loading) && <box {...messageStyle} content='Loading...' />}
|
|
148
|
-
{(schedule && games.length === 0) && <box {...messageStyle} content='No games today' />}
|
|
149
|
-
{(schedule && games.length > 0) && (
|
|
150
|
-
<Grid
|
|
151
|
-
items={games.map(formatGame)}
|
|
152
|
-
itemHeight={5}
|
|
153
|
-
itemMinWidth={34}
|
|
154
|
-
onSelect={handleGameSelect}
|
|
155
|
-
/>
|
|
156
|
-
)}
|
|
157
|
-
</element>
|
|
158
|
-
</element>
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
GameList.propTypes = {
|
|
163
|
-
onGameSelect: PropTypes.func,
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export default GameList;
|
package/src/components/Grid.jsx
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import useKey from '../hooks/useKey';
|
|
4
|
-
|
|
5
|
-
function Grid({ items, itemHeight, itemMinWidth, onSelect }) {
|
|
6
|
-
const containerRef = useRef();
|
|
7
|
-
const [size, setSize] = useState([0, 0]);
|
|
8
|
-
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
9
|
-
const updateSize = () => setSize([containerRef.current?.width, containerRef.current?.height]);
|
|
10
|
-
useEffect(updateSize, []);
|
|
11
|
-
|
|
12
|
-
const pos = [];
|
|
13
|
-
let row = 0;
|
|
14
|
-
let col = 0;
|
|
15
|
-
const numCols = Math.floor(size[0] / itemMinWidth);
|
|
16
|
-
const colWidth = Math.floor(size[0] / numCols);
|
|
17
|
-
for (let i = 0; i < items.length; i++) {
|
|
18
|
-
pos.push({
|
|
19
|
-
top: row,
|
|
20
|
-
left: col,
|
|
21
|
-
width: colWidth,
|
|
22
|
-
height: itemHeight,
|
|
23
|
-
});
|
|
24
|
-
col += colWidth;
|
|
25
|
-
if (col > size[0] - colWidth) {
|
|
26
|
-
col = 0;
|
|
27
|
-
row += itemHeight;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
const curr = pos[selectedIndex].top;
|
|
33
|
-
const total = pos[pos.length - 1].top;
|
|
34
|
-
const perc = Math.round(curr / total * 100);
|
|
35
|
-
containerRef.current.setScrollPerc(perc);
|
|
36
|
-
}, [pos, selectedIndex]);
|
|
37
|
-
|
|
38
|
-
useKey(['right', 'l'], useCallback(() => setSelectedIndex(prev => Math.min(prev + 1, items.length - 1)), [items.length]));
|
|
39
|
-
useKey(['left', 'h'], useCallback(() => setSelectedIndex(prev => Math.max(prev - 1, 0)), []));
|
|
40
|
-
useKey(['down', 'j'], useCallback(() => {
|
|
41
|
-
setSelectedIndex(prev => {
|
|
42
|
-
const next = prev + numCols;
|
|
43
|
-
if (next < items.length) {
|
|
44
|
-
return next;
|
|
45
|
-
} else {
|
|
46
|
-
return prev;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}, [numCols, items.length]));
|
|
50
|
-
useKey(['up', 'k'], useCallback(() => {
|
|
51
|
-
setSelectedIndex(prev => {
|
|
52
|
-
const next = prev - numCols;
|
|
53
|
-
if (next >= 0) {
|
|
54
|
-
return next;
|
|
55
|
-
} else {
|
|
56
|
-
return prev;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}, [numCols]));
|
|
60
|
-
useKey('enter', () => onSelect(selectedIndex));
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
<box
|
|
64
|
-
ref={containerRef}
|
|
65
|
-
onResize={updateSize}
|
|
66
|
-
width='100%'
|
|
67
|
-
height='100%'
|
|
68
|
-
scrollable={true}
|
|
69
|
-
>
|
|
70
|
-
{pos.map((p, idx) => (
|
|
71
|
-
<box
|
|
72
|
-
{...p}
|
|
73
|
-
border={{type: selectedIndex === idx ? 'line' : 'bg'}}
|
|
74
|
-
key={items[idx]}
|
|
75
|
-
tags
|
|
76
|
-
content={items[idx]}
|
|
77
|
-
wrap={false}
|
|
78
|
-
/>
|
|
79
|
-
))}
|
|
80
|
-
</box>
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
Grid.propTypes = {
|
|
85
|
-
items: PropTypes.arrayOf(PropTypes.string),
|
|
86
|
-
itemHeight: PropTypes.number,
|
|
87
|
-
itemMinWidth: PropTypes.number,
|
|
88
|
-
onSelect: PropTypes.func,
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export default Grid;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useSelector } from 'react-redux';
|
|
3
|
-
import LoadingSpinner from './LoadingSpinner';
|
|
4
|
-
|
|
5
|
-
const HelpBar = () => {
|
|
6
|
-
const keys = useSelector(state => state.keys);
|
|
7
|
-
const content = keys.map(({ key, label }) => `{inverse}${key}{/inverse}:${label}`).join(' ');
|
|
8
|
-
return (
|
|
9
|
-
<element>
|
|
10
|
-
<LoadingSpinner />
|
|
11
|
-
<box left={3}
|
|
12
|
-
content={content}
|
|
13
|
-
tags
|
|
14
|
-
/>
|
|
15
|
-
</element>
|
|
16
|
-
);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export default HelpBar;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useSelector } from 'react-redux';
|
|
3
|
-
|
|
4
|
-
import { selectLineScore } from '../features/games';
|
|
5
|
-
|
|
6
|
-
function InningDisplay() {
|
|
7
|
-
const linescore = useSelector(selectLineScore);
|
|
8
|
-
const content = [
|
|
9
|
-
linescore.isTopInning ? '▲' : '',
|
|
10
|
-
linescore.currentInning,
|
|
11
|
-
linescore.isTopInning ? '' : '▼'
|
|
12
|
-
].join('\n');
|
|
13
|
-
|
|
14
|
-
return (
|
|
15
|
-
<box content={content} align='right' />
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default InningDisplay;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { useSelector } from 'react-redux';
|
|
4
|
-
import { selectLineScore, selectTeams } from '../features/games';
|
|
5
|
-
|
|
6
|
-
const getRuns = (inning, homeAway, isFinal) => {
|
|
7
|
-
const runs = inning[homeAway].runs;
|
|
8
|
-
if (runs !== undefined) {
|
|
9
|
-
return runs;
|
|
10
|
-
}
|
|
11
|
-
return isFinal ? 'X' : '';
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const getTeamLine = (linescore, totalInnings, homeAway, final) => (
|
|
15
|
-
linescore.innings
|
|
16
|
-
.map(inning => getRuns(inning, homeAway, final))
|
|
17
|
-
.map(r => r.toString().padStart(2))
|
|
18
|
-
.join(' ')
|
|
19
|
-
.padEnd(totalInnings * 3) +
|
|
20
|
-
'{bold}' +
|
|
21
|
-
linescore.teams[homeAway].runs.toString().padStart(3) + '{/bold}' +
|
|
22
|
-
linescore.teams[homeAway].hits.toString().padStart(3) +
|
|
23
|
-
linescore.teams[homeAway].errors.toString().padStart(3)
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
function LineScore({ align, final }) {
|
|
27
|
-
const linescore = useSelector(selectLineScore);
|
|
28
|
-
const teams = useSelector(selectTeams);
|
|
29
|
-
|
|
30
|
-
const currentInning = linescore.currentInning;
|
|
31
|
-
if (!currentInning) {
|
|
32
|
-
return '';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const totalInnings = Math.max(currentInning, 9);
|
|
36
|
-
const home = teams.home.abbreviation;
|
|
37
|
-
const away = teams.away.abbreviation;
|
|
38
|
-
const teamNameLength = 3;
|
|
39
|
-
let str = ''.padEnd(teamNameLength) + Array.from(Array(totalInnings).keys()).map(i => (i + 1).toString().padStart(2)).join(' ') + ' {bold}R{/bold} H E\n' +
|
|
40
|
-
away.padEnd(teamNameLength) + getTeamLine(linescore, totalInnings, 'away', final) + '\n' +
|
|
41
|
-
home.padEnd(teamNameLength) + getTeamLine(linescore, totalInnings, 'home', final);
|
|
42
|
-
return (
|
|
43
|
-
<box align={align} content={str} tags wrap={false} />
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
LineScore.propTypes = {
|
|
48
|
-
align: PropTypes.oneOf(['left', 'center', 'right']),
|
|
49
|
-
final: PropTypes.bool,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export default LineScore;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import Count from './Count';
|
|
4
|
-
import Bases from './Bases';
|
|
5
|
-
import LineScore from './LineScore';
|
|
6
|
-
import Matchup from './Matchup';
|
|
7
|
-
import AtBat from './AtBat';
|
|
8
|
-
import AllPlays from './AllPlays';
|
|
9
|
-
import InningDisplay from './InningDisplay';
|
|
10
|
-
|
|
11
|
-
function LiveGame() {
|
|
12
|
-
return (
|
|
13
|
-
<element>
|
|
14
|
-
<element top={0} left={1} width='100%-1' height={3}>
|
|
15
|
-
<element left={0} width={2}>
|
|
16
|
-
<InningDisplay />
|
|
17
|
-
</element>
|
|
18
|
-
<element left={5} width='25%-5'>
|
|
19
|
-
<Count />
|
|
20
|
-
</element>
|
|
21
|
-
<element left='25%+1' width='25%'>
|
|
22
|
-
<Bases />
|
|
23
|
-
</element>
|
|
24
|
-
<element left='50%+2' width='50%-2'>
|
|
25
|
-
<LineScore />
|
|
26
|
-
</element>
|
|
27
|
-
</element>
|
|
28
|
-
<line orientation='horizontal' type='line' top={3} width='100%' />
|
|
29
|
-
<element top={4} left={1}>
|
|
30
|
-
<element width='50%-1'>
|
|
31
|
-
<element top={0} height={2}>
|
|
32
|
-
<Matchup />
|
|
33
|
-
</element>
|
|
34
|
-
<element top={3}>
|
|
35
|
-
<AtBat />
|
|
36
|
-
</element>
|
|
37
|
-
</element>
|
|
38
|
-
<line orientation='vertical' type='line' left='50%' />
|
|
39
|
-
<element left='50%+2' width='50%-2'>
|
|
40
|
-
<AllPlays />
|
|
41
|
-
</element>
|
|
42
|
-
</element>
|
|
43
|
-
</element>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default LiveGame;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { useSelector } from 'react-redux';
|
|
3
|
-
import { selectLoading as selectScheduleLoading } from '../features/schedule';
|
|
4
|
-
import { selectLoading as gamesLoading } from '../features/games';
|
|
5
|
-
|
|
6
|
-
const frames = [
|
|
7
|
-
'⠋',
|
|
8
|
-
'⠙',
|
|
9
|
-
'⠹',
|
|
10
|
-
'⠸',
|
|
11
|
-
'⠼',
|
|
12
|
-
'⠴',
|
|
13
|
-
'⠦',
|
|
14
|
-
'⠧',
|
|
15
|
-
'⠇',
|
|
16
|
-
'⠏'
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
function LoadingSpinner() {
|
|
20
|
-
const [frame, setFrame] = useState(0);
|
|
21
|
-
const [animating, setAnimating] = useState(false);
|
|
22
|
-
const timerRef = useRef(null);
|
|
23
|
-
const scheduleLoading = useSelector(selectScheduleLoading);
|
|
24
|
-
const gameLoading = useSelector(gamesLoading);
|
|
25
|
-
|
|
26
|
-
const increment = () => {
|
|
27
|
-
setFrame(prevFrame => (prevFrame + 1) % frames.length);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const doUpdate = () => {
|
|
31
|
-
if (!animating && (gameLoading || scheduleLoading)) {
|
|
32
|
-
setAnimating(true);
|
|
33
|
-
increment();
|
|
34
|
-
timerRef.current = setInterval(increment, 50);
|
|
35
|
-
}
|
|
36
|
-
if (!gameLoading && !scheduleLoading && frame === 0) {
|
|
37
|
-
setAnimating(false);
|
|
38
|
-
clearInterval(timerRef.current);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
doUpdate();
|
|
44
|
-
}, [gameLoading, scheduleLoading, frame]);
|
|
45
|
-
|
|
46
|
-
return <box content={animating ? frames[frame] : ' '} />;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default LoadingSpinner;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useSelector } from 'react-redux';
|
|
3
|
-
import { selectCurrentPlay, selectBoxscore, selectTeams } from '../features/games';
|
|
4
|
-
|
|
5
|
-
const getPlayerStats = (boxscore, teams, id) => {
|
|
6
|
-
const key = 'ID' + id;
|
|
7
|
-
const homePlayers = boxscore.home.players;
|
|
8
|
-
if (homePlayers[key]) {
|
|
9
|
-
return {
|
|
10
|
-
team: teams.home,
|
|
11
|
-
player: homePlayers[key],
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
team: teams.away,
|
|
16
|
-
player: boxscore.away.players[key],
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
function Matchup() {
|
|
21
|
-
const boxscore = useSelector(selectBoxscore);
|
|
22
|
-
const currentPlay = useSelector(selectCurrentPlay);
|
|
23
|
-
const teams = useSelector(selectTeams);
|
|
24
|
-
|
|
25
|
-
const pitcherId = currentPlay.matchup?.pitcher?.id;
|
|
26
|
-
const batterId = currentPlay.matchup?.batter?.id;
|
|
27
|
-
|
|
28
|
-
const {team: pitchTeam, player: pitcher} = getPlayerStats(boxscore, teams, pitcherId);
|
|
29
|
-
const {team: batTeam, player: batter} = getPlayerStats(boxscore, teams, batterId);
|
|
30
|
-
|
|
31
|
-
const display = `${pitchTeam.abbreviation} Pitching: ` +
|
|
32
|
-
`{bold}${pitcher.person.fullName}{/bold} ${pitcher.stats.pitching.inningsPitched} IP, ${pitcher.stats.pitching.pitchesThrown || 0} P, ${pitcher.seasonStats.pitching.era} ERA\n` +
|
|
33
|
-
`${batTeam.abbreviation} At Bat: ` +
|
|
34
|
-
`{bold}${batter.person.fullName}{/bold} ${batter.stats.batting.hits}-${batter.stats.batting.atBats}, ${batter.seasonStats.batting.avg} AVG, ${batter.seasonStats.batting.homeRuns} HR`;
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<box tags content={display} wrap={false} />
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default Matchup;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useSelector } from 'react-redux';
|
|
3
|
-
import { format } from 'date-fns';
|
|
4
|
-
import { selectTeams, selectVenue, selectStartTime, selectBoxscore, selectProbablePitchers, selectGameStatus } from '../features/games';
|
|
5
|
-
|
|
6
|
-
const formatPitcherName = (pitcher) => {
|
|
7
|
-
let display = pitcher.person.fullName;
|
|
8
|
-
const number = pitcher.jerseyNumber;
|
|
9
|
-
if (number) {
|
|
10
|
-
display += `, #${number}`;
|
|
11
|
-
}
|
|
12
|
-
return display;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const formatTeam = (teams, probables, boxscore, homeAway) => {
|
|
16
|
-
const pitcherId = probables[homeAway].id;
|
|
17
|
-
const pitcher = boxscore[homeAway].players['ID' + pitcherId];
|
|
18
|
-
let lines = [
|
|
19
|
-
teams[homeAway].teamName,
|
|
20
|
-
`(${teams[homeAway].record.wins}-${teams[homeAway].record.losses})`,
|
|
21
|
-
];
|
|
22
|
-
if (pitcher) {
|
|
23
|
-
lines = lines.concat([
|
|
24
|
-
'',
|
|
25
|
-
formatPitcherName(pitcher),
|
|
26
|
-
`${pitcher.seasonStats?.pitching?.wins}-${pitcher.seasonStats?.pitching?.losses}`,
|
|
27
|
-
`${pitcher.seasonStats?.pitching?.era} ERA ${pitcher.seasonStats?.pitching?.strikeOuts} K`,
|
|
28
|
-
]);
|
|
29
|
-
}
|
|
30
|
-
return lines;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
function PreviewGame() {
|
|
34
|
-
const boxscore = useSelector(selectBoxscore);
|
|
35
|
-
const probables = useSelector(selectProbablePitchers);
|
|
36
|
-
const startTime = useSelector(selectStartTime);
|
|
37
|
-
const status = useSelector(selectGameStatus);
|
|
38
|
-
const teams = useSelector(selectTeams);
|
|
39
|
-
const venue = useSelector(selectVenue);
|
|
40
|
-
const away = formatTeam(teams, probables, boxscore, 'away');
|
|
41
|
-
const home = formatTeam(teams, probables, boxscore, 'home');
|
|
42
|
-
const formattedStart = status.startTimeTBD ? 'Start time TBD' : format(new Date(startTime), 'MMMM d, yyy p');
|
|
43
|
-
return (
|
|
44
|
-
<element>
|
|
45
|
-
<element height='60%'>
|
|
46
|
-
<box content={away.join('\n')} width='33%-1' top='50%' align='center' />
|
|
47
|
-
<box content={`\nvs.\n\n${formattedStart}\n${venue.name}\n${venue.location.city}, ${venue.location.stateAbbrev}`} width='33%-1' left='33%' top='50%' align='center' />
|
|
48
|
-
<box content={home.join('\n')} width='34%' top='50%' left='66%' align='center' />
|
|
49
|
-
</element>
|
|
50
|
-
</element>
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export default PreviewGame;
|