UNPKG

playball

Version:

Watch MLB games from the comfort of your terminal

90 lines 4.34 kB
import React from 'react'; import { useSelector } from "react-redux/lib/alternate-renderers.js"; import { selectLineScore, selectTeams, selectDecisions, selectBoxscore, selectGameStatus } from "../features/games.js"; import LineScore from "./LineScore.js"; const getPlayer = (id, boxscore) => { var _boxscore$home, _boxscore$away; 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]; if (homePlayer !== undefined) { return homePlayer; } return (_boxscore$away = boxscore.away) === null || _boxscore$away === void 0 ? void 0 : _boxscore$away.players['ID' + id]; }; const formatDecisions = (decisions, boxscore) => { if (!decisions) { return ''; } const content = []; const winner = decisions.winner; if (winner) { var _pitcher$seasonStats, _pitcher$seasonStats2; const pitcher = getPlayer(winner.id, boxscore); 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})`); } const loser = decisions.loser; if (loser) { var _pitcher$seasonStats3, _pitcher$seasonStats4; const pitcher = getPlayer(loser.id, boxscore); 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})`); } const save = decisions.save; if (save) { var _pitcher$seasonStats5; const pitcher = getPlayer(save.id, boxscore); content.push(`Save: ${pitcher.person.fullName} (${(_pitcher$seasonStats5 = pitcher.seasonStats) === null || _pitcher$seasonStats5 === void 0 ? void 0 : _pitcher$seasonStats5.pitching.saves})`); } return content.join('\n'); }; const formatScore = (status, linescore) => { let display = ''; if (status.detailedState === 'Postponed') { display = status.detailedState; if (status.reason) { display += '\n' + status.reason; } } else { display = `\n${linescore.teams.away.runs} - ${linescore.teams.home.runs}`; } return display; }; function FinishedGame() { const boxscore = useSelector(selectBoxscore); const decisions = useSelector(selectDecisions); const linescore = useSelector(selectLineScore); const status = useSelector(selectGameStatus); const teams = useSelector(selectTeams); const awayTeam = `${teams.away.teamName}\n(${teams.away.record.wins}-${teams.away.record.losses})`; const homeTeam = `${teams.home.teamName}\n(${teams.home.record.wins}-${teams.home.record.losses})`; return /*#__PURE__*/React.createElement("element", null, /*#__PURE__*/React.createElement("element", { height: "60%" }, /*#__PURE__*/React.createElement("box", { content: awayTeam, width: "33%-1", top: "50%", align: "center" }), /*#__PURE__*/React.createElement("box", { content: formatScore(status, linescore), width: "33%-1", left: "33%", top: "50%", align: "center" }), /*#__PURE__*/React.createElement("box", { content: homeTeam, width: "34%", top: "50%", left: "66%", align: "center" })), /*#__PURE__*/React.createElement("element", { top: "60%+1", height: 3 }, /*#__PURE__*/React.createElement(LineScore, { align: "center", final: true })), /*#__PURE__*/React.createElement("element", { top: "60%+5", left: "50%-20" }, /*#__PURE__*/React.createElement("box", { content: formatDecisions(decisions, boxscore) }))); } export default FinishedGame;