playball 2.2.0 → 3.0.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 (74) hide show
  1. package/.eslintrc.json +2 -2
  2. package/README.md +18 -4
  3. package/demo.cast +95 -0
  4. package/demo.gif +0 -0
  5. package/dist/components/AllPlays.js +94 -93
  6. package/dist/components/App.js +45 -117
  7. package/dist/components/AtBat.js +44 -43
  8. package/dist/components/Bases.js +17 -26
  9. package/dist/components/Count.js +15 -26
  10. package/dist/components/FinishedGame.js +51 -66
  11. package/dist/components/Game.js +51 -114
  12. package/dist/components/GameList.js +161 -134
  13. package/dist/components/Grid.js +115 -0
  14. package/dist/components/HelpBar.js +13 -6
  15. package/dist/components/InningDisplay.js +26 -0
  16. package/dist/components/LineScore.js +32 -90
  17. package/dist/components/LiveGame.js +24 -19
  18. package/dist/components/LoadingSpinner.js +34 -125
  19. package/dist/components/Matchup.js +38 -59
  20. package/dist/components/PreviewGame.js +34 -52
  21. package/dist/components/Standings.js +91 -0
  22. package/dist/features/games.js +135 -0
  23. package/dist/features/keys.js +63 -0
  24. package/dist/features/schedule.js +58 -0
  25. package/dist/features/standings.js +57 -0
  26. package/dist/hooks/useKey.js +23 -0
  27. package/dist/logger.js +8 -10
  28. package/dist/main.js +13 -23
  29. package/dist/screen.js +22 -0
  30. package/dist/store/index.js +21 -7
  31. package/dist/style/index.js +3 -3
  32. package/package.json +44 -26
  33. package/src/components/AllPlays.jsx +95 -63
  34. package/src/components/App.jsx +38 -66
  35. package/src/components/AtBat.jsx +34 -36
  36. package/src/components/Bases.jsx +8 -13
  37. package/src/components/Count.jsx +10 -15
  38. package/src/components/FinishedGame.jsx +29 -40
  39. package/src/components/Game.jsx +48 -65
  40. package/src/components/GameList.jsx +128 -82
  41. package/src/components/Grid.jsx +91 -0
  42. package/src/components/HelpBar.jsx +14 -9
  43. package/src/components/InningDisplay.jsx +19 -0
  44. package/src/components/LineScore.jsx +27 -33
  45. package/src/components/LiveGame.jsx +7 -3
  46. package/src/components/LoadingSpinner.jsx +26 -60
  47. package/src/components/Matchup.jsx +26 -39
  48. package/src/components/PreviewGame.jsx +22 -33
  49. package/src/components/Standings.jsx +78 -0
  50. package/src/features/games.js +165 -0
  51. package/src/features/keys.js +38 -0
  52. package/src/features/schedule.js +59 -0
  53. package/src/features/standings.js +60 -0
  54. package/src/hooks/useKey.js +13 -0
  55. package/src/main.js +7 -14
  56. package/src/screen.js +14 -0
  57. package/src/store/index.js +16 -7
  58. package/src/style/index.js +1 -1
  59. package/dist/actions/game.js +0 -36
  60. package/dist/actions/schedule.js +0 -31
  61. package/dist/actions/types.js +0 -16
  62. package/dist/reducers/game.js +0 -70
  63. package/dist/reducers/index.js +0 -21
  64. package/dist/reducers/schedule.js +0 -35
  65. package/dist/selectors/game.js +0 -82
  66. package/dist/selectors/schedule.js +0 -25
  67. package/src/actions/game.js +0 -25
  68. package/src/actions/schedule.js +0 -19
  69. package/src/actions/types.js +0 -5
  70. package/src/reducers/game.js +0 -56
  71. package/src/reducers/index.js +0 -9
  72. package/src/reducers/schedule.js +0 -28
  73. package/src/selectors/game.js +0 -93
  74. package/src/selectors/schedule.js +0 -18
@@ -3,193 +3,220 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = void 0;
6
+ exports.default = void 0;
7
7
 
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
- var _reactRedux = require("react-redux");
10
+ var _alternateRenderers = require("react-redux/lib/alternate-renderers");
11
11
 
12
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
13
 
14
- var _moment = _interopRequireDefault(require("moment"));
14
+ var _dateFns = require("date-fns");
15
15
 
16
- var _schedule = require("../selectors/schedule");
16
+ var _schedule = require("../features/schedule");
17
17
 
18
- var _schedule2 = require("../actions/schedule");
18
+ var _Grid = _interopRequireDefault(require("./Grid"));
19
19
 
20
- var _style = _interopRequireDefault(require("../style"));
20
+ var _useKey = _interopRequireDefault(require("../hooks/useKey"));
21
21
 
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
23
 
24
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
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
25
 
26
- function _extends() { _extends = Object.assign || 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); }
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
27
 
28
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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
29
 
30
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
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;
31
33
 
32
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
34
+ const teamName = team => `${team.team.teamName} (${team.leagueRecord.wins}-${team.leagueRecord.losses})`.padEnd(20);
33
35
 
34
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
35
-
36
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
37
-
38
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
39
-
40
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
41
-
42
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
43
-
44
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
45
-
46
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
47
-
48
- var formatGame = function formatGame(game) {
49
- var start = (0, _moment["default"])(game.gameDate).format('LT').padStart(8);
50
-
51
- var teamName = function teamName(team) {
52
- return "".concat(team.team.teamName, " (").concat(team.leagueRecord.wins, "-").concat(team.leagueRecord.losses, ")");
53
- };
54
-
55
- var content = "".concat(start, " ").concat(teamName(game.teams.away), " at ").concat(teamName(game.teams.home));
56
- var gameState = game.status.abstractGameCode;
57
- var detailedState = game.status.detailedState;
36
+ let content = [start, teamName(game.teams.away), teamName(game.teams.home)];
37
+ const gameState = game.status.abstractGameCode;
38
+ const detailedState = game.status.detailedState;
58
39
 
59
40
  switch (gameState) {
60
41
  case 'P':
61
42
  break;
62
43
 
63
44
  case 'L':
64
- if (detailedState !== 'In Progress') {
65
- content += ' | ' + detailedState;
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
+ }
66
53
  }
67
54
 
68
55
  if (game.linescore) {
69
- content += ' | ' + game.linescore.inningState + ' ' + game.linescore.currentInningOrdinal + ' | ' + game.teams.away.team.abbreviation + ' ' + game.linescore.teams.away.runs + ' - ' + game.teams.home.team.abbreviation + ' ' + game.linescore.teams.home.runs;
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);
70
59
  }
71
60
 
72
61
  break;
73
62
 
74
63
  case 'F':
75
- content += ' | ' + detailedState;
64
+ content[0] = detailedState;
76
65
 
77
66
  if (game.status.reason) {
78
- content += ' | ' + game.status.reason;
67
+ content[0] += ' | ' + game.status.reason;
79
68
  }
80
69
 
81
70
  if (game.linescore) {
82
- content += ' | ' + game.teams.away.team.abbreviation + ' ' + game.linescore.teams.away.runs + ' - ' + game.teams.home.team.abbreviation + ' ' + game.linescore.teams.home.runs;
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
+ }
83
86
  }
84
87
 
85
88
  break;
86
89
  }
87
90
 
88
- return content;
91
+ return content.map(s => ' ' + s).join('\n');
89
92
  };
90
93
 
91
- var GameList = /*#__PURE__*/function (_React$Component) {
92
- _inherits(GameList, _React$Component);
94
+ const GAME_STATE_ORDER = {
95
+ L: 0,
96
+ P: 1,
97
+ F: 2
98
+ };
93
99
 
94
- var _super = _createSuper(GameList);
100
+ function compareGameState(a, b) {
101
+ return GAME_STATE_ORDER[a.status.abstractGameCode] - GAME_STATE_ORDER[b.status.abstractGameCode];
102
+ }
95
103
 
96
- function GameList(props) {
97
- var _this;
104
+ function compareGameInnings(a, b) {
105
+ const inningCompare = b.linescore.currentInning - a.linescore.currentInning;
98
106
 
99
- _classCallCheck(this, GameList);
107
+ if (inningCompare !== 0) {
108
+ return inningCompare;
109
+ }
100
110
 
101
- _this = _super.call(this, props);
102
- _this.handleGameSelect = _this.handleGameSelect.bind(_assertThisInitialized(_this));
103
- return _this;
111
+ if (a.isTopInning && !b.isTopInning) {
112
+ return -1;
104
113
  }
105
114
 
106
- _createClass(GameList, [{
107
- key: "componentDidMount",
108
- value: function componentDidMount() {
109
- this.props.fetchSchedule();
110
- }
111
- }, {
112
- key: "handleGameSelect",
113
- value: function handleGameSelect(item, idx) {
114
- var _this$props = this.props,
115
- onGameSelect = _this$props.onGameSelect,
116
- schedule = _this$props.schedule;
117
- var selected = schedule.dates[0].games[idx];
118
- onGameSelect(selected);
119
- }
120
- }, {
121
- key: "render",
122
- value: function render() {
123
- var _this$props2 = this.props,
124
- loading = _this$props2.loading,
125
- schedule = _this$props2.schedule;
126
- var messageStyle = {
127
- left: 'center',
128
- top: 'center',
129
- height: '80%',
130
- width: '80%',
131
- border: {
132
- type: 'line'
133
- },
134
- align: 'center',
135
- valign: 'middle'
136
- };
137
-
138
- if (loading) {
139
- return /*#__PURE__*/_react["default"].createElement("box", _extends({}, messageStyle, {
140
- content: "Loading..."
141
- }));
142
- }
115
+ if (b.isTopInning && !a.isTopInning) {
116
+ return 1;
117
+ }
143
118
 
144
- if (schedule && !schedule.dates.length) {
145
- return /*#__PURE__*/_react["default"].createElement("box", _extends({}, messageStyle, {
146
- content: "No games today"
147
- }));
148
- }
119
+ return 0;
120
+ }
121
+
122
+ function compareGames(a, b) {
123
+ const stateCompare = compareGameState(a, b);
149
124
 
150
- return /*#__PURE__*/_react["default"].createElement("list", {
151
- left: "center",
152
- top: "center",
153
- width: "80%",
154
- height: "80%",
155
- keys: true,
156
- vi: true,
157
- focused: true,
158
- border: {
159
- type: 'line'
160
- },
161
- label: " Select a game ",
162
- scrollbar: _style["default"].scrollbar,
163
- style: _style["default"].list,
164
- items: schedule && schedule.dates.length > 0 ? schedule.dates[0].games.map(formatGame) : [],
165
- onSelect: this.handleGameSelect
166
- });
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;
167
134
  }
168
- }]);
135
+ }
169
136
 
170
- return GameList;
171
- }(_react["default"].Component);
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
+ }
172
153
 
173
- GameList.propTypes = {
174
- error: _propTypes["default"].object,
175
- fetchSchedule: _propTypes["default"].func,
176
- loading: _propTypes["default"].bool,
177
- onGameSelect: _propTypes["default"].func,
178
- schedule: _propTypes["default"].object
179
- };
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
180
 
181
- var mapStateToProps = function mapStateToProps(state) {
182
- return {
183
- loading: (0, _schedule.selectLoading)(state),
184
- error: (0, _schedule.selectError)(state),
185
- schedule: (0, _schedule.selectData)(state)
181
+ const messageStyle = {
182
+ left: 0,
183
+ top: 0,
184
+ height: '100%',
185
+ width: '100%',
186
+ align: 'center',
187
+ valign: 'middle'
186
188
  };
187
- };
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
+ }
188
217
 
189
- var mapDispatchToProps = {
190
- fetchSchedule: _schedule2.fetchSchedule
218
+ GameList.propTypes = {
219
+ onGameSelect: _propTypes.default.func
191
220
  };
192
-
193
- var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(GameList);
194
-
195
- exports["default"] = _default;
221
+ var _default = GameList;
222
+ exports.default = _default;
@@ -0,0 +1,115 @@
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;
@@ -3,21 +3,28 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = void 0;
6
+ exports.default = void 0;
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
10
+ var _alternateRenderers = require("react-redux/lib/alternate-renderers");
11
+
10
12
  var _LoadingSpinner = _interopRequireDefault(require("./LoadingSpinner"));
11
13
 
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
 
14
- var HelpBar = function HelpBar() {
15
- return /*#__PURE__*/_react["default"].createElement("element", null, /*#__PURE__*/_react["default"].createElement(_LoadingSpinner["default"], null), /*#__PURE__*/_react["default"].createElement("box", {
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", {
16
23
  left: 3,
17
- content: '{inverse}Q{/inverse}:Quit {inverse}L{/inverse}:List Games',
24
+ content: content,
18
25
  tags: true
19
26
  }));
20
27
  };
21
28
 
22
29
  var _default = HelpBar;
23
- exports["default"] = _default;
30
+ exports.default = _default;
@@ -0,0 +1,26 @@
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;