playball 3.0.0 → 3.1.0

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 (61) hide show
  1. package/.eslintrc.json +1 -1
  2. package/README.md +62 -0
  3. package/bin/playball.js +1 -1
  4. package/package.json +10 -6
  5. package/src/cli.js +46 -0
  6. package/src/components/AllPlays.jsx +14 -13
  7. package/src/components/App.jsx +6 -6
  8. package/src/components/AtBat.jsx +1 -1
  9. package/src/components/Bases.jsx +3 -2
  10. package/src/components/Count.jsx +5 -4
  11. package/src/components/FinishedGame.jsx +2 -2
  12. package/src/components/Game.jsx +5 -5
  13. package/src/components/GameList.jsx +8 -5
  14. package/src/components/Grid.jsx +1 -1
  15. package/src/components/HelpBar.jsx +1 -1
  16. package/src/components/InningDisplay.jsx +1 -1
  17. package/src/components/LineScore.jsx +1 -1
  18. package/src/components/LiveGame.jsx +7 -7
  19. package/src/components/LoadingSpinner.jsx +2 -2
  20. package/src/components/Matchup.jsx +1 -1
  21. package/src/components/PreviewGame.jsx +1 -1
  22. package/src/components/Standings.jsx +6 -3
  23. package/src/config.js +167 -0
  24. package/src/features/games.js +2 -1
  25. package/src/features/keys.js +5 -4
  26. package/src/features/schedule.js +2 -1
  27. package/src/features/standings.js +2 -1
  28. package/src/hooks/useKey.js +1 -1
  29. package/src/logger.js +4 -1
  30. package/src/main.js +19 -15
  31. package/src/package.js +7 -0
  32. package/src/screen.js +18 -10
  33. package/src/store/index.js +6 -5
  34. package/src/utils.js +10 -0
  35. package/dist/components/AllPlays.js +0 -133
  36. package/dist/components/App.js +0 -68
  37. package/dist/components/AtBat.js +0 -67
  38. package/dist/components/Bases.js +0 -38
  39. package/dist/components/Count.js +0 -36
  40. package/dist/components/FinishedGame.js +0 -124
  41. package/dist/components/Game.js +0 -82
  42. package/dist/components/GameList.js +0 -222
  43. package/dist/components/Grid.js +0 -115
  44. package/dist/components/HelpBar.js +0 -30
  45. package/dist/components/InningDisplay.js +0 -26
  46. package/dist/components/LineScore.js +0 -60
  47. package/dist/components/LiveGame.js +0 -70
  48. package/dist/components/LoadingSpinner.js +0 -55
  49. package/dist/components/Matchup.js +0 -58
  50. package/dist/components/PreviewGame.js +0 -76
  51. package/dist/components/Standings.js +0 -91
  52. package/dist/features/games.js +0 -135
  53. package/dist/features/keys.js +0 -63
  54. package/dist/features/schedule.js +0 -58
  55. package/dist/features/standings.js +0 -57
  56. package/dist/hooks/useKey.js +0 -23
  57. package/dist/logger.js +0 -22
  58. package/dist/main.js +0 -28
  59. package/dist/screen.js +0 -22
  60. package/dist/store/index.js +0 -32
  61. package/dist/style/index.js +0 -22
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _alternateRenderers = require("react-redux/lib/alternate-renderers");
11
-
12
- var _propTypes = _interopRequireDefault(require("prop-types"));
13
-
14
- var _games = require("../features/games");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- const formatCount = (count, total) => '● '.repeat(count) + '○ '.repeat(total - count);
19
-
20
- function Count({
21
- align
22
- }) {
23
- const linescore = (0, _alternateRenderers.useSelector)(_games.selectLineScore);
24
- const content = `B: {green-fg}${formatCount(linescore.balls, 4)}{/green-fg}\n` + `S: {red-fg}${formatCount(linescore.strikes, 3)}{/red-fg}\n` + `O: {red-fg}${formatCount(linescore.outs, 3)}{/red-fg}`;
25
- return /*#__PURE__*/_react.default.createElement("box", {
26
- align: align,
27
- content: content,
28
- tags: true
29
- });
30
- }
31
-
32
- Count.propTypes = {
33
- align: _propTypes.default.oneOf(['left', 'center', 'right'])
34
- };
35
- var _default = Count;
36
- exports.default = _default;
@@ -1,124 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _alternateRenderers = require("react-redux/lib/alternate-renderers");
11
-
12
- var _games = require("../features/games");
13
-
14
- var _LineScore = _interopRequireDefault(require("./LineScore"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- const getPlayer = (id, boxscore) => {
19
- var _boxscore$home, _boxscore$home$player, _boxscore$away;
20
-
21
- const homePlayer = (_boxscore$home = boxscore.home) === null || _boxscore$home === void 0 ? void 0 : (_boxscore$home$player = _boxscore$home.players) === null || _boxscore$home$player === void 0 ? void 0 : _boxscore$home$player['ID' + id];
22
-
23
- if (homePlayer !== undefined) {
24
- return homePlayer;
25
- }
26
-
27
- return (_boxscore$away = boxscore.away) === null || _boxscore$away === void 0 ? void 0 : _boxscore$away.players['ID' + id];
28
- };
29
-
30
- const formatDecisions = (decisions, boxscore) => {
31
- if (!decisions) {
32
- return '';
33
- }
34
-
35
- const content = [];
36
- const winner = decisions.winner;
37
-
38
- if (winner) {
39
- var _pitcher$seasonStats, _pitcher$seasonStats$, _pitcher$seasonStats2, _pitcher$seasonStats3;
40
-
41
- const pitcher = getPlayer(winner.id, boxscore);
42
- content.push(`Win: ${pitcher.person.fullName} (${(_pitcher$seasonStats = pitcher.seasonStats) === null || _pitcher$seasonStats === void 0 ? 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 ? void 0 : (_pitcher$seasonStats3 = _pitcher$seasonStats2.pitching) === null || _pitcher$seasonStats3 === void 0 ? void 0 : _pitcher$seasonStats3.losses})`);
43
- }
44
-
45
- const loser = decisions.loser;
46
-
47
- if (loser) {
48
- var _pitcher$seasonStats4, _pitcher$seasonStats5, _pitcher$seasonStats6, _pitcher$seasonStats7;
49
-
50
- const pitcher = getPlayer(loser.id, boxscore);
51
- content.push(`Loss: ${pitcher.person.fullName} (${(_pitcher$seasonStats4 = pitcher.seasonStats) === null || _pitcher$seasonStats4 === void 0 ? void 0 : (_pitcher$seasonStats5 = _pitcher$seasonStats4.pitching) === null || _pitcher$seasonStats5 === void 0 ? void 0 : _pitcher$seasonStats5.wins}-${(_pitcher$seasonStats6 = pitcher.seasonStats) === null || _pitcher$seasonStats6 === void 0 ? void 0 : (_pitcher$seasonStats7 = _pitcher$seasonStats6.pitching) === null || _pitcher$seasonStats7 === void 0 ? void 0 : _pitcher$seasonStats7.losses})`);
52
- }
53
-
54
- const save = decisions.save;
55
-
56
- if (save) {
57
- var _pitcher$seasonStats8;
58
-
59
- const pitcher = getPlayer(save.id, boxscore);
60
- content.push(`Save: ${pitcher.person.fullName} (${(_pitcher$seasonStats8 = pitcher.seasonStats) === null || _pitcher$seasonStats8 === void 0 ? void 0 : _pitcher$seasonStats8.pitching.saves})`);
61
- }
62
-
63
- return content.join('\n');
64
- };
65
-
66
- const formatScore = (status, linescore) => {
67
- let display = '';
68
-
69
- if (status.detailedState === 'Postponed') {
70
- display = status.detailedState;
71
-
72
- if (status.reason) {
73
- display += '\n' + status.reason;
74
- }
75
- } else {
76
- display = `\n${linescore.teams.away.runs} - ${linescore.teams.home.runs}`;
77
- }
78
-
79
- return display;
80
- };
81
-
82
- function FinishedGame() {
83
- const boxscore = (0, _alternateRenderers.useSelector)(_games.selectBoxscore);
84
- const decisions = (0, _alternateRenderers.useSelector)(_games.selectDecisions);
85
- const linescore = (0, _alternateRenderers.useSelector)(_games.selectLineScore);
86
- const status = (0, _alternateRenderers.useSelector)(_games.selectGameStatus);
87
- const teams = (0, _alternateRenderers.useSelector)(_games.selectTeams);
88
- const awayTeam = `${teams.away.teamName}\n(${teams.away.record.wins}-${teams.away.record.losses})`;
89
- const homeTeam = `${teams.home.teamName}\n(${teams.home.record.wins}-${teams.home.record.losses})`;
90
- return /*#__PURE__*/_react.default.createElement("element", null, /*#__PURE__*/_react.default.createElement("element", {
91
- height: "60%"
92
- }, /*#__PURE__*/_react.default.createElement("box", {
93
- content: awayTeam,
94
- width: "33%-1",
95
- top: "50%",
96
- align: "center"
97
- }), /*#__PURE__*/_react.default.createElement("box", {
98
- content: formatScore(status, linescore),
99
- width: "33%-1",
100
- left: "33%",
101
- top: "50%",
102
- align: "center"
103
- }), /*#__PURE__*/_react.default.createElement("box", {
104
- content: homeTeam,
105
- width: "34%",
106
- top: "50%",
107
- left: "66%",
108
- align: "center"
109
- })), /*#__PURE__*/_react.default.createElement("element", {
110
- top: "60%+1",
111
- height: 3
112
- }, /*#__PURE__*/_react.default.createElement(_LineScore.default, {
113
- align: "center",
114
- final: true
115
- })), /*#__PURE__*/_react.default.createElement("element", {
116
- top: "60%+5",
117
- left: "50%-20"
118
- }, /*#__PURE__*/_react.default.createElement("box", {
119
- content: formatDecisions(decisions, boxscore)
120
- })));
121
- }
122
-
123
- var _default = FinishedGame;
124
- exports.default = _default;
@@ -1,82 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _alternateRenderers = require("react-redux/lib/alternate-renderers");
11
-
12
- var _games = require("../features/games");
13
-
14
- var _PreviewGame = _interopRequireDefault(require("./PreviewGame"));
15
-
16
- var _LiveGame = _interopRequireDefault(require("./LiveGame"));
17
-
18
- var _FinishedGame = _interopRequireDefault(require("./FinishedGame"));
19
-
20
- var _logger = _interopRequireDefault(require("../logger"));
21
-
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
-
26
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
-
28
- function Game() {
29
- var _game$metaData, _game$gameData, _game$gameData$status;
30
-
31
- const dispatch = (0, _alternateRenderers.useDispatch)();
32
- const game = (0, _alternateRenderers.useSelector)(_games.selectGame);
33
- const fullUpdateRequired = (0, _alternateRenderers.useSelector)(_games.selectFullUpdateRequired);
34
- const id = (0, _alternateRenderers.useSelector)(_games.selectSelectedId);
35
- const timerRef = (0, _react.useRef)(null);
36
- const timestampRef = (0, _react.useRef)();
37
- timestampRef.current = fullUpdateRequired ? null : game === null || game === void 0 ? void 0 : (_game$metaData = game.metaData) === null || _game$metaData === void 0 ? void 0 : _game$metaData.timeStamp;
38
-
39
- const updateGameData = () => {
40
- dispatch((0, _games.fetchGame)({
41
- id,
42
- start: timestampRef.current
43
- })).unwrap().then(result => {
44
- var _result$metaData;
45
-
46
- const wait = (result && ((_result$metaData = result.metaData) === null || _result$metaData === void 0 ? void 0 : _result$metaData.wait) || 10) * 1000;
47
- timerRef.current = setTimeout(updateGameData, wait);
48
- }).catch(err => _logger.default.error('UPDATE_GAME_DATA:\n' + JSON.stringify(err) + '\n' + err.stack));
49
- };
50
-
51
- (0, _react.useEffect)(() => {
52
- updateGameData();
53
- return () => {
54
- clearTimeout(timerRef.current);
55
- };
56
- }, [id]);
57
-
58
- if (!game) {
59
- return /*#__PURE__*/_react.default.createElement("element", null);
60
- }
61
-
62
- let Wrapped = null;
63
-
64
- switch ((_game$gameData = game.gameData) === null || _game$gameData === void 0 ? void 0 : (_game$gameData$status = _game$gameData.status) === null || _game$gameData$status === void 0 ? void 0 : _game$gameData$status.abstractGameCode) {
65
- case 'P':
66
- Wrapped = _PreviewGame.default;
67
- break;
68
-
69
- case 'L':
70
- Wrapped = _LiveGame.default;
71
- break;
72
-
73
- case 'F':
74
- Wrapped = _FinishedGame.default;
75
- break;
76
- }
77
-
78
- return /*#__PURE__*/_react.default.createElement("element", null, /*#__PURE__*/_react.default.createElement(Wrapped, null));
79
- }
80
-
81
- var _default = Game;
82
- exports.default = _default;
@@ -1,222 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _alternateRenderers = require("react-redux/lib/alternate-renderers");
11
-
12
- var _propTypes = _interopRequireDefault(require("prop-types"));
13
-
14
- var _dateFns = require("date-fns");
15
-
16
- var _schedule = require("../features/schedule");
17
-
18
- var _Grid = _interopRequireDefault(require("./Grid"));
19
-
20
- var _useKey = _interopRequireDefault(require("../hooks/useKey"));
21
-
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
-
26
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
-
28
- 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); }
29
-
30
- const formatGame = game => {
31
- const startTime = (0, _dateFns.format)(new Date(game.gameDate), 'p');
32
- const start = game.doubleHeader === 'Y' && game.gameNumber > 1 ? 'Game ' + game.gameNumber : startTime;
33
-
34
- const teamName = team => `${team.team.teamName} (${team.leagueRecord.wins}-${team.leagueRecord.losses})`.padEnd(20);
35
-
36
- let content = [start, teamName(game.teams.away), teamName(game.teams.home)];
37
- const gameState = game.status.abstractGameCode;
38
- const detailedState = game.status.detailedState;
39
-
40
- switch (gameState) {
41
- case 'P':
42
- break;
43
-
44
- case 'L':
45
- if (detailedState === 'Warmup') {
46
- content[0] = detailedState;
47
- } else {
48
- content[0] = game.linescore.inningState + ' ' + game.linescore.currentInningOrdinal;
49
-
50
- if (detailedState !== 'In Progress') {
51
- content[0] += ' | ' + detailedState;
52
- }
53
- }
54
-
55
- if (game.linescore) {
56
- content[0] = content[0].padEnd(20) + ' R H E';
57
- 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);
58
- 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);
59
- }
60
-
61
- break;
62
-
63
- case 'F':
64
- content[0] = detailedState;
65
-
66
- if (game.status.reason) {
67
- content[0] += ' | ' + game.status.reason;
68
- }
69
-
70
- if (game.linescore) {
71
- if (game.linescore.currentInning !== game.scheduledInnings) {
72
- content[0] += '/' + game.linescore.currentInning;
73
- }
74
-
75
- content[0] = content[0].padEnd(20) + ' R H E';
76
- 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);
77
- 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);
78
-
79
- if (game.teams.away.isWinner) {
80
- content[1] = `{bold}${content[1]}{/bold}`;
81
- }
82
-
83
- if (game.teams.home.isWinner) {
84
- content[2] = `{bold}${content[2]}{/bold}`;
85
- }
86
- }
87
-
88
- break;
89
- }
90
-
91
- return content.map(s => ' ' + s).join('\n');
92
- };
93
-
94
- const GAME_STATE_ORDER = {
95
- L: 0,
96
- P: 1,
97
- F: 2
98
- };
99
-
100
- function compareGameState(a, b) {
101
- return GAME_STATE_ORDER[a.status.abstractGameCode] - GAME_STATE_ORDER[b.status.abstractGameCode];
102
- }
103
-
104
- function compareGameInnings(a, b) {
105
- const inningCompare = b.linescore.currentInning - a.linescore.currentInning;
106
-
107
- if (inningCompare !== 0) {
108
- return inningCompare;
109
- }
110
-
111
- if (a.isTopInning && !b.isTopInning) {
112
- return -1;
113
- }
114
-
115
- if (b.isTopInning && !a.isTopInning) {
116
- return 1;
117
- }
118
-
119
- return 0;
120
- }
121
-
122
- function compareGames(a, b) {
123
- const stateCompare = compareGameState(a, b);
124
-
125
- if (stateCompare !== 0) {
126
- return stateCompare;
127
- }
128
-
129
- if (a.status.abstractGameCode === 'L') {
130
- const inningCompare = compareGameInnings(a, b);
131
-
132
- if (inningCompare !== 0) {
133
- return inningCompare;
134
- }
135
- }
136
-
137
- return 0;
138
- }
139
-
140
- function GameList({
141
- onGameSelect
142
- }) {
143
- const dispatch = (0, _alternateRenderers.useDispatch)();
144
- const schedule = (0, _alternateRenderers.useSelector)(_schedule.selectData);
145
- const loading = (0, _alternateRenderers.useSelector)(_schedule.selectLoading);
146
- const timerRef = (0, _react.useRef)(null);
147
- const [date, setDate] = (0, _react.useState)(new Date());
148
- let games = [];
149
-
150
- if (schedule && schedule.dates.length > 0) {
151
- games = schedule.dates[0].games.slice().sort(compareGames);
152
- }
153
-
154
- (0, _react.useEffect)(() => {
155
- dispatch((0, _schedule.fetchSchedule)(date));
156
- timerRef.current = setInterval(() => dispatch((0, _schedule.fetchSchedule)(date)), 30000);
157
- return () => clearInterval(timerRef.current);
158
- }, [date]);
159
- (0, _useKey.default)('p', (0, _react.useCallback)(() => setDate(prev => (0, _dateFns.add)(prev, {
160
- days: -1
161
- })), []), {
162
- key: 'P',
163
- label: 'Prev Day'
164
- });
165
- (0, _useKey.default)('n', (0, _react.useCallback)(() => setDate(prev => (0, _dateFns.add)(prev, {
166
- days: 1
167
- })), []), {
168
- key: 'N',
169
- label: 'Next Day'
170
- });
171
- (0, _useKey.default)('t', (0, _react.useCallback)(() => setDate(new Date()), []), {
172
- key: 'T',
173
- label: 'Today'
174
- });
175
-
176
- const handleGameSelect = idx => {
177
- const selected = games[idx];
178
- onGameSelect(selected);
179
- };
180
-
181
- const messageStyle = {
182
- left: 0,
183
- top: 0,
184
- height: '100%',
185
- width: '100%',
186
- align: 'center',
187
- valign: 'middle'
188
- };
189
- return /*#__PURE__*/_react.default.createElement("element", null, /*#__PURE__*/_react.default.createElement("box", {
190
- top: 0,
191
- left: 0,
192
- width: "100%",
193
- height: 1,
194
- align: "center",
195
- valign: "middle",
196
- style: {
197
- bg: 'white',
198
- fg: 'black'
199
- },
200
- content: (0, _dateFns.format)(date, 'PPPP')
201
- }), /*#__PURE__*/_react.default.createElement("element", {
202
- top: 2,
203
- left: 0,
204
- width: "100%",
205
- height: "100%-2"
206
- }, !schedule && loading && /*#__PURE__*/_react.default.createElement("box", _extends({}, messageStyle, {
207
- content: "Loading..."
208
- })), schedule && games.length === 0 && /*#__PURE__*/_react.default.createElement("box", _extends({}, messageStyle, {
209
- content: "No games today"
210
- })), schedule && games.length > 0 && /*#__PURE__*/_react.default.createElement(_Grid.default, {
211
- items: games.map(formatGame),
212
- itemHeight: 5,
213
- itemMinWidth: 34,
214
- onSelect: handleGameSelect
215
- })));
216
- }
217
-
218
- GameList.propTypes = {
219
- onGameSelect: _propTypes.default.func
220
- };
221
- var _default = GameList;
222
- exports.default = _default;
@@ -1,115 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
- var _useKey = _interopRequireDefault(require("../hooks/useKey"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
- 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); }
21
-
22
- function Grid({
23
- items,
24
- itemHeight,
25
- itemMinWidth,
26
- onSelect
27
- }) {
28
- const containerRef = (0, _react.useRef)();
29
- const [size, setSize] = (0, _react.useState)([0, 0]);
30
- const [selectedIndex, setSelectedIndex] = (0, _react.useState)(0);
31
-
32
- const updateSize = () => {
33
- var _containerRef$current, _containerRef$current2;
34
-
35
- return setSize([(_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.width, (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.height]);
36
- };
37
-
38
- (0, _react.useEffect)(updateSize, []);
39
- const pos = [];
40
- let row = 0;
41
- let col = 0;
42
- const numCols = Math.floor(size[0] / itemMinWidth);
43
- const colWidth = Math.floor(size[0] / numCols);
44
-
45
- for (let i = 0; i < items.length; i++) {
46
- pos.push({
47
- top: row,
48
- left: col,
49
- width: colWidth,
50
- height: itemHeight
51
- });
52
- col += colWidth;
53
-
54
- if (col > size[0] - colWidth) {
55
- col = 0;
56
- row += itemHeight;
57
- }
58
- }
59
-
60
- (0, _react.useEffect)(() => {
61
- const curr = pos[selectedIndex].top;
62
- const total = pos[pos.length - 1].top;
63
- const perc = Math.round(curr / total * 100);
64
- containerRef.current.setScrollPerc(perc);
65
- }, [pos, selectedIndex]);
66
- (0, _useKey.default)(['right', 'l'], (0, _react.useCallback)(() => setSelectedIndex(prev => Math.min(prev + 1, items.length - 1)), [items.length]));
67
- (0, _useKey.default)(['left', 'h'], (0, _react.useCallback)(() => setSelectedIndex(prev => Math.max(prev - 1, 0)), []));
68
- (0, _useKey.default)(['down', 'j'], (0, _react.useCallback)(() => {
69
- setSelectedIndex(prev => {
70
- const next = prev + numCols;
71
-
72
- if (next < items.length) {
73
- return next;
74
- } else {
75
- return prev;
76
- }
77
- });
78
- }, [numCols, items.length]));
79
- (0, _useKey.default)(['up', 'k'], (0, _react.useCallback)(() => {
80
- setSelectedIndex(prev => {
81
- const next = prev - numCols;
82
-
83
- if (next >= 0) {
84
- return next;
85
- } else {
86
- return prev;
87
- }
88
- });
89
- }, [numCols]));
90
- (0, _useKey.default)('enter', () => onSelect(selectedIndex));
91
- return /*#__PURE__*/_react.default.createElement("box", {
92
- ref: containerRef,
93
- onResize: updateSize,
94
- width: "100%",
95
- height: "100%",
96
- scrollable: true
97
- }, pos.map((p, idx) => /*#__PURE__*/_react.default.createElement("box", _extends({}, p, {
98
- border: {
99
- type: selectedIndex === idx ? 'line' : 'bg'
100
- },
101
- key: items[idx],
102
- tags: true,
103
- content: items[idx],
104
- wrap: false
105
- }))));
106
- }
107
-
108
- Grid.propTypes = {
109
- items: _propTypes.default.arrayOf(_propTypes.default.string),
110
- itemHeight: _propTypes.default.number,
111
- itemMinWidth: _propTypes.default.number,
112
- onSelect: _propTypes.default.func
113
- };
114
- var _default = Grid;
115
- exports.default = _default;
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _alternateRenderers = require("react-redux/lib/alternate-renderers");
11
-
12
- var _LoadingSpinner = _interopRequireDefault(require("./LoadingSpinner"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- const HelpBar = () => {
17
- const keys = (0, _alternateRenderers.useSelector)(state => state.keys);
18
- const content = keys.map(({
19
- key,
20
- label
21
- }) => `{inverse}${key}{/inverse}:${label}`).join(' ');
22
- return /*#__PURE__*/_react.default.createElement("element", null, /*#__PURE__*/_react.default.createElement(_LoadingSpinner.default, null), /*#__PURE__*/_react.default.createElement("box", {
23
- left: 3,
24
- content: content,
25
- tags: true
26
- }));
27
- };
28
-
29
- var _default = HelpBar;
30
- exports.default = _default;
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _alternateRenderers = require("react-redux/lib/alternate-renderers");
11
-
12
- var _games = require("../features/games");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- function InningDisplay() {
17
- const linescore = (0, _alternateRenderers.useSelector)(_games.selectLineScore);
18
- const content = [linescore.isTopInning ? '▲' : '', linescore.currentInning, linescore.isTopInning ? '' : '▼'].join('\n');
19
- return /*#__PURE__*/_react.default.createElement("box", {
20
- content: content,
21
- align: "right"
22
- });
23
- }
24
-
25
- var _default = InningDisplay;
26
- exports.default = _default;