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
package/dist/config.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import pkg from "./package.js";
|
|
2
|
+
import Conf from 'conf';
|
|
3
|
+
const colorPattern = '^(((light-|bright-)?(black|red|green|yellow|blue|magenta|cyan|white|grey))|default|#([0-9a-fA-F]{3}){1,2})$';
|
|
4
|
+
const schema = {
|
|
5
|
+
color: {
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
ball: {
|
|
9
|
+
type: 'string',
|
|
10
|
+
default: 'green',
|
|
11
|
+
pattern: colorPattern
|
|
12
|
+
},
|
|
13
|
+
strike: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
default: 'red',
|
|
16
|
+
pattern: colorPattern
|
|
17
|
+
},
|
|
18
|
+
out: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
default: 'red',
|
|
21
|
+
pattern: colorPattern
|
|
22
|
+
},
|
|
23
|
+
'on-base': {
|
|
24
|
+
type: 'string',
|
|
25
|
+
default: 'yellow',
|
|
26
|
+
pattern: colorPattern
|
|
27
|
+
},
|
|
28
|
+
'strike-out': {
|
|
29
|
+
type: 'string',
|
|
30
|
+
default: 'red',
|
|
31
|
+
pattern: colorPattern
|
|
32
|
+
},
|
|
33
|
+
'walk': {
|
|
34
|
+
type: 'string',
|
|
35
|
+
default: 'green',
|
|
36
|
+
pattern: colorPattern
|
|
37
|
+
},
|
|
38
|
+
'other-event': {
|
|
39
|
+
type: 'string',
|
|
40
|
+
default: 'white',
|
|
41
|
+
pattern: colorPattern
|
|
42
|
+
},
|
|
43
|
+
'in-play-no-out': {
|
|
44
|
+
type: 'string',
|
|
45
|
+
default: 'blue',
|
|
46
|
+
pattern: colorPattern
|
|
47
|
+
},
|
|
48
|
+
'in-play-out': {
|
|
49
|
+
type: 'string',
|
|
50
|
+
default: 'white',
|
|
51
|
+
pattern: colorPattern
|
|
52
|
+
},
|
|
53
|
+
'in-play-runs-bg': {
|
|
54
|
+
type: 'string',
|
|
55
|
+
default: 'white',
|
|
56
|
+
pattern: colorPattern
|
|
57
|
+
},
|
|
58
|
+
'in-play-runs-fg': {
|
|
59
|
+
type: 'string',
|
|
60
|
+
default: 'black',
|
|
61
|
+
pattern: colorPattern
|
|
62
|
+
},
|
|
63
|
+
'favorite-star': {
|
|
64
|
+
type: 'string',
|
|
65
|
+
default: 'yellow',
|
|
66
|
+
pattern: colorPattern
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
default: {}
|
|
70
|
+
},
|
|
71
|
+
favorites: {
|
|
72
|
+
type: 'array',
|
|
73
|
+
items: {
|
|
74
|
+
type: 'string',
|
|
75
|
+
enum: ['ATL', 'AZ', 'BAL', 'BOS', 'CHC', 'CIN', 'CLE', 'COL', 'CWS', 'DET', 'HOU', 'KC', 'LAA', 'LAD', 'MIA', 'MIL', 'MIN', 'NYM', 'NYY', 'OAK', 'PHI', 'PIT', 'SD', 'SEA', 'SF', 'STL', 'TB', 'TEX', 'TOR', 'WSH']
|
|
76
|
+
},
|
|
77
|
+
default: []
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const config = new Conf({
|
|
81
|
+
projectName: pkg.name,
|
|
82
|
+
schema
|
|
83
|
+
});
|
|
84
|
+
function serialize(value) {
|
|
85
|
+
if (value && Array.isArray(value)) {
|
|
86
|
+
return value.join(',');
|
|
87
|
+
}
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
function deserialize(key, value) {
|
|
91
|
+
var _schema$key;
|
|
92
|
+
if (value && ((_schema$key = schema[key]) === null || _schema$key === void 0 ? void 0 : _schema$key.type) === 'array') {
|
|
93
|
+
return value.split(/\s*,\s*/);
|
|
94
|
+
}
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
export function get(key) {
|
|
98
|
+
return serialize(config.get(key));
|
|
99
|
+
}
|
|
100
|
+
export function set(key, value) {
|
|
101
|
+
return config.set(key, deserialize(key, value));
|
|
102
|
+
}
|
|
103
|
+
export function unset(key) {
|
|
104
|
+
if (key) {
|
|
105
|
+
return config.delete(key);
|
|
106
|
+
} else {
|
|
107
|
+
return config.clear();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function flatten(obj) {
|
|
111
|
+
const result = {};
|
|
112
|
+
for (const [key, value] of Object.entries(obj).sort()) {
|
|
113
|
+
if (value != null && typeof value === 'object' && !Array.isArray(value)) {
|
|
114
|
+
const sub = flatten(value);
|
|
115
|
+
for (const [subkey, subvalue] of Object.entries(sub)) {
|
|
116
|
+
result[key + '.' + subkey] = subvalue;
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
result[key] = serialize(value);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
export function getAll() {
|
|
125
|
+
return flatten(config.store);
|
|
126
|
+
}
|
package/dist/features/games.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _toolkit = require("@reduxjs/toolkit");
|
|
11
|
-
|
|
12
|
-
var _jsonPatch = _interopRequireDefault(require("json-patch"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import reduxjsToolkit from '@reduxjs/toolkit';
|
|
3
|
+
const {
|
|
4
|
+
createAsyncThunk,
|
|
5
|
+
createSlice,
|
|
6
|
+
createSelector
|
|
7
|
+
} = reduxjsToolkit;
|
|
8
|
+
import jsonpatch from 'json-patch';
|
|
16
9
|
const initialState = {
|
|
17
10
|
loading: false,
|
|
18
11
|
fullUpdateRequired: false,
|
|
@@ -20,24 +13,22 @@ const initialState = {
|
|
|
20
13
|
selectedId: null,
|
|
21
14
|
games: {}
|
|
22
15
|
};
|
|
23
|
-
const fetchGame =
|
|
16
|
+
export const fetchGame = createAsyncThunk('games/fetch', async ({
|
|
24
17
|
id,
|
|
25
18
|
start
|
|
26
19
|
}) => {
|
|
27
20
|
const diffParams = start ? `/diffPatch?startTimecode=${start}` : '';
|
|
28
21
|
const url = `https://statsapi.mlb.com/api/v1.1/game/${id}/feed/live${diffParams}`;
|
|
29
|
-
const response = await
|
|
22
|
+
const response = await axios.get(url);
|
|
30
23
|
return response.data;
|
|
31
24
|
});
|
|
32
|
-
|
|
33
|
-
const gamesSlice = (0, _toolkit.createSlice)({
|
|
25
|
+
export const gamesSlice = createSlice({
|
|
34
26
|
name: 'games',
|
|
35
27
|
initialState,
|
|
36
28
|
reducers: {
|
|
37
29
|
setSelectedId(state, action) {
|
|
38
30
|
state.selectedId = action.payload;
|
|
39
31
|
}
|
|
40
|
-
|
|
41
32
|
},
|
|
42
33
|
extraReducers: builder => {
|
|
43
34
|
builder.addCase(fetchGame.pending, state => {
|
|
@@ -47,15 +38,13 @@ const gamesSlice = (0, _toolkit.createSlice)({
|
|
|
47
38
|
const id = state.selectedId;
|
|
48
39
|
let game = state.games[id];
|
|
49
40
|
let patchError = false;
|
|
50
|
-
|
|
51
41
|
if (Array.isArray(action.payload)) {
|
|
52
42
|
action.payload.forEach(obj => {
|
|
53
43
|
if (patchError) {
|
|
54
44
|
return;
|
|
55
45
|
}
|
|
56
|
-
|
|
57
46
|
try {
|
|
58
|
-
|
|
47
|
+
jsonpatch.apply(game || {}, obj.diff);
|
|
59
48
|
} catch (e) {
|
|
60
49
|
patchError = true;
|
|
61
50
|
return;
|
|
@@ -64,7 +53,6 @@ const gamesSlice = (0, _toolkit.createSlice)({
|
|
|
64
53
|
} else {
|
|
65
54
|
game = action.payload;
|
|
66
55
|
}
|
|
67
|
-
|
|
68
56
|
if (patchError) {
|
|
69
57
|
state.fullUpdateRequired = true;
|
|
70
58
|
} else {
|
|
@@ -72,7 +60,6 @@ const gamesSlice = (0, _toolkit.createSlice)({
|
|
|
72
60
|
state.error = null;
|
|
73
61
|
state.games[id] = game;
|
|
74
62
|
}
|
|
75
|
-
|
|
76
63
|
state.loading = false;
|
|
77
64
|
});
|
|
78
65
|
builder.addCase(fetchGame.rejected, (state, action) => {
|
|
@@ -82,54 +69,32 @@ const gamesSlice = (0, _toolkit.createSlice)({
|
|
|
82
69
|
});
|
|
83
70
|
}
|
|
84
71
|
});
|
|
85
|
-
|
|
86
|
-
const {
|
|
72
|
+
export const {
|
|
87
73
|
setSelectedId
|
|
88
74
|
} = gamesSlice.actions;
|
|
89
|
-
exports.setSelectedId = setSelectedId;
|
|
90
|
-
|
|
91
75
|
const gamesRoot = state => state.games;
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
exports.selectGame = selectGame;
|
|
103
|
-
const selectLiveData = (0, _toolkit.createSelector)(selectGame, game => game.liveData);
|
|
104
|
-
const selectPlays = (0, _toolkit.createSelector)(selectLiveData, data => data.plays);
|
|
105
|
-
const selectCurrentPlay = (0, _toolkit.createSelector)(selectPlays, plays => plays.currentPlay);
|
|
106
|
-
exports.selectCurrentPlay = selectCurrentPlay;
|
|
107
|
-
const selectAllPlays = (0, _toolkit.createSelector)(selectPlays, plays => plays.allPlays);
|
|
108
|
-
exports.selectAllPlays = selectAllPlays;
|
|
109
|
-
const selectBoxscore = (0, _toolkit.createSelector)(selectLiveData, data => {
|
|
76
|
+
export const selectLoading = createSelector(gamesRoot, root => root.loading);
|
|
77
|
+
export const selectError = createSelector(gamesRoot, root => root.error);
|
|
78
|
+
export const selectFullUpdateRequired = createSelector(gamesRoot, root => root.fullUpdateRequired);
|
|
79
|
+
export const selectSelectedId = createSelector(gamesRoot, root => root.selectedId);
|
|
80
|
+
export const selectGame = createSelector([gamesRoot, selectSelectedId], (root, id) => root.games[id]);
|
|
81
|
+
const selectLiveData = createSelector(selectGame, game => game.liveData);
|
|
82
|
+
const selectPlays = createSelector(selectLiveData, data => data.plays);
|
|
83
|
+
export const selectCurrentPlay = createSelector(selectPlays, plays => plays.currentPlay);
|
|
84
|
+
export const selectAllPlays = createSelector(selectPlays, plays => plays.allPlays);
|
|
85
|
+
export const selectBoxscore = createSelector(selectLiveData, data => {
|
|
110
86
|
var _data$boxscore;
|
|
111
|
-
|
|
112
87
|
return (_data$boxscore = data.boxscore) === null || _data$boxscore === void 0 ? void 0 : _data$boxscore.teams;
|
|
113
88
|
});
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
exports.selectGameStatus = selectGameStatus;
|
|
122
|
-
const selectTeams = (0, _toolkit.createSelector)(selectGameData, gameData => gameData.teams);
|
|
123
|
-
exports.selectTeams = selectTeams;
|
|
124
|
-
const selectVenue = (0, _toolkit.createSelector)(selectGameData, gameData => gameData.venue);
|
|
125
|
-
exports.selectVenue = selectVenue;
|
|
126
|
-
const selectStartTime = (0, _toolkit.createSelector)(selectGameData, gameData => {
|
|
89
|
+
export const selectLineScore = createSelector(selectLiveData, data => data.linescore);
|
|
90
|
+
export const selectDecisions = createSelector(selectLiveData, data => data.decisions);
|
|
91
|
+
const selectGameData = createSelector(selectGame, game => game.gameData);
|
|
92
|
+
export const selectGameStatus = createSelector(selectGameData, game => game.status);
|
|
93
|
+
export const selectTeams = createSelector(selectGameData, gameData => gameData.teams);
|
|
94
|
+
export const selectVenue = createSelector(selectGameData, gameData => gameData.venue);
|
|
95
|
+
export const selectStartTime = createSelector(selectGameData, gameData => {
|
|
127
96
|
var _gameData$datetime;
|
|
128
|
-
|
|
129
97
|
return (_gameData$datetime = gameData.datetime) === null || _gameData$datetime === void 0 ? void 0 : _gameData$datetime.dateTime;
|
|
130
98
|
});
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
exports.selectProbablePitchers = selectProbablePitchers;
|
|
134
|
-
var _default = gamesSlice.reducer;
|
|
135
|
-
exports.default = _default;
|
|
99
|
+
export const selectProbablePitchers = createSelector(selectGameData, gameData => gameData.probablePitchers);
|
|
100
|
+
export default gamesSlice.reducer;
|
package/dist/features/keys.js
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _toolkit = require("@reduxjs/toolkit");
|
|
9
|
-
|
|
10
|
-
var _screen = _interopRequireDefault(require("../screen"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
const keysSlice = (0, _toolkit.createSlice)({
|
|
1
|
+
import reduxjsToolkit from '@reduxjs/toolkit';
|
|
2
|
+
const {
|
|
3
|
+
createSlice
|
|
4
|
+
} = reduxjsToolkit;
|
|
5
|
+
import screen from "../screen.js";
|
|
6
|
+
export const keysSlice = createSlice({
|
|
15
7
|
name: 'keys',
|
|
16
8
|
initialState: [{
|
|
17
9
|
key: 'Q',
|
|
@@ -25,8 +17,7 @@ const keysSlice = (0, _toolkit.createSlice)({
|
|
|
25
17
|
}
|
|
26
18
|
},
|
|
27
19
|
prepare: (key, listener, help) => {
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
screen().key(key, listener);
|
|
30
21
|
return {
|
|
31
22
|
payload: help
|
|
32
23
|
};
|
|
@@ -36,15 +27,13 @@ const keysSlice = (0, _toolkit.createSlice)({
|
|
|
36
27
|
reducer: (state, action) => {
|
|
37
28
|
if (action.payload) {
|
|
38
29
|
const idx = state.findIndex(item => item.key === action.payload.key);
|
|
39
|
-
|
|
40
30
|
if (idx >= 0) {
|
|
41
31
|
state.splice(idx, 1);
|
|
42
32
|
}
|
|
43
33
|
}
|
|
44
34
|
},
|
|
45
35
|
prepare: (key, listener, help) => {
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
screen().unkey(key, listener);
|
|
48
37
|
return {
|
|
49
38
|
payload: help
|
|
50
39
|
};
|
|
@@ -52,12 +41,8 @@ const keysSlice = (0, _toolkit.createSlice)({
|
|
|
52
41
|
}
|
|
53
42
|
}
|
|
54
43
|
});
|
|
55
|
-
|
|
56
|
-
const {
|
|
44
|
+
export const {
|
|
57
45
|
addKeyListener,
|
|
58
46
|
removeKeyListener
|
|
59
47
|
} = keysSlice.actions;
|
|
60
|
-
|
|
61
|
-
exports.addKeyListener = addKeyListener;
|
|
62
|
-
var _default = keysSlice.reducer;
|
|
63
|
-
exports.default = _default;
|
|
48
|
+
export default keysSlice.reducer;
|
|
@@ -1,30 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _toolkit = require("@reduxjs/toolkit");
|
|
11
|
-
|
|
12
|
-
var _dateFns = require("date-fns");
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import reduxjsToolkit from '@reduxjs/toolkit';
|
|
3
|
+
const {
|
|
4
|
+
createAsyncThunk,
|
|
5
|
+
createSlice,
|
|
6
|
+
createSelector
|
|
7
|
+
} = reduxjsToolkit;
|
|
8
|
+
import { format } from 'date-fns';
|
|
16
9
|
const initialState = {
|
|
17
10
|
loading: false,
|
|
18
11
|
error: null,
|
|
19
12
|
data: null
|
|
20
13
|
};
|
|
21
|
-
const fetchSchedule =
|
|
22
|
-
const dateStr =
|
|
23
|
-
const response = await
|
|
14
|
+
export const fetchSchedule = createAsyncThunk('schedule/fetch', async date => {
|
|
15
|
+
const dateStr = format(date, 'MM/dd/yyyy');
|
|
16
|
+
const response = await axios.get(`http://statsapi.mlb.com/api/v1/schedule?sportId=1&hydrate=team,linescore&date=${dateStr}`);
|
|
24
17
|
return response.data;
|
|
25
18
|
});
|
|
26
|
-
|
|
27
|
-
const scheduleSlice = (0, _toolkit.createSlice)({
|
|
19
|
+
export const scheduleSlice = createSlice({
|
|
28
20
|
name: 'schedule',
|
|
29
21
|
initialState,
|
|
30
22
|
reducers: {},
|
|
@@ -44,15 +36,8 @@ const scheduleSlice = (0, _toolkit.createSlice)({
|
|
|
44
36
|
});
|
|
45
37
|
}
|
|
46
38
|
});
|
|
47
|
-
exports.scheduleSlice = scheduleSlice;
|
|
48
|
-
|
|
49
39
|
const scheduleSelector = state => state.schedule;
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
exports.selectError = selectError;
|
|
55
|
-
const selectData = (0, _toolkit.createSelector)(scheduleSelector, schedule => schedule.data);
|
|
56
|
-
exports.selectData = selectData;
|
|
57
|
-
var _default = scheduleSlice.reducer;
|
|
58
|
-
exports.default = _default;
|
|
40
|
+
export const selectLoading = createSelector(scheduleSelector, schedule => schedule.loading);
|
|
41
|
+
export const selectError = createSelector(scheduleSelector, schedule => schedule.error);
|
|
42
|
+
export const selectData = createSelector(scheduleSelector, schedule => schedule.data);
|
|
43
|
+
export default scheduleSlice.reducer;
|
|
@@ -1,29 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _axios = _interopRequireDefault(require("axios"));
|
|
9
|
-
|
|
10
|
-
var _toolkit = require("@reduxjs/toolkit");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import reduxjsToolkit from '@reduxjs/toolkit';
|
|
3
|
+
const {
|
|
4
|
+
createAsyncThunk,
|
|
5
|
+
createSlice,
|
|
6
|
+
createSelector
|
|
7
|
+
} = reduxjsToolkit;
|
|
14
8
|
const initialState = {
|
|
15
9
|
loading: false,
|
|
16
10
|
error: null,
|
|
17
11
|
data: null
|
|
18
12
|
};
|
|
19
13
|
const SEASON = new Date().getFullYear();
|
|
20
|
-
const fetchStandings =
|
|
14
|
+
export const fetchStandings = createAsyncThunk('standings/fetch', async () => {
|
|
21
15
|
const url = `https://statsapi.mlb.com/api/v1/standings?leagueId=103,104&season=${SEASON}&standingsTypes=regularSeason&hydrate=division,team`;
|
|
22
|
-
const response = await
|
|
16
|
+
const response = await axios.get(url);
|
|
23
17
|
return response.data;
|
|
24
18
|
});
|
|
25
|
-
|
|
26
|
-
const standingsSlice = (0, _toolkit.createSlice)({
|
|
19
|
+
export const standingsSlice = createSlice({
|
|
27
20
|
name: 'standings',
|
|
28
21
|
initialState,
|
|
29
22
|
reducers: {},
|
|
@@ -43,15 +36,8 @@ const standingsSlice = (0, _toolkit.createSlice)({
|
|
|
43
36
|
});
|
|
44
37
|
}
|
|
45
38
|
});
|
|
46
|
-
exports.standingsSlice = standingsSlice;
|
|
47
|
-
|
|
48
39
|
const standingsSelector = state => state.standings;
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
exports.selectError = selectError;
|
|
54
|
-
const selectData = (0, _toolkit.createSelector)(standingsSelector, standings => standings.data);
|
|
55
|
-
exports.selectData = selectData;
|
|
56
|
-
var _default = standingsSlice.reducer;
|
|
57
|
-
exports.default = _default;
|
|
40
|
+
export const selectLoading = createSelector(standingsSelector, standings => standings.loading);
|
|
41
|
+
export const selectError = createSelector(standingsSelector, standings => standings.error);
|
|
42
|
+
export const selectData = createSelector(standingsSelector, standings => standings.data);
|
|
43
|
+
export default standingsSlice.reducer;
|
package/dist/hooks/useKey.js
CHANGED
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
|
|
10
|
-
var _alternateRenderers = require("react-redux/lib/alternate-renderers");
|
|
11
|
-
|
|
12
|
-
var _keys = require("../features/keys");
|
|
13
|
-
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useDispatch } from "react-redux/lib/alternate-renderers.js";
|
|
3
|
+
import { addKeyListener, removeKeyListener } from "../features/keys.js";
|
|
14
4
|
function useKey(key, handler, help) {
|
|
15
|
-
const dispatch =
|
|
16
|
-
return
|
|
17
|
-
dispatch(
|
|
18
|
-
return () => dispatch(
|
|
5
|
+
const dispatch = useDispatch();
|
|
6
|
+
return useEffect(() => {
|
|
7
|
+
dispatch(addKeyListener(key, handler, help));
|
|
8
|
+
return () => dispatch(removeKeyListener(key, handler, help));
|
|
19
9
|
}, [key, handler, help, dispatch]);
|
|
20
10
|
}
|
|
21
|
-
|
|
22
|
-
var _default = useKey;
|
|
23
|
-
exports.default = _default;
|
|
11
|
+
export default useKey;
|
package/dist/logger.js
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _winston = _interopRequireDefault(require("winston"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
_winston.default.configure({
|
|
15
|
-
transports: [new _winston.default.transports.File({
|
|
16
|
-
filename: _path.default.resolve(__dirname, 'playball.log'),
|
|
17
|
-
format: _winston.default.format.combine(_winston.default.format.timestamp(), _winston.default.format.printf(info => `[${info.timestamp}] ${info.level}: ${info.message}`))
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import winston from 'winston';
|
|
4
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
winston.configure({
|
|
6
|
+
transports: [new winston.transports.File({
|
|
7
|
+
filename: path.resolve(__dirname, 'playball.log'),
|
|
8
|
+
format: winston.format.combine(winston.format.timestamp(), winston.format.printf(info => `[${info.timestamp}] ${info.level}: ${info.message}`))
|
|
18
9
|
})]
|
|
19
10
|
});
|
|
20
|
-
|
|
21
|
-
var _default = _winston.default;
|
|
22
|
-
exports.default = _default;
|
|
11
|
+
export default winston;
|
package/dist/main.js
CHANGED
|
@@ -1,28 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
_raf.default.polyfill();
|
|
22
|
-
|
|
23
|
-
process.on('uncaughtException', function (error) {
|
|
24
|
-
_logger.default.error('UNCAUGHT EXCEPTION\n' + JSON.stringify(error) + '\n' + error.stack);
|
|
25
|
-
});
|
|
26
|
-
(0, _reactBlessed.render)( /*#__PURE__*/_react.default.createElement(_alternateRenderers.Provider, {
|
|
27
|
-
store: _store.default
|
|
28
|
-
}, /*#__PURE__*/_react.default.createElement(_App.default, null)), _screen.default);
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Provider } from "react-redux/lib/alternate-renderers.js";
|
|
3
|
+
import raf from 'raf';
|
|
4
|
+
import screen from "./screen.js";
|
|
5
|
+
import store from "./store/index.js";
|
|
6
|
+
import log from "./logger.js";
|
|
7
|
+
import App from "./components/App.js";
|
|
8
|
+
export default async function startInterface() {
|
|
9
|
+
raf.polyfill();
|
|
10
|
+
process.on('uncaughtException', function (error) {
|
|
11
|
+
log.error('UNCAUGHT EXCEPTION\n' + JSON.stringify(error) + '\n' + error.stack);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Must be imported dynamically because the import seems to have
|
|
15
|
+
// side effects that block other CLI commands from exiting
|
|
16
|
+
const reactBlessed = await import('react-blessed');
|
|
17
|
+
reactBlessed.render( /*#__PURE__*/React.createElement(Provider, {
|
|
18
|
+
store: store
|
|
19
|
+
}, /*#__PURE__*/React.createElement(App, null)), screen());
|
|
20
|
+
}
|
package/dist/package.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import fs from 'node:fs/promises';
|
|
4
|
+
const packagePath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../package.json');
|
|
5
|
+
export default JSON.parse(await fs.readFile(packagePath));
|
package/dist/screen.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
handleUncaughtExceptions: false
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
screen.key(['escape', 'q', 'C-c'], () => process.exit(0));
|
|
21
|
-
var _default = screen;
|
|
22
|
-
exports.default = _default;
|
|
1
|
+
import blessed from 'blessed';
|
|
2
|
+
let screen;
|
|
3
|
+
function getScreen() {
|
|
4
|
+
if (screen === undefined) {
|
|
5
|
+
screen = blessed.screen({
|
|
6
|
+
autoPadding: true,
|
|
7
|
+
debug: true,
|
|
8
|
+
smartCSR: true,
|
|
9
|
+
title: 'Playball!',
|
|
10
|
+
handleUncaughtExceptions: false
|
|
11
|
+
});
|
|
12
|
+
screen.key(['escape', 'q', 'C-c'], () => process.exit(0));
|
|
13
|
+
}
|
|
14
|
+
return screen;
|
|
15
|
+
}
|
|
16
|
+
export default getScreen;
|