Skip to content

Commit 8f0afe0

Browse files
authored
Merge pull request asapzacy#38 from asapzacy/fix/nba-games-post-covid
Fix/nba games post covid
2 parents a3538f1 + 2212d5a commit 8f0afe0

File tree

18 files changed

+178
-108
lines changed

18 files changed

+178
-108
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"regenerator": true
2828
}
2929
],
30-
"@babel/plugin-syntax-dynamic-import"
30+
"@babel/plugin-syntax-dynamic-import",
31+
"@babel/plugin-proposal-optional-chaining"
3132
],
3233
"env": {
3334
"test": {

.eslintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"no-console": [2, { "allow": ["warn", "error"] }],
2626
"semi": [2, "never"],
2727
"no-extra-semi": 2,
28-
"space-before-function-paren": ["error", "never"],
2928
"react/jsx-boolean-value": [2, "always"],
3029
"react/jsx-curly-spacing": [2, "never", { "allowMultiline": false }],
3130
"react/jsx-no-literals": 2,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"@babel/core": "^7.4.5",
5151
"@babel/plugin-proposal-class-properties": "^7.4.4",
5252
"@babel/plugin-proposal-decorators": "^7.4.4",
53+
"@babel/plugin-proposal-optional-chaining": "^7.11.0",
5354
"@babel/plugin-syntax-dynamic-import": "^7.7.4",
5455
"@babel/plugin-transform-runtime": "^7.4.4",
5556
"@babel/preset-env": "^7.4.5",

server.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,31 @@ app.get('/api/mlb/scores/:dt', (req, res) => {
4141

4242
app.get('/api/nba/scores/:dt', (req, res) => {
4343
const { dt } = req.params
44-
const url = `http://data.nba.com/data/5s/json/cms/noseason/scoreboard/${dt}/games.json`
45-
const url2 = `http://data.nba.net/data/10s/prod/v2/${dt}/scoreboard.json`
44+
const gamesUrl = `http://data.nba.net/prod/v2/${dt}/scoreboard.json`
45+
const teamsUrl = `https://data.nba.net/prod/v2/2019/teams.json`
46+
4647
return axios
47-
.all([axios.get(url), axios.get(url2)])
48+
.all([axios.get(gamesUrl), axios.get(teamsUrl)])
4849
.then(
49-
axios.spread((games, standings) => {
50-
const scores = {}
51-
scores.year =
52-
games.data.sports_content.sports_meta.season_meta.season_year
53-
scores.games = games.data.sports_content.games.game.reduce(
54-
(arr, el, i) => {
55-
arr.push(Object.assign({}, el, standings.data.games[i]))
56-
return arr
57-
},
58-
[]
50+
axios.spread((games, teams) => {
51+
const nbaTeams = teams.data.league.standard.filter(
52+
team => team.isNBAFranchise === true
5953
)
54+
const scores = {}
55+
scores.year = dt.slice(0, 4)
56+
scores.games = games.data.games
57+
58+
scores.games.forEach(game => {
59+
game.vTeam = {
60+
...game.vTeam,
61+
...nbaTeams.find(team => team.teamId === game.vTeam.teamId)
62+
}
63+
game.hTeam = {
64+
...game.hTeam,
65+
...nbaTeams.find(team => team.teamId === game.hTeam.teamId)
66+
}
67+
})
68+
6069
res.send(scores)
6170
})
6271
)
@@ -65,7 +74,7 @@ app.get('/api/nba/scores/:dt', (req, res) => {
6574

6675
app.get('/api/nba/scores/:dt/details/:id', (req, res) => {
6776
const { dt, id } = req.params
68-
const url = `http://data.nba.com/data/10s/json/cms/noseason/game/${dt}/${id}/boxscore.json`
77+
const url = `http://data.nba.com/prod/v1/${dt}/${id}_boxscore.json`
6978
return axios
7079
.get(url)
7180
.then(scores => res.send(scores.data))

src/components/BoxScore/props.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ export const mlbBoxScoreProps = (game, league) => {
2727
// nba box score props --> BoxScore component
2828
export const nbaBoxScoreProps = (game, league) => {
2929
const inGame = game.period.current
30-
const size = Number(game.period_time.period_value)
30+
const size = Number(game.period.current)
3131
return {
32-
awayTeam: shortenTeamName(game.visitor.nickname),
33-
homeTeam: shortenTeamName(game.home.nickname),
32+
awayTeam: shortenTeamName(game.vTeam.nickname),
33+
homeTeam: shortenTeamName(game.hTeam.nickname),
3434
awayScore: inGame ? game.vTeam.score : '',
3535
homeScore: inGame ? game.hTeam.score : '',
3636
linescore: {
@@ -39,7 +39,7 @@ export const nbaBoxScoreProps = (game, league) => {
3939
},
4040
periods: 4,
4141
totalPeriods: size,
42-
overtimes: game.period_time.period_value > 4 ? size - 4 : 0,
42+
overtimes: game.period.current > 4 ? size - 4 : 0,
4343
league
4444
}
4545
}

src/components/Details/Details.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const MlbDetails = ({
4343
panels,
4444
activePanel,
4545
switchPanel,
46-
lastUpdated
46+
lastUpdatedStr
4747
}) => (
4848
<section className={s.container}>
4949
<Matchup {...mlbMatchupProps(game, date)} />
@@ -57,7 +57,7 @@ const MlbDetails = ({
5757
<Diamond {...mlbDiamondProps(game)} />
5858
</BoxScore>
5959
)}
60-
<UpdateTime lastUpdated={lastUpdated} />
60+
<UpdateTime lastUpdatedStr={lastUpdatedStr} />
6161
</section>
6262
)
6363

@@ -68,7 +68,7 @@ const NbaDetails = ({
6868
panels,
6969
activePanel,
7070
switchPanel,
71-
lastUpdated
71+
lastUpdatedStr
7272
}) => (
7373
<section className={s.container}>
7474
<Matchup {...nbaMatchupProps(game, date)} />
@@ -81,24 +81,24 @@ const NbaDetails = ({
8181
<BoxScore {...nbaBoxScoreProps(game, league)} />
8282
)}
8383
{activePanel === 'team stats' && <Stats {...nbaStatsProps(game)} />}
84-
<UpdateTime lastUpdated={lastUpdated} />
84+
<UpdateTime lastUpdatedStr={lastUpdatedStr} />
8585
</section>
8686
)
8787

88-
const NflDetails = ({ lastUpdated }) => (
88+
const NflDetails = ({ lastUpdatedStr }) => (
8989
<section className={s.container}>
9090
<br />
9191
<br />
9292
<br />
9393
<br />
94-
<UpdateTime lastUpdated={lastUpdated} />
94+
<UpdateTime lastUpdatedStr={lastUpdatedStr} />
9595
</section>
9696
)
9797

98-
const NhlDetails = ({ game, date, league, lastUpdated }) => (
98+
const NhlDetails = ({ game, date, league, lastUpdatedStr }) => (
9999
<section className={s.container}>
100100
<Matchup {...nhlMatchupProps(game, date)} />
101101
<BoxScore {...nhlBoxScoreProps(game, league)} />
102-
<UpdateTime lastUpdated={lastUpdated} />
102+
<UpdateTime lastUpdatedStr={lastUpdatedStr} />
103103
</section>
104104
)

src/components/Game/Game.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const NbaGame = ({
4848
game,
4949
date,
5050
league,
51-
lastUpdated,
51+
lastUpdatedStr,
5252
isExpanded,
5353
showDetails,
5454
isHovered,
@@ -88,7 +88,7 @@ const NbaGame = ({
8888
game={game}
8989
date={date}
9090
league={league}
91-
lastUpdated={lastUpdated}
91+
lastUpdatedStr={lastUpdatedStr}
9292
/>
9393
)}
9494
</VelocityTransitionGroup>
@@ -99,7 +99,7 @@ const NflGame = ({
9999
game,
100100
date,
101101
league,
102-
lastUpdated,
102+
lastUpdatedStr,
103103
isExpanded,
104104
showDetails,
105105
isHovered,
@@ -139,7 +139,7 @@ const NflGame = ({
139139
game={game}
140140
date={date}
141141
league={league}
142-
lastUpdated={lastUpdated}
142+
lastUpdatedStr={lastUpdatedStr}
143143
/>
144144
)}
145145
</VelocityTransitionGroup>
@@ -150,7 +150,7 @@ const MlbGame = ({
150150
game,
151151
date,
152152
league,
153-
lastUpdated,
153+
lastUpdatedStr,
154154
isExpanded,
155155
showDetails,
156156
isHovered,
@@ -190,7 +190,7 @@ const MlbGame = ({
190190
game={game}
191191
date={date}
192192
league={league}
193-
lastUpdated={lastUpdated}
193+
lastUpdatedStr={lastUpdatedStr}
194194
/>
195195
)}
196196
</VelocityTransitionGroup>
@@ -201,7 +201,7 @@ const NhlGame = ({
201201
game,
202202
date,
203203
league,
204-
lastUpdated,
204+
lastUpdatedStr,
205205
isExpanded,
206206
showDetails,
207207
isHovered,
@@ -241,7 +241,7 @@ const NhlGame = ({
241241
game={game}
242242
date={date}
243243
league={league}
244-
lastUpdated={lastUpdated}
244+
lastUpdatedStr={lastUpdatedStr}
245245
/>
246246
)}
247247
</VelocityTransitionGroup>

src/components/GameState/props.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,20 @@ export const mlbGameStateProps = game => {
5656
// nba game state props --> GameState component
5757
export const nbaGameStateProps = game => {
5858
const isPlayoffs = Boolean(game.playoffs)
59+
5960
return {
60-
gameState: Number(game.period_time.game_status) - 1,
61-
status: game.period_time.period_status,
61+
gameState: Number(game.statusNum) - 1,
62+
status: game.statusNum === 3 ? 'Final' : '', // game.period_time.period_status
6263
time: `${formatTimezone(game.startTimeUTC)} ET`,
6364
periods: 4,
64-
currentPeriod: game.period_time.period_value,
65-
currentTime: game.period.isEndOfPeriod
66-
? 'END'
67-
: game.period_time.game_clock,
68-
isHalfTime:
69-
game.period.isHalftime || game.period_time.period_status === 'Halftime',
70-
totalPeriods: game.period_time.period_value,
65+
currentPeriod: game.period.current,
66+
currentTime: game.period.isEndOfPeriod ? 'END' : game.clock,
67+
isHalfTime: game.period.isHalftime,
68+
totalPeriods: game.period.maxRegular,
7169
overtime:
72-
game.period_time.period_value > 4
73-
? game.period_time.period_value > 5
74-
? `${game.period_time.period_value - 4}OT`
70+
game.period.current > 4
71+
? game.period.current > 5
72+
? `${game.period.current - 4}OT`
7573
: 'OT'
7674
: '',
7775
playoffs: isPlayoffs

src/components/League/League.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const League = ({
1111
year,
1212
date,
1313
today,
14-
league
14+
league,
15+
lastUpdated
1516
}) => (
1617
<div className={s.container}>
1718
{isLoading ? (
@@ -24,6 +25,7 @@ const League = ({
2425
today={today}
2526
league={league}
2627
isError={isError}
28+
lastUpdated={lastUpdated}
2729
/>
2830
) : (
2931
<NotFound />

src/components/Matchup/props.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ export const mlbMatchupProps = (game, date) => ({
99

1010
// nba matchup props --> Matchup component
1111
export const nbaMatchupProps = (game, date) => ({
12-
awayTeam: game.visitor.nickname,
13-
homeTeam: game.home.nickname,
14-
location: `${game.city}, ${game.state}.`,
12+
awayTeam: game.vTeam.nickname,
13+
homeTeam: game.hTeam.nickname,
14+
location: `${game.arena.city}, ${game.arena.stateAbbr}.`,
1515
venue: game.arena.name,
1616
date
1717
})

0 commit comments

Comments
 (0)