UNPKG

playball

Version:

Watch MLB games from the comfort of your terminal

40 lines 2 kB
import React from 'react'; import { useSelector } from "react-redux/lib/alternate-renderers.js"; import { selectCurrentPlay, selectBoxscore, selectTeams } from "../features/games.js"; const getPlayerStats = (boxscore, teams, id) => { const key = 'ID' + id; const homePlayers = boxscore.home.players; if (homePlayers[key]) { return { team: teams.home, player: homePlayers[key] }; } return { team: teams.away, player: boxscore.away.players[key] }; }; function Matchup() { var _currentPlay$matchup, _currentPlay$matchup2; const boxscore = useSelector(selectBoxscore); const currentPlay = useSelector(selectCurrentPlay); const teams = useSelector(selectTeams); const pitcherId = (_currentPlay$matchup = currentPlay.matchup) === null || _currentPlay$matchup === void 0 || (_currentPlay$matchup = _currentPlay$matchup.pitcher) === null || _currentPlay$matchup === void 0 ? void 0 : _currentPlay$matchup.id; const batterId = (_currentPlay$matchup2 = currentPlay.matchup) === null || _currentPlay$matchup2 === void 0 || (_currentPlay$matchup2 = _currentPlay$matchup2.batter) === null || _currentPlay$matchup2 === void 0 ? void 0 : _currentPlay$matchup2.id; const { team: pitchTeam, player: pitcher } = getPlayerStats(boxscore, teams, pitcherId); const { team: batTeam, player: batter } = getPlayerStats(boxscore, teams, batterId); const display = `${pitchTeam.abbreviation} Pitching: ` + `{bold}${pitcher.person.fullName}{/bold} ${pitcher.stats.pitching.inningsPitched} IP, ${pitcher.stats.pitching.pitchesThrown || 0} P, ${pitcher.seasonStats.pitching.era} ERA\n` + `${batTeam.abbreviation} At Bat: ` + `{bold}${batter.person.fullName}{/bold} ${batter.stats.batting.hits}-${batter.stats.batting.atBats}, ${batter.seasonStats.batting.avg} AVG, ${batter.seasonStats.batting.homeRuns} HR`; return /*#__PURE__*/React.createElement("box", { tags: true, content: display, wrap: false }); } export default Matchup;