import React from "react"; import classnames from "classnames"; import { getTimeObj } from "../utils"; import { TIME_MODE, MEDIA_STATUS } from "../constants"; import * as Actions from "../actionCreators"; import Character from "./Character"; import * as Selectors from "../selectors"; import "../../css/mini-time.css"; import { useTypedSelector, useActionCreator } from "../hooks"; // Sigh. When the display is blinking (say when it's paused) we need to // alternate between the actual character and the space character. Not // Possible to do that in pure 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 = () => { const status = useTypedSelector(Selectors.getMediaStatus); const duration = useTypedSelector(Selectors.getDuration); const timeElapsed = useTypedSelector(Selectors.getTimeElapsed); const timeMode = useTypedSelector(Selectors.getTimeMode); const toggle = useActionCreator(Actions.toggleTimeMode); let seconds = null; // TODO: Clean this up: If stopped, just render the background, rather than // rendering spaces twice. if (status !== MEDIA_STATUS.STOPPED && duration != null) { seconds = timeMode === TIME_MODE.ELAPSED ? timeElapsed : duration - timeElapsed; } const timeObj = getTimeObj(seconds); const showMinus = timeMode === TIME_MODE.REMAINING && status !== MEDIA_STATUS.STOPPED; return (
{showMinus ? "-" : " "} {timeObj.minutesFirstDigit} {timeObj.minutesSecondDigit} {timeObj.secondsFirstDigit} {timeObj.secondsSecondDigit}
); }; export default MiniTime;