import { useState } from "react"; import { formatMMSS } from "../../utils/time"; import { CharArray } from "../../utils/string"; import { CHAR_HEIGHT, CHAR_WIDTH } from "../Kitty"; import { type InnerKittyProps, useKitty } from "../../context/KittyContext"; export const SpotifyPlayer = (props: { title: string; artist: string; album: string; duration: number; played: number; onTogglePause: (state: boolean) => void; }) => { const kitty = useKitty(); return (
{kitty && }
); }; const InnerSpotifyPlayer = (props: InnerKittyProps) => { const [paused, setPaused] = useState(false); const fillSize = Math.round( (props.played / props.duration) * (props.cols - 2), ); const emptySize = props.cols - 2 - fillSize; const timeString = `${formatMMSS(props.played)}/${formatMMSS(props.duration)}`; const timeStringLeft = Math.round( (props.cols - 2) / 2 - timeString.length / 2, ); const fill = new CharArray(" ", fillSize) .write(timeStringLeft, timeString) .toString(); const empty = new CharArray(" ", emptySize) .write(timeStringLeft - fillSize, timeString) .toString(); const handleTogglePause = () => { setPaused(!paused); props.onTogglePause(!paused); }; return ( <> {/* title */} Playback {/* border right */} {"│\n".repeat(props.rows - 2)} {/* borer left */} {"│\n".repeat(props.rows - 2)} {/* border top */} {"─".repeat(props.cols - 2 - 8)} {/* border bottom */} {"─".repeat(props.cols - 2)} {/* body */}
{paused ? "\udb81\udc0a " : "\udb80\udfe4 "} {props.title} · {props.artist}
{props.album}
{fill} {empty}

); };