UNPKG

playball

Version:

Watch MLB games from the comfort of your terminal

77 lines (76 loc) 3.99 kB
import React, { useEffect } from 'react'; import { useSelector } from "react-redux/lib/alternate-renderers.js"; import { format, isSameDay } from 'date-fns'; import { get } from "../config.js"; import { selectTeams, selectVenue, selectStartTime, selectBoxscore, selectProbablePitchers, selectGameStatus } from "../features/games.js"; import { resetTitle, setTitle } from "../screen.js"; const formatPitcherName = pitcher => { let display = pitcher.person.fullName; const number = pitcher.jerseyNumber; if (number) { display += `, #${number}`; } return display; }; const formatTeam = (teams, probables, boxscore, homeAway) => { var _probables$homeAway; const pitcherId = (_probables$homeAway = probables[homeAway]) === null || _probables$homeAway === void 0 ? void 0 : _probables$homeAway.id; const pitcher = boxscore[homeAway].players['ID' + pitcherId]; let lines = [teams[homeAway].teamName, `(${teams[homeAway].record.wins}-${teams[homeAway].record.losses})`]; if (pitcher) { var _pitcher$seasonStats, _pitcher$seasonStats2, _pitcher$seasonStats3, _pitcher$seasonStats4; lines = lines.concat(['', formatPitcherName(pitcher), `${(_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}`, `${(_pitcher$seasonStats3 = pitcher.seasonStats) === null || _pitcher$seasonStats3 === void 0 || (_pitcher$seasonStats3 = _pitcher$seasonStats3.pitching) === null || _pitcher$seasonStats3 === void 0 ? void 0 : _pitcher$seasonStats3.era} ERA ${(_pitcher$seasonStats4 = pitcher.seasonStats) === null || _pitcher$seasonStats4 === void 0 || (_pitcher$seasonStats4 = _pitcher$seasonStats4.pitching) === null || _pitcher$seasonStats4 === void 0 ? void 0 : _pitcher$seasonStats4.strikeOuts} K`]); } else { lines = lines.concat(['TBD']); } return lines; }; function PreviewGame() { const boxscore = useSelector(selectBoxscore); const probables = useSelector(selectProbablePitchers); const startTime = useSelector(selectStartTime); const status = useSelector(selectGameStatus); const teams = useSelector(selectTeams); const venue = useSelector(selectVenue); const away = formatTeam(teams, probables, boxscore, 'away'); const home = formatTeam(teams, probables, boxscore, 'home'); const formattedStart = status.startTimeTBD ? 'Start time TBD' : format(new Date(startTime), 'MMMM d, yyy p'); useEffect(() => { if (get('title')) { const home = teams.home.abbreviation; const away = teams.away.abbreviation; // Only show the date if it's not today. const startDate = new Date(startTime); const today = new Date(); let start = format(startDate, 'p'); if (!isSameDay(startDate, today)) { start = `${format(startDate, 'MMMM d, yyy')} ${start}`; } setTitle(`${away} - ${home} @ ${start}`); return () => { resetTitle(); }; } }, [get, resetTitle, setTitle, startTime, teams]); return /*#__PURE__*/React.createElement("element", null, /*#__PURE__*/React.createElement("element", { height: "60%" }, /*#__PURE__*/React.createElement("box", { content: away.join('\n'), width: "33%-1", top: "50%", align: "center" }), /*#__PURE__*/React.createElement("box", { content: `\nvs.\n\n${formattedStart}\n${venue.name}\n${venue.location.city}, ${venue.location.stateAbbrev}`, width: "33%-1", left: "33%", top: "50%", align: "center" }), /*#__PURE__*/React.createElement("box", { content: home.join('\n'), width: "34%", top: "50%", left: "66%", align: "center" }))); } export default PreviewGame;