playball 3.1.0 → 3.1.2

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.
Files changed (57) hide show
  1. package/dist/cli.js +31 -0
  2. package/{src/components/AllPlays.jsx → dist/components/AllPlays.js} +22 -37
  3. package/dist/components/App.js +42 -0
  4. package/dist/components/AtBat.js +42 -0
  5. package/dist/components/Bases.js +23 -0
  6. package/dist/components/Count.js +21 -0
  7. package/dist/components/FinishedGame.js +90 -0
  8. package/dist/components/Game.js +50 -0
  9. package/dist/components/GameList.js +171 -0
  10. package/{src/components/Grid.jsx → dist/components/Grid.js} +30 -33
  11. package/dist/components/HelpBar.js +16 -0
  12. package/dist/components/InningDisplay.js +12 -0
  13. package/dist/components/LineScore.js +39 -0
  14. package/dist/components/LiveGame.js +51 -0
  15. package/{src/components/LoadingSpinner.jsx → dist/components/LoadingSpinner.js} +8 -24
  16. package/dist/components/Matchup.js +40 -0
  17. package/dist/components/PreviewGame.js +54 -0
  18. package/dist/components/Standings.js +70 -0
  19. package/{src → dist}/config.js +21 -62
  20. package/dist/features/games.js +100 -0
  21. package/{src → dist}/features/keys.js +19 -10
  22. package/dist/features/schedule.js +43 -0
  23. package/dist/features/standings.js +43 -0
  24. package/{src → dist}/hooks/useKey.js +3 -5
  25. package/dist/logger.js +11 -0
  26. package/dist/main.js +20 -0
  27. package/{src → dist}/package.js +2 -4
  28. package/{src → dist}/screen.js +2 -8
  29. package/dist/store/index.js +19 -0
  30. package/{src → dist}/style/index.js +2 -2
  31. package/{src → dist}/utils.js +4 -5
  32. package/package.json +5 -1
  33. package/.eslintrc.json +0 -33
  34. package/CODE_OF_CONDUCT.md +0 -76
  35. package/demo.cast +0 -95
  36. package/demo.gif +0 -0
  37. package/src/cli.js +0 -46
  38. package/src/components/App.jsx +0 -43
  39. package/src/components/AtBat.jsx +0 -41
  40. package/src/components/Bases.jsx +0 -23
  41. package/src/components/Count.jsx +0 -25
  42. package/src/components/FinishedGame.jsx +0 -76
  43. package/src/components/Game.jsx +0 -60
  44. package/src/components/GameList.jsx +0 -169
  45. package/src/components/HelpBar.jsx +0 -19
  46. package/src/components/InningDisplay.jsx +0 -19
  47. package/src/components/LineScore.jsx +0 -52
  48. package/src/components/LiveGame.jsx +0 -47
  49. package/src/components/Matchup.jsx +0 -41
  50. package/src/components/PreviewGame.jsx +0 -54
  51. package/src/components/Standings.jsx +0 -81
  52. package/src/features/games.js +0 -166
  53. package/src/features/schedule.js +0 -60
  54. package/src/features/standings.js +0 -61
  55. package/src/logger.js +0 -19
  56. package/src/main.js +0 -27
  57. package/src/store/index.js +0 -19
package/src/cli.js DELETED
@@ -1,46 +0,0 @@
1
- /* eslint no-console: 0 */
2
- import { Command } from 'commander';
3
- import updateNotifier from 'update-notifier';
4
-
5
- import * as config from './config.js';
6
- import main from './main.js';
7
- import pkg from './package.js';
8
-
9
- const program = new Command();
10
- const notifier = updateNotifier({
11
- pkg,
12
- updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week
13
- });
14
-
15
- program
16
- .name(pkg.name)
17
- .description(pkg.description)
18
- .version(pkg.version)
19
- .action(main)
20
- .hook('postAction', () => notifier.notify({
21
- isGlobal: true,
22
- }));
23
-
24
- program.command('config')
25
- .description('Set or get configration values')
26
- .argument('[key]')
27
- .argument('[value]')
28
- .option('--unset', 'Unset configuration value')
29
- .action((key, value, options) => {
30
- if (options.unset) {
31
- config.unset(key);
32
- return;
33
- }
34
- if (!key) {
35
- for (const [key, value] of Object.entries(config.getAll())) {
36
- console.log(`${key} = ${value}`);
37
- }
38
- } else if (!value) {
39
- console.log(config.get(key));
40
- } else {
41
- config.set(key, value);
42
- }
43
- });
44
-
45
-
46
- program.parse();
@@ -1,43 +0,0 @@
1
- import React, { useState } from 'react';
2
- import { useDispatch } from 'react-redux';
3
- import GameList from './GameList.js';
4
- import HelpBar from './HelpBar.js';
5
- import { setSelectedId } from '../features/games.js';
6
- import Game from './Game.js';
7
- import useKey from '../hooks/useKey.js';
8
- import Standings from './Standings.js';
9
-
10
- const SCHEDULE = 'schedule';
11
- const STANDINGS = 'standings';
12
- const GAME = 'game';
13
-
14
- function App() {
15
- const [view, setView] = useState(SCHEDULE);
16
- const dispatch = useDispatch();
17
-
18
- useKey('c', () => {
19
- setView(SCHEDULE);
20
- dispatch(setSelectedId(null));
21
- }, { key: 'C', label: 'Schedule' });
22
- useKey('s', () => setView(STANDINGS), { key: 'S', label: 'Standings'});
23
-
24
- const handleGameSelect = (game) => {
25
- dispatch(setSelectedId(game.gamePk));
26
- setView(GAME);
27
- };
28
-
29
- return (
30
- <element>
31
- <element top={0} left={0} height='100%-1'>
32
- {view === STANDINGS && <Standings />}
33
- {view === SCHEDULE && <GameList onGameSelect={handleGameSelect} />}
34
- {view === GAME && <Game />}
35
- </element>
36
- <element top='100%-1' left={0} height={1}>
37
- <HelpBar />
38
- </element>
39
- </element>
40
- );
41
- }
42
-
43
- export default App;
@@ -1,41 +0,0 @@
1
- import React from 'react';
2
- import { useSelector } from 'react-redux';
3
- import { selectCurrentPlay } from '../features/games.js';
4
-
5
- function AtBat() {
6
- const currentPlay = useSelector(selectCurrentPlay);
7
- const playEvents = currentPlay.playEvents;
8
- const playResult = currentPlay.about.isComplete ? currentPlay.result.description : '';
9
- let content = '';
10
- if (playResult) {
11
- content += `${playResult}\n\n`;
12
- }
13
- if (playEvents && playEvents.length) {
14
- content += playEvents.slice().reverse().map(event => {
15
- let line = '';
16
- if (event.isPitch) {
17
- line = `[${event.details.description}] `;
18
- if (event.pitchData?.startSpeed) {
19
- line += `${event.pitchData.startSpeed} MPH `;
20
- }
21
- if (event.details?.type?.description) {
22
- line += event.details.type.description;
23
- }
24
- if (!event.details?.isInPlay) {
25
- line += `{|} ${event.count.balls}-${event.count.strikes}`;
26
- }
27
- } else {
28
- if (event.details?.event) {
29
- line += `[${event.details.event}] `;
30
- }
31
- line += event.details.description;
32
- }
33
- return line;
34
- }).join('\n');
35
- }
36
- return (
37
- <box content={content} tags />
38
- );
39
- }
40
-
41
- export default AtBat;
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import { useSelector } from 'react-redux';
3
- import PropTypes from 'prop-types';
4
- import { get } from '../config.js';
5
- import { selectLineScore } from '../features/games.js';
6
-
7
- const formatBase = (offense, base) => (base in offense) ? `{${get('color.on-base')}-fg}◆{/}` : '◇';
8
-
9
- function Bases({align}) {
10
- const { offense } = useSelector(selectLineScore);
11
- const content =
12
- ` ${formatBase(offense, 'second')}\n` +
13
- `${formatBase(offense, 'third')} ${formatBase(offense, 'first')}`;
14
- return (
15
- <box align={align} content={content} tags />
16
- );
17
- }
18
-
19
- Bases.propTypes = {
20
- align: PropTypes.oneOf(['left', 'center', 'right']),
21
- };
22
-
23
- export default Bases;
@@ -1,25 +0,0 @@
1
- import React from 'react';
2
- import { useSelector } from 'react-redux';
3
- import PropTypes from 'prop-types';
4
-
5
- import { get } from '../config.js';
6
- import { selectLineScore } from '../features/games.js';
7
-
8
- const formatCount = (count, total) => '● '.repeat(count) + '○ '.repeat(total - count);
9
-
10
- function Count({align}) {
11
- const linescore = useSelector(selectLineScore);
12
- const content =
13
- `B: {${get('color.ball')}-fg}${formatCount(linescore.balls, 4)}{/}\n` +
14
- `S: {${get('color.strike')}-fg}${formatCount(linescore.strikes, 3)}{/}\n` +
15
- `O: {${get('color.out')}-fg}${formatCount(linescore.outs, 3)}{/}`;
16
- return (
17
- <box align={align} content={content} tags />
18
- );
19
- }
20
-
21
- Count.propTypes = {
22
- align: PropTypes.oneOf(['left', 'center', 'right']),
23
- };
24
-
25
- export default Count;
@@ -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.js';
4
- import LineScore from './LineScore.js';
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;
@@ -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.js';
5
-
6
- import PreviewGame from './PreviewGame.js';
7
- import LiveGame from './LiveGame.js';
8
- import FinishedGame from './FinishedGame.js';
9
-
10
- import log from '../logger.js';
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,169 +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.js';
6
- import { teamFavoriteStar } from '../utils.js';
7
- import Grid from './Grid.js';
8
- import useKey from '../hooks/useKey.js';
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) => {
16
- const star = teamFavoriteStar(team.team);
17
- return star + `${team.team.teamName} (${team.leagueRecord.wins}-${team.leagueRecord.losses})`.padEnd(star ? 18 : 20);
18
- };
19
- let content = [start, teamName(game.teams.away), teamName(game.teams.home)];
20
- const gameState = game.status.abstractGameCode;
21
- const detailedState = game.status.detailedState;
22
- switch (gameState) {
23
- case 'P':
24
- break;
25
- case 'L':
26
- if (detailedState === 'Warmup') {
27
- content[0] = detailedState;
28
- } else {
29
- content[0] = game.linescore.inningState + ' ' + game.linescore.currentInningOrdinal;
30
- if (detailedState !== 'In Progress') {
31
- content[0] += ' | ' + detailedState;
32
- }
33
- }
34
- if (game.linescore) {
35
- content[0] = content[0].padEnd(20) + ' R H E';
36
- content[1] += game.linescore.teams.away.runs.toString().padStart(2) +
37
- game.linescore.teams.away.hits.toString().padStart(3) +
38
- game.linescore.teams.away.errors.toString().padStart(3);
39
- content[2] += game.linescore.teams.home.runs.toString().padStart(2) +
40
- game.linescore.teams.home.hits.toString().padStart(3) +
41
- game.linescore.teams.home.errors.toString().padStart(3);
42
- }
43
- break;
44
- case 'F':
45
- content[0] = detailedState;
46
- if (game.status.reason) {
47
- content[0] += ' | ' + game.status.reason;
48
- }
49
- if (game.linescore) {
50
- if (game.linescore.currentInning !== game.scheduledInnings) {
51
- content[0] += '/' + game.linescore.currentInning;
52
- }
53
- content[0] = content[0].padEnd(20) + ' R H E';
54
- content[1] += game.linescore.teams.away.runs.toString().padStart(2) +
55
- game.linescore.teams.away.hits.toString().padStart(3) +
56
- game.linescore.teams.away.errors.toString().padStart(3);
57
- content[2] += game.linescore.teams.home.runs.toString().padStart(2) +
58
- game.linescore.teams.home.hits.toString().padStart(3) +
59
- game.linescore.teams.home.errors.toString().padStart(3);
60
- if (game.teams.away.isWinner) {
61
- content[1] = `{bold}${content[1]}{/bold}`;
62
- }
63
- if (game.teams.home.isWinner) {
64
- content[2] = `{bold}${content[2]}{/bold}`;
65
- }
66
- }
67
- break;
68
- }
69
- return content.map(s => ' ' + s).join('\n');
70
- };
71
-
72
- const GAME_STATE_ORDER = {
73
- L: 0,
74
- P: 1,
75
- F: 2,
76
- };
77
- function compareGameState(a, b) {
78
- return GAME_STATE_ORDER[a.status.abstractGameCode] - GAME_STATE_ORDER[b.status.abstractGameCode];
79
- }
80
-
81
- function compareGameInnings(a, b) {
82
- const inningCompare = b.linescore.currentInning - a.linescore.currentInning;
83
- if (inningCompare !== 0) {
84
- return inningCompare;
85
- }
86
- if (a.isTopInning && !b.isTopInning) {
87
- return -1;
88
- }
89
- if (b.isTopInning && !a.isTopInning) {
90
- return 1;
91
- }
92
- return 0;
93
- }
94
-
95
- function compareGames(a, b) {
96
- const stateCompare = compareGameState(a, b);
97
- if (stateCompare !== 0) {
98
- return stateCompare;
99
- }
100
-
101
- if (a.status.abstractGameCode === 'L') {
102
- const inningCompare = compareGameInnings(a, b);
103
- if (inningCompare !== 0) {
104
- return inningCompare;
105
- }
106
- }
107
-
108
- return 0;
109
- }
110
-
111
- function GameList({ onGameSelect }) {
112
- const dispatch = useDispatch();
113
- const schedule = useSelector(selectData);
114
- const loading = useSelector(selectLoading);
115
- const timerRef = useRef(null);
116
- const [date, setDate] = useState(new Date());
117
- let games = [];
118
- if (schedule && schedule.dates.length > 0) {
119
- games = schedule.dates[0].games.slice().sort(compareGames);
120
- }
121
-
122
- useEffect(() => {
123
- dispatch(fetchSchedule(date));
124
- timerRef.current = setInterval(() => dispatch(fetchSchedule(date)), 30000);
125
- return () => clearInterval(timerRef.current);
126
- }, [date]);
127
-
128
- useKey('p', useCallback(() => setDate(prev => add(prev, { days: -1 })), []), { key: 'P', label: 'Prev Day' });
129
- useKey('n', useCallback(() => setDate(prev => add(prev, { days: 1 })), []), { key: 'N', label: 'Next Day' });
130
- useKey('t', useCallback(() => setDate(new Date()), []), { key: 'T', label: 'Today' });
131
-
132
- const handleGameSelect = (idx) => {
133
- const selected = games[idx];
134
- onGameSelect(selected);
135
- };
136
-
137
- const messageStyle = {
138
- left: 0,
139
- top: 0,
140
- height: '100%',
141
- width: '100%',
142
- align: 'center',
143
- valign: 'middle',
144
- };
145
-
146
- return (
147
- <element>
148
- <box top={0} left={0} width='100%' height={1} align='center' valign='middle' style={{ bg: 'white', fg: 'black' }} content={format(date, 'PPPP')}></box>
149
- <element top={2} left={0} width='100%' height='100%-2'>
150
- {(!schedule && loading) && <box {...messageStyle} content='Loading...' />}
151
- {(schedule && games.length === 0) && <box {...messageStyle} content='No games today' />}
152
- {(schedule && games.length > 0) && (
153
- <Grid
154
- items={games.map(formatGame)}
155
- itemHeight={5}
156
- itemMinWidth={34}
157
- onSelect={handleGameSelect}
158
- />
159
- )}
160
- </element>
161
- </element>
162
- );
163
- }
164
-
165
- GameList.propTypes = {
166
- onGameSelect: PropTypes.func,
167
- };
168
-
169
- export default GameList;
@@ -1,19 +0,0 @@
1
- import React from 'react';
2
- import { useSelector } from 'react-redux';
3
- import LoadingSpinner from './LoadingSpinner.js';
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.js';
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.js';
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.js';
4
- import Bases from './Bases.js';
5
- import LineScore from './LineScore.js';
6
- import Matchup from './Matchup.js';
7
- import AtBat from './AtBat.js';
8
- import AllPlays from './AllPlays.js';
9
- import InningDisplay from './InningDisplay.js';
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,41 +0,0 @@
1
- import React from 'react';
2
- import { useSelector } from 'react-redux';
3
- import { selectCurrentPlay, selectBoxscore, selectTeams } from '../features/games.js';
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;