playball 3.1.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/dist/cli.js +31 -0
- package/{src/components/AllPlays.jsx → dist/components/AllPlays.js} +22 -37
- package/dist/components/App.js +42 -0
- package/dist/components/AtBat.js +42 -0
- package/dist/components/Bases.js +23 -0
- package/dist/components/Count.js +21 -0
- package/dist/components/FinishedGame.js +90 -0
- package/dist/components/Game.js +50 -0
- package/dist/components/GameList.js +171 -0
- package/{src/components/Grid.jsx → dist/components/Grid.js} +30 -33
- package/dist/components/HelpBar.js +16 -0
- package/dist/components/InningDisplay.js +12 -0
- package/dist/components/LineScore.js +39 -0
- package/dist/components/LiveGame.js +51 -0
- package/{src/components/LoadingSpinner.jsx → dist/components/LoadingSpinner.js} +8 -24
- package/dist/components/Matchup.js +40 -0
- package/dist/components/PreviewGame.js +54 -0
- package/dist/components/Standings.js +69 -0
- package/{src → dist}/config.js +21 -62
- package/dist/features/games.js +100 -0
- package/{src → dist}/features/keys.js +19 -10
- package/dist/features/schedule.js +43 -0
- package/dist/features/standings.js +43 -0
- package/{src → dist}/hooks/useKey.js +3 -5
- package/dist/logger.js +11 -0
- package/dist/main.js +20 -0
- package/{src → dist}/package.js +2 -4
- package/{src → dist}/screen.js +2 -8
- package/dist/store/index.js +19 -0
- package/{src → dist}/style/index.js +2 -2
- package/{src → dist}/utils.js +2 -4
- package/package.json +5 -1
- package/.eslintrc.json +0 -33
- package/CODE_OF_CONDUCT.md +0 -76
- package/demo.cast +0 -95
- package/demo.gif +0 -0
- package/src/cli.js +0 -46
- package/src/components/App.jsx +0 -43
- package/src/components/AtBat.jsx +0 -41
- package/src/components/Bases.jsx +0 -23
- package/src/components/Count.jsx +0 -25
- package/src/components/FinishedGame.jsx +0 -76
- package/src/components/Game.jsx +0 -60
- package/src/components/GameList.jsx +0 -169
- 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/Matchup.jsx +0 -41
- package/src/components/PreviewGame.jsx +0 -54
- package/src/components/Standings.jsx +0 -81
- package/src/features/games.js +0 -166
- package/src/features/schedule.js +0 -60
- package/src/features/standings.js +0 -61
- package/src/logger.js +0 -19
- package/src/main.js +0 -27
- package/src/store/index.js +0 -19
package/dist/cli.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* eslint no-console: 0 */
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import updateNotifier from 'update-notifier';
|
|
4
|
+
import * as config from "./config.js";
|
|
5
|
+
import main from "./main.js";
|
|
6
|
+
import pkg from "./package.js";
|
|
7
|
+
const program = new Command();
|
|
8
|
+
const notifier = updateNotifier({
|
|
9
|
+
pkg,
|
|
10
|
+
updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
program.name(pkg.name).description(pkg.description).version(pkg.version).action(main).hook('postAction', () => notifier.notify({
|
|
14
|
+
isGlobal: true
|
|
15
|
+
}));
|
|
16
|
+
program.command('config').description('Set or get configration values').argument('[key]').argument('[value]').option('--unset', 'Unset configuration value').action((key, value, options) => {
|
|
17
|
+
if (options.unset) {
|
|
18
|
+
config.unset(key);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (!key) {
|
|
22
|
+
for (const [key, value] of Object.entries(config.getAll())) {
|
|
23
|
+
console.log(`${key} = ${value}`);
|
|
24
|
+
}
|
|
25
|
+
} else if (!value) {
|
|
26
|
+
console.log(config.get(key));
|
|
27
|
+
} else {
|
|
28
|
+
config.set(key, value);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
program.parse();
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { useSelector } from
|
|
3
|
-
import { selectAllPlays, selectTeams } from
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import style from '../style/index.js';
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { useSelector } from "react-redux/lib/alternate-renderers.js";
|
|
3
|
+
import { selectAllPlays, selectTeams } from "../features/games.js";
|
|
4
|
+
import { get } from "../config.js";
|
|
5
|
+
import style from "../style/index.js";
|
|
9
6
|
function getPlayResultColor(play) {
|
|
10
|
-
|
|
7
|
+
var _play$playEvents;
|
|
8
|
+
const lastPlay = (_play$playEvents = play.playEvents[play.playEvents.length - 1]) === null || _play$playEvents === void 0 ? void 0 : _play$playEvents.details;
|
|
11
9
|
if (!lastPlay) {
|
|
12
10
|
return get('color.other-event');
|
|
13
11
|
} else if (lastPlay.isBall) {
|
|
@@ -20,23 +18,13 @@ function getPlayResultColor(play) {
|
|
|
20
18
|
return get('color.in-play-out');
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
function formatOut(out) {
|
|
25
22
|
return ` {bold}${out} out{/}`;
|
|
26
23
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
24
|
function AllPlays() {
|
|
30
25
|
const plays = useSelector(selectAllPlays);
|
|
31
26
|
const teams = useSelector(selectTeams);
|
|
32
|
-
|
|
33
|
-
const formatScoreDetail = (scoreObj) => (
|
|
34
|
-
` {bold}{${get('color.in-play-runs-bg')}-bg}{${get('color.in-play-runs-fg')}-fg} ` +
|
|
35
|
-
`${teams.away.abbreviation} ${scoreObj.awayScore} - ` +
|
|
36
|
-
`${teams.home.abbreviation} ${scoreObj.homeScore}` +
|
|
37
|
-
' {/}'
|
|
38
|
-
);
|
|
39
|
-
|
|
27
|
+
const formatScoreDetail = scoreObj => ` {bold}{${get('color.in-play-runs-bg')}-bg}{${get('color.in-play-runs-fg')}-fg} ` + `${teams.away.abbreviation} ${scoreObj.awayScore} - ` + `${teams.home.abbreviation} ${scoreObj.homeScore}` + ' {/}';
|
|
40
28
|
let inning = '';
|
|
41
29
|
const lines = [];
|
|
42
30
|
plays && plays.slice().reverse().forEach((play, playIdx, plays) => {
|
|
@@ -52,7 +40,6 @@ function AllPlays() {
|
|
|
52
40
|
}
|
|
53
41
|
lines.push(`{bold}[${inning.toUpperCase()}]{/}`);
|
|
54
42
|
}
|
|
55
|
-
|
|
56
43
|
if (play.about.isComplete) {
|
|
57
44
|
const color = getPlayResultColor(play);
|
|
58
45
|
let line = `{${color}-fg}[${play.result.event}]{/} ${play.result.description}`;
|
|
@@ -67,9 +54,9 @@ function AllPlays() {
|
|
|
67
54
|
}
|
|
68
55
|
lines.push(line);
|
|
69
56
|
}
|
|
70
|
-
|
|
71
57
|
play.playEvents && play.playEvents.slice().reverse().forEach((event, eventIdx, events) => {
|
|
72
58
|
if (event.type === 'action') {
|
|
59
|
+
var _event$count;
|
|
73
60
|
let line = '';
|
|
74
61
|
if (event.details.event) {
|
|
75
62
|
line += `{${get('color.other-event')}-fg}[${event.details.event}]{/} `;
|
|
@@ -78,10 +65,11 @@ function AllPlays() {
|
|
|
78
65
|
if (event.isScoringPlay || event.details.isScoringPlay) {
|
|
79
66
|
line += formatScoreDetail(event.details);
|
|
80
67
|
}
|
|
81
|
-
const currentOut = event.count
|
|
68
|
+
const currentOut = (_event$count = event.count) === null || _event$count === void 0 ? void 0 : _event$count.outs;
|
|
82
69
|
let prevOut = lastPlay ? lastPlay.count.outs : 0;
|
|
83
70
|
if (eventIdx < events.length - 1) {
|
|
84
|
-
|
|
71
|
+
var _events$count;
|
|
72
|
+
prevOut = (_events$count = events[eventIdx + 1].count) === null || _events$count === void 0 ? void 0 : _events$count.outs;
|
|
85
73
|
}
|
|
86
74
|
if (currentOut > prevOut) {
|
|
87
75
|
line += formatOut(currentOut);
|
|
@@ -90,19 +78,16 @@ function AllPlays() {
|
|
|
90
78
|
}
|
|
91
79
|
});
|
|
92
80
|
});
|
|
93
|
-
return (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
/>
|
|
105
|
-
);
|
|
81
|
+
return /*#__PURE__*/React.createElement("box", {
|
|
82
|
+
content: lines.join('\n'),
|
|
83
|
+
focused: true,
|
|
84
|
+
mouse: true,
|
|
85
|
+
keys: true,
|
|
86
|
+
vi: true,
|
|
87
|
+
scrollable: true,
|
|
88
|
+
scrollbar: style.scrollbar,
|
|
89
|
+
alwaysScroll: true,
|
|
90
|
+
tags: true
|
|
91
|
+
});
|
|
106
92
|
}
|
|
107
|
-
|
|
108
93
|
export default AllPlays;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { useDispatch } from "react-redux/lib/alternate-renderers.js";
|
|
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
|
+
const SCHEDULE = 'schedule';
|
|
10
|
+
const STANDINGS = 'standings';
|
|
11
|
+
const GAME = 'game';
|
|
12
|
+
function App() {
|
|
13
|
+
const [view, setView] = useState(SCHEDULE);
|
|
14
|
+
const dispatch = useDispatch();
|
|
15
|
+
useKey('c', () => {
|
|
16
|
+
setView(SCHEDULE);
|
|
17
|
+
dispatch(setSelectedId(null));
|
|
18
|
+
}, {
|
|
19
|
+
key: 'C',
|
|
20
|
+
label: 'Schedule'
|
|
21
|
+
});
|
|
22
|
+
useKey('s', () => setView(STANDINGS), {
|
|
23
|
+
key: 'S',
|
|
24
|
+
label: 'Standings'
|
|
25
|
+
});
|
|
26
|
+
const handleGameSelect = game => {
|
|
27
|
+
dispatch(setSelectedId(game.gamePk));
|
|
28
|
+
setView(GAME);
|
|
29
|
+
};
|
|
30
|
+
return /*#__PURE__*/React.createElement("element", null, /*#__PURE__*/React.createElement("element", {
|
|
31
|
+
top: 0,
|
|
32
|
+
left: 0,
|
|
33
|
+
height: "100%-1"
|
|
34
|
+
}, view === STANDINGS && /*#__PURE__*/React.createElement(Standings, null), view === SCHEDULE && /*#__PURE__*/React.createElement(GameList, {
|
|
35
|
+
onGameSelect: handleGameSelect
|
|
36
|
+
}), view === GAME && /*#__PURE__*/React.createElement(Game, null)), /*#__PURE__*/React.createElement("element", {
|
|
37
|
+
top: "100%-1",
|
|
38
|
+
left: 0,
|
|
39
|
+
height: 1
|
|
40
|
+
}, /*#__PURE__*/React.createElement(HelpBar, null)));
|
|
41
|
+
}
|
|
42
|
+
export default App;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useSelector } from "react-redux/lib/alternate-renderers.js";
|
|
3
|
+
import { selectCurrentPlay } from "../features/games.js";
|
|
4
|
+
function AtBat() {
|
|
5
|
+
const currentPlay = useSelector(selectCurrentPlay);
|
|
6
|
+
const playEvents = currentPlay.playEvents;
|
|
7
|
+
const playResult = currentPlay.about.isComplete ? currentPlay.result.description : '';
|
|
8
|
+
let content = '';
|
|
9
|
+
if (playResult) {
|
|
10
|
+
content += `${playResult}\n\n`;
|
|
11
|
+
}
|
|
12
|
+
if (playEvents && playEvents.length) {
|
|
13
|
+
content += playEvents.slice().reverse().map(event => {
|
|
14
|
+
let line = '';
|
|
15
|
+
if (event.isPitch) {
|
|
16
|
+
var _event$pitchData, _event$details, _event$details2;
|
|
17
|
+
line = `[${event.details.description}] `;
|
|
18
|
+
if ((_event$pitchData = event.pitchData) !== null && _event$pitchData !== void 0 && _event$pitchData.startSpeed) {
|
|
19
|
+
line += `${event.pitchData.startSpeed} MPH `;
|
|
20
|
+
}
|
|
21
|
+
if ((_event$details = event.details) !== null && _event$details !== void 0 && (_event$details = _event$details.type) !== null && _event$details !== void 0 && _event$details.description) {
|
|
22
|
+
line += event.details.type.description;
|
|
23
|
+
}
|
|
24
|
+
if (!((_event$details2 = event.details) !== null && _event$details2 !== void 0 && _event$details2.isInPlay)) {
|
|
25
|
+
line += `{|} ${event.count.balls}-${event.count.strikes}`;
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
var _event$details3;
|
|
29
|
+
if ((_event$details3 = event.details) !== null && _event$details3 !== void 0 && _event$details3.event) {
|
|
30
|
+
line += `[${event.details.event}] `;
|
|
31
|
+
}
|
|
32
|
+
line += event.details.description;
|
|
33
|
+
}
|
|
34
|
+
return line;
|
|
35
|
+
}).join('\n');
|
|
36
|
+
}
|
|
37
|
+
return /*#__PURE__*/React.createElement("box", {
|
|
38
|
+
content: content,
|
|
39
|
+
tags: true
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export default AtBat;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useSelector } from "react-redux/lib/alternate-renderers.js";
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { get } from "../config.js";
|
|
5
|
+
import { selectLineScore } from "../features/games.js";
|
|
6
|
+
const formatBase = (offense, base) => base in offense ? `{${get('color.on-base')}-fg}◆{/}` : '◇';
|
|
7
|
+
function Bases({
|
|
8
|
+
align
|
|
9
|
+
}) {
|
|
10
|
+
const {
|
|
11
|
+
offense
|
|
12
|
+
} = useSelector(selectLineScore);
|
|
13
|
+
const content = ` ${formatBase(offense, 'second')}\n` + `${formatBase(offense, 'third')} ${formatBase(offense, 'first')}`;
|
|
14
|
+
return /*#__PURE__*/React.createElement("box", {
|
|
15
|
+
align: align,
|
|
16
|
+
content: content,
|
|
17
|
+
tags: true
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
Bases.propTypes = {
|
|
21
|
+
align: PropTypes.oneOf(['left', 'center', 'right'])
|
|
22
|
+
};
|
|
23
|
+
export default Bases;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useSelector } from "react-redux/lib/alternate-renderers.js";
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { get } from "../config.js";
|
|
5
|
+
import { selectLineScore } from "../features/games.js";
|
|
6
|
+
const formatCount = (count, total) => '● '.repeat(count) + '○ '.repeat(total - count);
|
|
7
|
+
function Count({
|
|
8
|
+
align
|
|
9
|
+
}) {
|
|
10
|
+
const linescore = useSelector(selectLineScore);
|
|
11
|
+
const content = `B: {${get('color.ball')}-fg}${formatCount(linescore.balls, 4)}{/}\n` + `S: {${get('color.strike')}-fg}${formatCount(linescore.strikes, 3)}{/}\n` + `O: {${get('color.out')}-fg}${formatCount(linescore.outs, 3)}{/}`;
|
|
12
|
+
return /*#__PURE__*/React.createElement("box", {
|
|
13
|
+
align: align,
|
|
14
|
+
content: content,
|
|
15
|
+
tags: true
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
Count.propTypes = {
|
|
19
|
+
align: PropTypes.oneOf(['left', 'center', 'right'])
|
|
20
|
+
};
|
|
21
|
+
export default Count;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useSelector } from "react-redux/lib/alternate-renderers.js";
|
|
3
|
+
import { selectLineScore, selectTeams, selectDecisions, selectBoxscore, selectGameStatus } from "../features/games.js";
|
|
4
|
+
import LineScore from "./LineScore.js";
|
|
5
|
+
const getPlayer = (id, boxscore) => {
|
|
6
|
+
var _boxscore$home, _boxscore$away;
|
|
7
|
+
const homePlayer = (_boxscore$home = boxscore.home) === null || _boxscore$home === void 0 || (_boxscore$home = _boxscore$home.players) === null || _boxscore$home === void 0 ? void 0 : _boxscore$home['ID' + id];
|
|
8
|
+
if (homePlayer !== undefined) {
|
|
9
|
+
return homePlayer;
|
|
10
|
+
}
|
|
11
|
+
return (_boxscore$away = boxscore.away) === null || _boxscore$away === void 0 ? void 0 : _boxscore$away.players['ID' + id];
|
|
12
|
+
};
|
|
13
|
+
const formatDecisions = (decisions, boxscore) => {
|
|
14
|
+
if (!decisions) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
const content = [];
|
|
18
|
+
const winner = decisions.winner;
|
|
19
|
+
if (winner) {
|
|
20
|
+
var _pitcher$seasonStats, _pitcher$seasonStats2;
|
|
21
|
+
const pitcher = getPlayer(winner.id, boxscore);
|
|
22
|
+
content.push(`Win: ${pitcher.person.fullName} (${(_pitcher$seasonStats = pitcher.seasonStats) === null || _pitcher$seasonStats === void 0 || (_pitcher$seasonStats = _pitcher$seasonStats.pitching) === null || _pitcher$seasonStats === void 0 ? void 0 : _pitcher$seasonStats.wins}-${(_pitcher$seasonStats2 = pitcher.seasonStats) === null || _pitcher$seasonStats2 === void 0 || (_pitcher$seasonStats2 = _pitcher$seasonStats2.pitching) === null || _pitcher$seasonStats2 === void 0 ? void 0 : _pitcher$seasonStats2.losses})`);
|
|
23
|
+
}
|
|
24
|
+
const loser = decisions.loser;
|
|
25
|
+
if (loser) {
|
|
26
|
+
var _pitcher$seasonStats3, _pitcher$seasonStats4;
|
|
27
|
+
const pitcher = getPlayer(loser.id, boxscore);
|
|
28
|
+
content.push(`Loss: ${pitcher.person.fullName} (${(_pitcher$seasonStats3 = pitcher.seasonStats) === null || _pitcher$seasonStats3 === void 0 || (_pitcher$seasonStats3 = _pitcher$seasonStats3.pitching) === null || _pitcher$seasonStats3 === void 0 ? void 0 : _pitcher$seasonStats3.wins}-${(_pitcher$seasonStats4 = pitcher.seasonStats) === null || _pitcher$seasonStats4 === void 0 || (_pitcher$seasonStats4 = _pitcher$seasonStats4.pitching) === null || _pitcher$seasonStats4 === void 0 ? void 0 : _pitcher$seasonStats4.losses})`);
|
|
29
|
+
}
|
|
30
|
+
const save = decisions.save;
|
|
31
|
+
if (save) {
|
|
32
|
+
var _pitcher$seasonStats5;
|
|
33
|
+
const pitcher = getPlayer(save.id, boxscore);
|
|
34
|
+
content.push(`Save: ${pitcher.person.fullName} (${(_pitcher$seasonStats5 = pitcher.seasonStats) === null || _pitcher$seasonStats5 === void 0 ? void 0 : _pitcher$seasonStats5.pitching.saves})`);
|
|
35
|
+
}
|
|
36
|
+
return content.join('\n');
|
|
37
|
+
};
|
|
38
|
+
const formatScore = (status, linescore) => {
|
|
39
|
+
let display = '';
|
|
40
|
+
if (status.detailedState === 'Postponed') {
|
|
41
|
+
display = status.detailedState;
|
|
42
|
+
if (status.reason) {
|
|
43
|
+
display += '\n' + status.reason;
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
display = `\n${linescore.teams.away.runs} - ${linescore.teams.home.runs}`;
|
|
47
|
+
}
|
|
48
|
+
return display;
|
|
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
|
+
const awayTeam = `${teams.away.teamName}\n(${teams.away.record.wins}-${teams.away.record.losses})`;
|
|
57
|
+
const homeTeam = `${teams.home.teamName}\n(${teams.home.record.wins}-${teams.home.record.losses})`;
|
|
58
|
+
return /*#__PURE__*/React.createElement("element", null, /*#__PURE__*/React.createElement("element", {
|
|
59
|
+
height: "60%"
|
|
60
|
+
}, /*#__PURE__*/React.createElement("box", {
|
|
61
|
+
content: awayTeam,
|
|
62
|
+
width: "33%-1",
|
|
63
|
+
top: "50%",
|
|
64
|
+
align: "center"
|
|
65
|
+
}), /*#__PURE__*/React.createElement("box", {
|
|
66
|
+
content: formatScore(status, linescore),
|
|
67
|
+
width: "33%-1",
|
|
68
|
+
left: "33%",
|
|
69
|
+
top: "50%",
|
|
70
|
+
align: "center"
|
|
71
|
+
}), /*#__PURE__*/React.createElement("box", {
|
|
72
|
+
content: homeTeam,
|
|
73
|
+
width: "34%",
|
|
74
|
+
top: "50%",
|
|
75
|
+
left: "66%",
|
|
76
|
+
align: "center"
|
|
77
|
+
})), /*#__PURE__*/React.createElement("element", {
|
|
78
|
+
top: "60%+1",
|
|
79
|
+
height: 3
|
|
80
|
+
}, /*#__PURE__*/React.createElement(LineScore, {
|
|
81
|
+
align: "center",
|
|
82
|
+
final: true
|
|
83
|
+
})), /*#__PURE__*/React.createElement("element", {
|
|
84
|
+
top: "60%+5",
|
|
85
|
+
left: "50%-20"
|
|
86
|
+
}, /*#__PURE__*/React.createElement("box", {
|
|
87
|
+
content: formatDecisions(decisions, boxscore)
|
|
88
|
+
})));
|
|
89
|
+
}
|
|
90
|
+
export default FinishedGame;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { useDispatch, useSelector } from "react-redux/lib/alternate-renderers.js";
|
|
3
|
+
import { fetchGame, selectGame, selectSelectedId, selectFullUpdateRequired } from "../features/games.js";
|
|
4
|
+
import PreviewGame from "./PreviewGame.js";
|
|
5
|
+
import LiveGame from "./LiveGame.js";
|
|
6
|
+
import FinishedGame from "./FinishedGame.js";
|
|
7
|
+
import log from "../logger.js";
|
|
8
|
+
function Game() {
|
|
9
|
+
var _game$metaData, _game$gameData;
|
|
10
|
+
const dispatch = useDispatch();
|
|
11
|
+
const game = useSelector(selectGame);
|
|
12
|
+
const fullUpdateRequired = useSelector(selectFullUpdateRequired);
|
|
13
|
+
const id = useSelector(selectSelectedId);
|
|
14
|
+
const timerRef = useRef(null);
|
|
15
|
+
const timestampRef = useRef();
|
|
16
|
+
timestampRef.current = fullUpdateRequired ? null : game === null || game === void 0 || (_game$metaData = game.metaData) === null || _game$metaData === void 0 ? void 0 : _game$metaData.timeStamp;
|
|
17
|
+
const updateGameData = () => {
|
|
18
|
+
dispatch(fetchGame({
|
|
19
|
+
id,
|
|
20
|
+
start: timestampRef.current
|
|
21
|
+
})).unwrap().then(result => {
|
|
22
|
+
var _result$metaData;
|
|
23
|
+
const wait = (result && ((_result$metaData = result.metaData) === null || _result$metaData === void 0 ? void 0 : _result$metaData.wait) || 10) * 1000;
|
|
24
|
+
timerRef.current = setTimeout(updateGameData, wait);
|
|
25
|
+
}).catch(err => log.error('UPDATE_GAME_DATA:\n' + JSON.stringify(err) + '\n' + err.stack));
|
|
26
|
+
};
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
updateGameData();
|
|
29
|
+
return () => {
|
|
30
|
+
clearTimeout(timerRef.current);
|
|
31
|
+
};
|
|
32
|
+
}, [id]);
|
|
33
|
+
if (!game) {
|
|
34
|
+
return /*#__PURE__*/React.createElement("element", null);
|
|
35
|
+
}
|
|
36
|
+
let Wrapped = null;
|
|
37
|
+
switch ((_game$gameData = game.gameData) === null || _game$gameData === void 0 || (_game$gameData = _game$gameData.status) === null || _game$gameData === void 0 ? void 0 : _game$gameData.abstractGameCode) {
|
|
38
|
+
case 'P':
|
|
39
|
+
Wrapped = PreviewGame;
|
|
40
|
+
break;
|
|
41
|
+
case 'L':
|
|
42
|
+
Wrapped = LiveGame;
|
|
43
|
+
break;
|
|
44
|
+
case 'F':
|
|
45
|
+
Wrapped = FinishedGame;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
return /*#__PURE__*/React.createElement("element", null, /*#__PURE__*/React.createElement(Wrapped, null));
|
|
49
|
+
}
|
|
50
|
+
export default Game;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useDispatch, useSelector } from "react-redux/lib/alternate-renderers.js";
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { add, format } from 'date-fns';
|
|
6
|
+
import { fetchSchedule, selectData, selectLoading } from "../features/schedule.js";
|
|
7
|
+
import { teamFavoriteStar } from "../utils.js";
|
|
8
|
+
import Grid from "./Grid.js";
|
|
9
|
+
import useKey from "../hooks/useKey.js";
|
|
10
|
+
const formatGame = game => {
|
|
11
|
+
const startTime = format(new Date(game.gameDate), 'p');
|
|
12
|
+
const start = game.doubleHeader === 'Y' && game.gameNumber > 1 ? 'Game ' + game.gameNumber : startTime;
|
|
13
|
+
const teamName = team => {
|
|
14
|
+
const star = teamFavoriteStar(team.team);
|
|
15
|
+
return star + `${team.team.teamName} (${team.leagueRecord.wins}-${team.leagueRecord.losses})`.padEnd(star ? 18 : 20);
|
|
16
|
+
};
|
|
17
|
+
let content = [start, teamName(game.teams.away), teamName(game.teams.home)];
|
|
18
|
+
const gameState = game.status.abstractGameCode;
|
|
19
|
+
const detailedState = game.status.detailedState;
|
|
20
|
+
switch (gameState) {
|
|
21
|
+
case 'P':
|
|
22
|
+
break;
|
|
23
|
+
case 'L':
|
|
24
|
+
if (detailedState === 'Warmup') {
|
|
25
|
+
content[0] = detailedState;
|
|
26
|
+
} else {
|
|
27
|
+
content[0] = game.linescore.inningState + ' ' + game.linescore.currentInningOrdinal;
|
|
28
|
+
if (detailedState !== 'In Progress') {
|
|
29
|
+
content[0] += ' | ' + detailedState;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (game.linescore) {
|
|
33
|
+
content[0] = content[0].padEnd(20) + ' R H E';
|
|
34
|
+
content[1] += game.linescore.teams.away.runs.toString().padStart(2) + game.linescore.teams.away.hits.toString().padStart(3) + game.linescore.teams.away.errors.toString().padStart(3);
|
|
35
|
+
content[2] += game.linescore.teams.home.runs.toString().padStart(2) + game.linescore.teams.home.hits.toString().padStart(3) + game.linescore.teams.home.errors.toString().padStart(3);
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
case 'F':
|
|
39
|
+
content[0] = detailedState;
|
|
40
|
+
if (game.status.reason) {
|
|
41
|
+
content[0] += ' | ' + game.status.reason;
|
|
42
|
+
}
|
|
43
|
+
if (game.linescore) {
|
|
44
|
+
if (game.linescore.currentInning !== game.scheduledInnings) {
|
|
45
|
+
content[0] += '/' + game.linescore.currentInning;
|
|
46
|
+
}
|
|
47
|
+
content[0] = content[0].padEnd(20) + ' R H E';
|
|
48
|
+
content[1] += game.linescore.teams.away.runs.toString().padStart(2) + game.linescore.teams.away.hits.toString().padStart(3) + game.linescore.teams.away.errors.toString().padStart(3);
|
|
49
|
+
content[2] += game.linescore.teams.home.runs.toString().padStart(2) + game.linescore.teams.home.hits.toString().padStart(3) + game.linescore.teams.home.errors.toString().padStart(3);
|
|
50
|
+
if (game.teams.away.isWinner) {
|
|
51
|
+
content[1] = `{bold}${content[1]}{/bold}`;
|
|
52
|
+
}
|
|
53
|
+
if (game.teams.home.isWinner) {
|
|
54
|
+
content[2] = `{bold}${content[2]}{/bold}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
return content.map(s => ' ' + s).join('\n');
|
|
60
|
+
};
|
|
61
|
+
const GAME_STATE_ORDER = {
|
|
62
|
+
L: 0,
|
|
63
|
+
P: 1,
|
|
64
|
+
F: 2
|
|
65
|
+
};
|
|
66
|
+
function compareGameState(a, b) {
|
|
67
|
+
return GAME_STATE_ORDER[a.status.abstractGameCode] - GAME_STATE_ORDER[b.status.abstractGameCode];
|
|
68
|
+
}
|
|
69
|
+
function compareGameInnings(a, b) {
|
|
70
|
+
const inningCompare = b.linescore.currentInning - a.linescore.currentInning;
|
|
71
|
+
if (inningCompare !== 0) {
|
|
72
|
+
return inningCompare;
|
|
73
|
+
}
|
|
74
|
+
if (a.isTopInning && !b.isTopInning) {
|
|
75
|
+
return -1;
|
|
76
|
+
}
|
|
77
|
+
if (b.isTopInning && !a.isTopInning) {
|
|
78
|
+
return 1;
|
|
79
|
+
}
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
function compareGames(a, b) {
|
|
83
|
+
const stateCompare = compareGameState(a, b);
|
|
84
|
+
if (stateCompare !== 0) {
|
|
85
|
+
return stateCompare;
|
|
86
|
+
}
|
|
87
|
+
if (a.status.abstractGameCode === 'L') {
|
|
88
|
+
const inningCompare = compareGameInnings(a, b);
|
|
89
|
+
if (inningCompare !== 0) {
|
|
90
|
+
return inningCompare;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
function GameList({
|
|
96
|
+
onGameSelect
|
|
97
|
+
}) {
|
|
98
|
+
const dispatch = useDispatch();
|
|
99
|
+
const schedule = useSelector(selectData);
|
|
100
|
+
const loading = useSelector(selectLoading);
|
|
101
|
+
const timerRef = useRef(null);
|
|
102
|
+
const [date, setDate] = useState(new Date());
|
|
103
|
+
let games = [];
|
|
104
|
+
if (schedule && schedule.dates.length > 0) {
|
|
105
|
+
games = schedule.dates[0].games.slice().sort(compareGames);
|
|
106
|
+
}
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
dispatch(fetchSchedule(date));
|
|
109
|
+
timerRef.current = setInterval(() => dispatch(fetchSchedule(date)), 30000);
|
|
110
|
+
return () => clearInterval(timerRef.current);
|
|
111
|
+
}, [date]);
|
|
112
|
+
useKey('p', useCallback(() => setDate(prev => add(prev, {
|
|
113
|
+
days: -1
|
|
114
|
+
})), []), {
|
|
115
|
+
key: 'P',
|
|
116
|
+
label: 'Prev Day'
|
|
117
|
+
});
|
|
118
|
+
useKey('n', useCallback(() => setDate(prev => add(prev, {
|
|
119
|
+
days: 1
|
|
120
|
+
})), []), {
|
|
121
|
+
key: 'N',
|
|
122
|
+
label: 'Next Day'
|
|
123
|
+
});
|
|
124
|
+
useKey('t', useCallback(() => setDate(new Date()), []), {
|
|
125
|
+
key: 'T',
|
|
126
|
+
label: 'Today'
|
|
127
|
+
});
|
|
128
|
+
const handleGameSelect = idx => {
|
|
129
|
+
const selected = games[idx];
|
|
130
|
+
onGameSelect(selected);
|
|
131
|
+
};
|
|
132
|
+
const messageStyle = {
|
|
133
|
+
left: 0,
|
|
134
|
+
top: 0,
|
|
135
|
+
height: '100%',
|
|
136
|
+
width: '100%',
|
|
137
|
+
align: 'center',
|
|
138
|
+
valign: 'middle'
|
|
139
|
+
};
|
|
140
|
+
return /*#__PURE__*/React.createElement("element", null, /*#__PURE__*/React.createElement("box", {
|
|
141
|
+
top: 0,
|
|
142
|
+
left: 0,
|
|
143
|
+
width: "100%",
|
|
144
|
+
height: 1,
|
|
145
|
+
align: "center",
|
|
146
|
+
valign: "middle",
|
|
147
|
+
style: {
|
|
148
|
+
bg: 'white',
|
|
149
|
+
fg: 'black'
|
|
150
|
+
},
|
|
151
|
+
content: format(date, 'PPPP')
|
|
152
|
+
}), /*#__PURE__*/React.createElement("element", {
|
|
153
|
+
top: 2,
|
|
154
|
+
left: 0,
|
|
155
|
+
width: "100%",
|
|
156
|
+
height: "100%-2"
|
|
157
|
+
}, !schedule && loading && /*#__PURE__*/React.createElement("box", _extends({}, messageStyle, {
|
|
158
|
+
content: "Loading..."
|
|
159
|
+
})), schedule && games.length === 0 && /*#__PURE__*/React.createElement("box", _extends({}, messageStyle, {
|
|
160
|
+
content: "No games today"
|
|
161
|
+
})), schedule && games.length > 0 && /*#__PURE__*/React.createElement(Grid, {
|
|
162
|
+
items: games.map(formatGame),
|
|
163
|
+
itemHeight: 5,
|
|
164
|
+
itemMinWidth: 34,
|
|
165
|
+
onSelect: handleGameSelect
|
|
166
|
+
})));
|
|
167
|
+
}
|
|
168
|
+
GameList.propTypes = {
|
|
169
|
+
onGameSelect: PropTypes.func
|
|
170
|
+
};
|
|
171
|
+
export default GameList;
|