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,124 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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";
|
|
18
5
|
const getPlayer = (id, boxscore) => {
|
|
19
|
-
var _boxscore$home, _boxscore$
|
|
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
|
-
|
|
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];
|
|
23
8
|
if (homePlayer !== undefined) {
|
|
24
9
|
return homePlayer;
|
|
25
10
|
}
|
|
26
|
-
|
|
27
11
|
return (_boxscore$away = boxscore.away) === null || _boxscore$away === void 0 ? void 0 : _boxscore$away.players['ID' + id];
|
|
28
12
|
};
|
|
29
|
-
|
|
30
13
|
const formatDecisions = (decisions, boxscore) => {
|
|
31
14
|
if (!decisions) {
|
|
32
15
|
return '';
|
|
33
16
|
}
|
|
34
|
-
|
|
35
17
|
const content = [];
|
|
36
18
|
const winner = decisions.winner;
|
|
37
|
-
|
|
38
19
|
if (winner) {
|
|
39
|
-
var _pitcher$seasonStats, _pitcher$
|
|
40
|
-
|
|
20
|
+
var _pitcher$seasonStats, _pitcher$seasonStats2;
|
|
41
21
|
const pitcher = getPlayer(winner.id, boxscore);
|
|
42
|
-
content.push(`Win: ${pitcher.person.fullName} (${(_pitcher$seasonStats = pitcher.seasonStats) === null || _pitcher$seasonStats === void 0
|
|
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})`);
|
|
43
23
|
}
|
|
44
|
-
|
|
45
24
|
const loser = decisions.loser;
|
|
46
|
-
|
|
47
25
|
if (loser) {
|
|
48
|
-
var _pitcher$
|
|
49
|
-
|
|
26
|
+
var _pitcher$seasonStats3, _pitcher$seasonStats4;
|
|
50
27
|
const pitcher = getPlayer(loser.id, boxscore);
|
|
51
|
-
content.push(`Loss: ${pitcher.person.fullName} (${(_pitcher$
|
|
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})`);
|
|
52
29
|
}
|
|
53
|
-
|
|
54
30
|
const save = decisions.save;
|
|
55
|
-
|
|
56
31
|
if (save) {
|
|
57
|
-
var _pitcher$
|
|
58
|
-
|
|
32
|
+
var _pitcher$seasonStats5;
|
|
59
33
|
const pitcher = getPlayer(save.id, boxscore);
|
|
60
|
-
content.push(`Save: ${pitcher.person.fullName} (${(_pitcher$
|
|
34
|
+
content.push(`Save: ${pitcher.person.fullName} (${(_pitcher$seasonStats5 = pitcher.seasonStats) === null || _pitcher$seasonStats5 === void 0 ? void 0 : _pitcher$seasonStats5.pitching.saves})`);
|
|
61
35
|
}
|
|
62
|
-
|
|
63
36
|
return content.join('\n');
|
|
64
37
|
};
|
|
65
|
-
|
|
66
38
|
const formatScore = (status, linescore) => {
|
|
67
39
|
let display = '';
|
|
68
|
-
|
|
69
40
|
if (status.detailedState === 'Postponed') {
|
|
70
41
|
display = status.detailedState;
|
|
71
|
-
|
|
72
42
|
if (status.reason) {
|
|
73
43
|
display += '\n' + status.reason;
|
|
74
44
|
}
|
|
75
45
|
} else {
|
|
76
46
|
display = `\n${linescore.teams.away.runs} - ${linescore.teams.home.runs}`;
|
|
77
47
|
}
|
|
78
|
-
|
|
79
48
|
return display;
|
|
80
49
|
};
|
|
81
|
-
|
|
82
50
|
function FinishedGame() {
|
|
83
|
-
const boxscore =
|
|
84
|
-
const decisions =
|
|
85
|
-
const linescore =
|
|
86
|
-
const status =
|
|
87
|
-
const teams =
|
|
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);
|
|
88
56
|
const awayTeam = `${teams.away.teamName}\n(${teams.away.record.wins}-${teams.away.record.losses})`;
|
|
89
57
|
const homeTeam = `${teams.home.teamName}\n(${teams.home.record.wins}-${teams.home.record.losses})`;
|
|
90
|
-
return /*#__PURE__*/
|
|
58
|
+
return /*#__PURE__*/React.createElement("element", null, /*#__PURE__*/React.createElement("element", {
|
|
91
59
|
height: "60%"
|
|
92
|
-
}, /*#__PURE__*/
|
|
60
|
+
}, /*#__PURE__*/React.createElement("box", {
|
|
93
61
|
content: awayTeam,
|
|
94
62
|
width: "33%-1",
|
|
95
63
|
top: "50%",
|
|
96
64
|
align: "center"
|
|
97
|
-
}), /*#__PURE__*/
|
|
65
|
+
}), /*#__PURE__*/React.createElement("box", {
|
|
98
66
|
content: formatScore(status, linescore),
|
|
99
67
|
width: "33%-1",
|
|
100
68
|
left: "33%",
|
|
101
69
|
top: "50%",
|
|
102
70
|
align: "center"
|
|
103
|
-
}), /*#__PURE__*/
|
|
71
|
+
}), /*#__PURE__*/React.createElement("box", {
|
|
104
72
|
content: homeTeam,
|
|
105
73
|
width: "34%",
|
|
106
74
|
top: "50%",
|
|
107
75
|
left: "66%",
|
|
108
76
|
align: "center"
|
|
109
|
-
})), /*#__PURE__*/
|
|
77
|
+
})), /*#__PURE__*/React.createElement("element", {
|
|
110
78
|
top: "60%+1",
|
|
111
79
|
height: 3
|
|
112
|
-
}, /*#__PURE__*/
|
|
80
|
+
}, /*#__PURE__*/React.createElement(LineScore, {
|
|
113
81
|
align: "center",
|
|
114
82
|
final: true
|
|
115
|
-
})), /*#__PURE__*/
|
|
83
|
+
})), /*#__PURE__*/React.createElement("element", {
|
|
116
84
|
top: "60%+5",
|
|
117
85
|
left: "50%-20"
|
|
118
|
-
}, /*#__PURE__*/
|
|
86
|
+
}, /*#__PURE__*/React.createElement("box", {
|
|
119
87
|
content: formatDecisions(decisions, boxscore)
|
|
120
88
|
})));
|
|
121
89
|
}
|
|
122
|
-
|
|
123
|
-
var _default = FinishedGame;
|
|
124
|
-
exports.default = _default;
|
|
90
|
+
export default FinishedGame;
|
package/dist/components/Game.js
CHANGED
|
@@ -1,82 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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";
|
|
28
8
|
function Game() {
|
|
29
|
-
var _game$metaData, _game$gameData
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
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
|
-
|
|
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;
|
|
39
17
|
const updateGameData = () => {
|
|
40
|
-
dispatch(
|
|
18
|
+
dispatch(fetchGame({
|
|
41
19
|
id,
|
|
42
20
|
start: timestampRef.current
|
|
43
21
|
})).unwrap().then(result => {
|
|
44
22
|
var _result$metaData;
|
|
45
|
-
|
|
46
23
|
const wait = (result && ((_result$metaData = result.metaData) === null || _result$metaData === void 0 ? void 0 : _result$metaData.wait) || 10) * 1000;
|
|
47
24
|
timerRef.current = setTimeout(updateGameData, wait);
|
|
48
|
-
}).catch(err =>
|
|
25
|
+
}).catch(err => log.error('UPDATE_GAME_DATA:\n' + JSON.stringify(err) + '\n' + err.stack));
|
|
49
26
|
};
|
|
50
|
-
|
|
51
|
-
(0, _react.useEffect)(() => {
|
|
27
|
+
useEffect(() => {
|
|
52
28
|
updateGameData();
|
|
53
29
|
return () => {
|
|
54
30
|
clearTimeout(timerRef.current);
|
|
55
31
|
};
|
|
56
32
|
}, [id]);
|
|
57
|
-
|
|
58
33
|
if (!game) {
|
|
59
|
-
return /*#__PURE__*/
|
|
34
|
+
return /*#__PURE__*/React.createElement("element", null);
|
|
60
35
|
}
|
|
61
|
-
|
|
62
36
|
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) {
|
|
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) {
|
|
65
38
|
case 'P':
|
|
66
|
-
Wrapped =
|
|
39
|
+
Wrapped = PreviewGame;
|
|
67
40
|
break;
|
|
68
|
-
|
|
69
41
|
case 'L':
|
|
70
|
-
Wrapped =
|
|
42
|
+
Wrapped = LiveGame;
|
|
71
43
|
break;
|
|
72
|
-
|
|
73
44
|
case 'F':
|
|
74
|
-
Wrapped =
|
|
45
|
+
Wrapped = FinishedGame;
|
|
75
46
|
break;
|
|
76
47
|
}
|
|
77
|
-
|
|
78
|
-
return /*#__PURE__*/_react.default.createElement("element", null, /*#__PURE__*/_react.default.createElement(Wrapped, null));
|
|
48
|
+
return /*#__PURE__*/React.createElement("element", null, /*#__PURE__*/React.createElement(Wrapped, null));
|
|
79
49
|
}
|
|
80
|
-
|
|
81
|
-
var _default = Game;
|
|
82
|
-
exports.default = _default;
|
|
50
|
+
export default Game;
|
|
@@ -1,183 +1,134 @@
|
|
|
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
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); }
|
|
29
|
-
|
|
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";
|
|
30
10
|
const formatGame = game => {
|
|
31
|
-
const startTime =
|
|
11
|
+
const startTime = format(new Date(game.gameDate), 'p');
|
|
32
12
|
const start = game.doubleHeader === 'Y' && game.gameNumber > 1 ? 'Game ' + game.gameNumber : startTime;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
};
|
|
36
17
|
let content = [start, teamName(game.teams.away), teamName(game.teams.home)];
|
|
37
18
|
const gameState = game.status.abstractGameCode;
|
|
38
19
|
const detailedState = game.status.detailedState;
|
|
39
|
-
|
|
40
20
|
switch (gameState) {
|
|
41
21
|
case 'P':
|
|
42
22
|
break;
|
|
43
|
-
|
|
44
23
|
case 'L':
|
|
45
24
|
if (detailedState === 'Warmup') {
|
|
46
25
|
content[0] = detailedState;
|
|
47
26
|
} else {
|
|
48
27
|
content[0] = game.linescore.inningState + ' ' + game.linescore.currentInningOrdinal;
|
|
49
|
-
|
|
50
28
|
if (detailedState !== 'In Progress') {
|
|
51
29
|
content[0] += ' | ' + detailedState;
|
|
52
30
|
}
|
|
53
31
|
}
|
|
54
|
-
|
|
55
32
|
if (game.linescore) {
|
|
56
33
|
content[0] = content[0].padEnd(20) + ' R H E';
|
|
57
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);
|
|
58
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);
|
|
59
36
|
}
|
|
60
|
-
|
|
61
37
|
break;
|
|
62
|
-
|
|
63
38
|
case 'F':
|
|
64
39
|
content[0] = detailedState;
|
|
65
|
-
|
|
66
40
|
if (game.status.reason) {
|
|
67
41
|
content[0] += ' | ' + game.status.reason;
|
|
68
42
|
}
|
|
69
|
-
|
|
70
43
|
if (game.linescore) {
|
|
71
44
|
if (game.linescore.currentInning !== game.scheduledInnings) {
|
|
72
45
|
content[0] += '/' + game.linescore.currentInning;
|
|
73
46
|
}
|
|
74
|
-
|
|
75
47
|
content[0] = content[0].padEnd(20) + ' R H E';
|
|
76
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);
|
|
77
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);
|
|
78
|
-
|
|
79
50
|
if (game.teams.away.isWinner) {
|
|
80
51
|
content[1] = `{bold}${content[1]}{/bold}`;
|
|
81
52
|
}
|
|
82
|
-
|
|
83
53
|
if (game.teams.home.isWinner) {
|
|
84
54
|
content[2] = `{bold}${content[2]}{/bold}`;
|
|
85
55
|
}
|
|
86
56
|
}
|
|
87
|
-
|
|
88
57
|
break;
|
|
89
58
|
}
|
|
90
|
-
|
|
91
59
|
return content.map(s => ' ' + s).join('\n');
|
|
92
60
|
};
|
|
93
|
-
|
|
94
61
|
const GAME_STATE_ORDER = {
|
|
95
62
|
L: 0,
|
|
96
63
|
P: 1,
|
|
97
64
|
F: 2
|
|
98
65
|
};
|
|
99
|
-
|
|
100
66
|
function compareGameState(a, b) {
|
|
101
67
|
return GAME_STATE_ORDER[a.status.abstractGameCode] - GAME_STATE_ORDER[b.status.abstractGameCode];
|
|
102
68
|
}
|
|
103
|
-
|
|
104
69
|
function compareGameInnings(a, b) {
|
|
105
70
|
const inningCompare = b.linescore.currentInning - a.linescore.currentInning;
|
|
106
|
-
|
|
107
71
|
if (inningCompare !== 0) {
|
|
108
72
|
return inningCompare;
|
|
109
73
|
}
|
|
110
|
-
|
|
111
74
|
if (a.isTopInning && !b.isTopInning) {
|
|
112
75
|
return -1;
|
|
113
76
|
}
|
|
114
|
-
|
|
115
77
|
if (b.isTopInning && !a.isTopInning) {
|
|
116
78
|
return 1;
|
|
117
79
|
}
|
|
118
|
-
|
|
119
80
|
return 0;
|
|
120
81
|
}
|
|
121
|
-
|
|
122
82
|
function compareGames(a, b) {
|
|
123
83
|
const stateCompare = compareGameState(a, b);
|
|
124
|
-
|
|
125
84
|
if (stateCompare !== 0) {
|
|
126
85
|
return stateCompare;
|
|
127
86
|
}
|
|
128
|
-
|
|
129
87
|
if (a.status.abstractGameCode === 'L') {
|
|
130
88
|
const inningCompare = compareGameInnings(a, b);
|
|
131
|
-
|
|
132
89
|
if (inningCompare !== 0) {
|
|
133
90
|
return inningCompare;
|
|
134
91
|
}
|
|
135
92
|
}
|
|
136
|
-
|
|
137
93
|
return 0;
|
|
138
94
|
}
|
|
139
|
-
|
|
140
95
|
function GameList({
|
|
141
96
|
onGameSelect
|
|
142
97
|
}) {
|
|
143
|
-
const dispatch =
|
|
144
|
-
const schedule =
|
|
145
|
-
const loading =
|
|
146
|
-
const timerRef =
|
|
147
|
-
const [date, setDate] =
|
|
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());
|
|
148
103
|
let games = [];
|
|
149
|
-
|
|
150
104
|
if (schedule && schedule.dates.length > 0) {
|
|
151
105
|
games = schedule.dates[0].games.slice().sort(compareGames);
|
|
152
106
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
timerRef.current = setInterval(() => dispatch((0, _schedule.fetchSchedule)(date)), 30000);
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
dispatch(fetchSchedule(date));
|
|
109
|
+
timerRef.current = setInterval(() => dispatch(fetchSchedule(date)), 30000);
|
|
157
110
|
return () => clearInterval(timerRef.current);
|
|
158
111
|
}, [date]);
|
|
159
|
-
(
|
|
112
|
+
useKey('p', useCallback(() => setDate(prev => add(prev, {
|
|
160
113
|
days: -1
|
|
161
114
|
})), []), {
|
|
162
115
|
key: 'P',
|
|
163
116
|
label: 'Prev Day'
|
|
164
117
|
});
|
|
165
|
-
(
|
|
118
|
+
useKey('n', useCallback(() => setDate(prev => add(prev, {
|
|
166
119
|
days: 1
|
|
167
120
|
})), []), {
|
|
168
121
|
key: 'N',
|
|
169
122
|
label: 'Next Day'
|
|
170
123
|
});
|
|
171
|
-
(
|
|
124
|
+
useKey('t', useCallback(() => setDate(new Date()), []), {
|
|
172
125
|
key: 'T',
|
|
173
126
|
label: 'Today'
|
|
174
127
|
});
|
|
175
|
-
|
|
176
128
|
const handleGameSelect = idx => {
|
|
177
129
|
const selected = games[idx];
|
|
178
130
|
onGameSelect(selected);
|
|
179
131
|
};
|
|
180
|
-
|
|
181
132
|
const messageStyle = {
|
|
182
133
|
left: 0,
|
|
183
134
|
top: 0,
|
|
@@ -186,7 +137,7 @@ function GameList({
|
|
|
186
137
|
align: 'center',
|
|
187
138
|
valign: 'middle'
|
|
188
139
|
};
|
|
189
|
-
return /*#__PURE__*/
|
|
140
|
+
return /*#__PURE__*/React.createElement("element", null, /*#__PURE__*/React.createElement("box", {
|
|
190
141
|
top: 0,
|
|
191
142
|
left: 0,
|
|
192
143
|
width: "100%",
|
|
@@ -197,26 +148,24 @@ function GameList({
|
|
|
197
148
|
bg: 'white',
|
|
198
149
|
fg: 'black'
|
|
199
150
|
},
|
|
200
|
-
content:
|
|
201
|
-
}), /*#__PURE__*/
|
|
151
|
+
content: format(date, 'PPPP')
|
|
152
|
+
}), /*#__PURE__*/React.createElement("element", {
|
|
202
153
|
top: 2,
|
|
203
154
|
left: 0,
|
|
204
155
|
width: "100%",
|
|
205
156
|
height: "100%-2"
|
|
206
|
-
}, !schedule && loading && /*#__PURE__*/
|
|
157
|
+
}, !schedule && loading && /*#__PURE__*/React.createElement("box", _extends({}, messageStyle, {
|
|
207
158
|
content: "Loading..."
|
|
208
|
-
})), schedule && games.length === 0 && /*#__PURE__*/
|
|
159
|
+
})), schedule && games.length === 0 && /*#__PURE__*/React.createElement("box", _extends({}, messageStyle, {
|
|
209
160
|
content: "No games today"
|
|
210
|
-
})), schedule && games.length > 0 && /*#__PURE__*/
|
|
161
|
+
})), schedule && games.length > 0 && /*#__PURE__*/React.createElement(Grid, {
|
|
211
162
|
items: games.map(formatGame),
|
|
212
163
|
itemHeight: 5,
|
|
213
164
|
itemMinWidth: 34,
|
|
214
165
|
onSelect: handleGameSelect
|
|
215
166
|
})));
|
|
216
167
|
}
|
|
217
|
-
|
|
218
168
|
GameList.propTypes = {
|
|
219
|
-
onGameSelect:
|
|
169
|
+
onGameSelect: PropTypes.func
|
|
220
170
|
};
|
|
221
|
-
|
|
222
|
-
exports.default = _default;
|
|
171
|
+
export default GameList;
|
package/dist/components/Grid.js
CHANGED
|
@@ -1,47 +1,26 @@
|
|
|
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
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); }
|
|
21
|
-
|
|
2
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import useKey from "../hooks/useKey.js";
|
|
22
5
|
function Grid({
|
|
23
6
|
items,
|
|
24
7
|
itemHeight,
|
|
25
8
|
itemMinWidth,
|
|
26
9
|
onSelect
|
|
27
10
|
}) {
|
|
28
|
-
const containerRef =
|
|
29
|
-
const [size, setSize] =
|
|
30
|
-
const [selectedIndex, setSelectedIndex] =
|
|
31
|
-
|
|
11
|
+
const containerRef = useRef();
|
|
12
|
+
const [size, setSize] = useState([0, 0]);
|
|
13
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
32
14
|
const updateSize = () => {
|
|
33
15
|
var _containerRef$current, _containerRef$current2;
|
|
34
|
-
|
|
35
16
|
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
17
|
};
|
|
37
|
-
|
|
38
|
-
(0, _react.useEffect)(updateSize, []);
|
|
18
|
+
useEffect(updateSize, []);
|
|
39
19
|
const pos = [];
|
|
40
20
|
let row = 0;
|
|
41
21
|
let col = 0;
|
|
42
22
|
const numCols = Math.floor(size[0] / itemMinWidth);
|
|
43
23
|
const colWidth = Math.floor(size[0] / numCols);
|
|
44
|
-
|
|
45
24
|
for (let i = 0; i < items.length; i++) {
|
|
46
25
|
pos.push({
|
|
47
26
|
top: row,
|
|
@@ -50,25 +29,22 @@ function Grid({
|
|
|
50
29
|
height: itemHeight
|
|
51
30
|
});
|
|
52
31
|
col += colWidth;
|
|
53
|
-
|
|
54
32
|
if (col > size[0] - colWidth) {
|
|
55
33
|
col = 0;
|
|
56
34
|
row += itemHeight;
|
|
57
35
|
}
|
|
58
36
|
}
|
|
59
|
-
|
|
60
|
-
(0, _react.useEffect)(() => {
|
|
37
|
+
useEffect(() => {
|
|
61
38
|
const curr = pos[selectedIndex].top;
|
|
62
39
|
const total = pos[pos.length - 1].top;
|
|
63
40
|
const perc = Math.round(curr / total * 100);
|
|
64
41
|
containerRef.current.setScrollPerc(perc);
|
|
65
42
|
}, [pos, selectedIndex]);
|
|
66
|
-
(
|
|
67
|
-
(
|
|
68
|
-
(
|
|
43
|
+
useKey(['right', 'l'], useCallback(() => setSelectedIndex(prev => Math.min(prev + 1, items.length - 1)), [items.length]));
|
|
44
|
+
useKey(['left', 'h'], useCallback(() => setSelectedIndex(prev => Math.max(prev - 1, 0)), []));
|
|
45
|
+
useKey(['down', 'j'], useCallback(() => {
|
|
69
46
|
setSelectedIndex(prev => {
|
|
70
47
|
const next = prev + numCols;
|
|
71
|
-
|
|
72
48
|
if (next < items.length) {
|
|
73
49
|
return next;
|
|
74
50
|
} else {
|
|
@@ -76,10 +52,9 @@ function Grid({
|
|
|
76
52
|
}
|
|
77
53
|
});
|
|
78
54
|
}, [numCols, items.length]));
|
|
79
|
-
(
|
|
55
|
+
useKey(['up', 'k'], useCallback(() => {
|
|
80
56
|
setSelectedIndex(prev => {
|
|
81
57
|
const next = prev - numCols;
|
|
82
|
-
|
|
83
58
|
if (next >= 0) {
|
|
84
59
|
return next;
|
|
85
60
|
} else {
|
|
@@ -87,14 +62,14 @@ function Grid({
|
|
|
87
62
|
}
|
|
88
63
|
});
|
|
89
64
|
}, [numCols]));
|
|
90
|
-
(
|
|
91
|
-
return /*#__PURE__*/
|
|
65
|
+
useKey('enter', () => onSelect(selectedIndex));
|
|
66
|
+
return /*#__PURE__*/React.createElement("box", {
|
|
92
67
|
ref: containerRef,
|
|
93
68
|
onResize: updateSize,
|
|
94
69
|
width: "100%",
|
|
95
70
|
height: "100%",
|
|
96
71
|
scrollable: true
|
|
97
|
-
}, pos.map((p, idx) => /*#__PURE__*/
|
|
72
|
+
}, pos.map((p, idx) => /*#__PURE__*/React.createElement("box", _extends({}, p, {
|
|
98
73
|
border: {
|
|
99
74
|
type: selectedIndex === idx ? 'line' : 'bg'
|
|
100
75
|
},
|
|
@@ -104,12 +79,10 @@ function Grid({
|
|
|
104
79
|
wrap: false
|
|
105
80
|
}))));
|
|
106
81
|
}
|
|
107
|
-
|
|
108
82
|
Grid.propTypes = {
|
|
109
|
-
items:
|
|
110
|
-
itemHeight:
|
|
111
|
-
itemMinWidth:
|
|
112
|
-
onSelect:
|
|
83
|
+
items: PropTypes.arrayOf(PropTypes.string),
|
|
84
|
+
itemHeight: PropTypes.number,
|
|
85
|
+
itemMinWidth: PropTypes.number,
|
|
86
|
+
onSelect: PropTypes.func
|
|
113
87
|
};
|
|
114
|
-
|
|
115
|
-
exports.default = _default;
|
|
88
|
+
export default Grid;
|