import React from "react"; import { connect } from "react-redux"; import classnames from "classnames"; import { getTimeObj } from "../utils"; import { TOGGLE_TIME_MODE } from "../actionTypes"; import Character from "./Character"; import "../../css/mini-time.css"; // Sigh. When he display is blinking (say when it's paused) we need to // alternate between the actual caracter and the space character. Not // Possible to that in purce CSS with the background being dynamically generated. // All "space" characters is also how Winamp renders no content. const Background = () => [1, 7, 12, 20, 25].map((left, i) => ( )); const MiniTime = props => { let seconds = null; // TODO: Clean this up: If stopped, just render the background, rather than // rendering spaces twice. if (props.status !== "STOPPED") { seconds = props.timeMode === "ELAPSED" ? props.timeElapsed : props.length - props.timeElapsed; } const timeObj = getTimeObj(seconds); const showMinus = props.timeMode === "REMAINING" && props.status !== "STOPPED"; return (
{showMinus ? "-" : " "} {timeObj.minutesFirstDigit} {timeObj.minutesSecondDigit} {timeObj.secondsFirstDigit} {timeObj.secondsSecondDigit}
); }; const mapDispatchToProps = { toggle: () => ({ type: TOGGLE_TIME_MODE }) }; export default connect(state => state.media, mapDispatchToProps)(MiniTime);