import styled from "@emotion/styled"; import { Link as DefaultLink } from "@tanstack/react-router"; import { ProgressBar } from "baseui/progress-bar"; import { LabelSmall } from "baseui/typography"; import { useRef } from "react"; import { useTimeFormat } from "../../hooks/useFormat"; import Equalizer from "../Icons/Equalizer"; import Heart from "../Icons/Heart"; import HeartOutline from "../Icons/HeartOutline"; import Next from "../Icons/Next"; import Pause from "../Icons/Pause"; import Play from "../Icons/Play"; import Playlist from "../Icons/Playlist"; import Previous from "../Icons/Previous"; import Speaker from "../Icons/Speaker"; import { Button, Controls, LikeButton, MainWrapper, NextButton, PlayButton, PreviousButton, ProgressbarContainer, RightActions, styles, } from "./styles"; const Container = styled.div` position: fixed; bottom: 0; z-index: 1; align-items: center; display: flex; height: 128px; `; const MiniPlayerWrapper = styled.div` padding: 24px; `; const MiniPlayer = styled.div` background-color: white; width: 1120px; height: 80px; padding: 16px; border-radius: 16px; box-shadow: 0px 0px 24px rgba(19, 19, 19, 0.08); display: flex; flex-direction: row; align-items: center; @media (max-width: 1120px) { width: 100vw; } `; const Cover = styled.img` width: 54px; height: 54px; margin-right: 16px; border-radius: 5px; `; const Link = styled(DefaultLink)` color: inherit; text-decoration: none; &:hover { text-decoration: underline; } `; export type StickyPlayerProps = { nowPlaying?: { title: string; artist: string; artistUri: string; songUri: string; albumUri: string; duration: number; progress: number; albumArt?: string; liked: boolean; sha256: string; } | null; onPlay: () => void; onPause: () => void; onPrevious: () => void; onNext: () => void; onSpeaker: () => void; onEqualizer: () => void; onPlaylist: () => void; onSeek: (position: number) => void; onLike: (id: string) => void; onDislike: (id: string) => void; isPlaying: boolean; }; function StickyPlayer(props: StickyPlayerProps) { const { nowPlaying, onPlay, onPause, onPrevious, onNext, onSpeaker, onEqualizer, onPlaylist, onSeek, onLike, onDislike, isPlaying, } = props; const progressbarRef = useRef(null); const { formatTime } = useTimeFormat(); // eslint-disable-next-line @typescript-eslint/no-explicit-any const handleSeek = (e: any) => { if (progressbarRef.current) { const rect = progressbarRef.current.getBoundingClientRect(); const x = e.clientX - rect.left < 0 ? 0 : e.clientX - rect.left; const width = rect.width; const percentage = (x / width) * 100; const time = (percentage / 100) * nowPlaying!.duration; onSeek(Math.floor(time)); } }; if (!nowPlaying) { return <>; } return ( {nowPlaying?.albumUri && ( )} {!nowPlaying?.albumUri && ( )}
{!!nowPlaying?.songUri && ( {nowPlaying?.title} )} {!nowPlaying?.songUri && (
{nowPlaying?.title}
)}
{!!nowPlaying?.artistUri && ( {nowPlaying?.artist} )} {!nowPlaying?.artistUri && (
{nowPlaying?.artist}
)}
{ if (nowPlaying?.liked) { onDislike(nowPlaying!.songUri); return; } onLike(nowPlaying!.songUri); }} > {nowPlaying?.liked && } {!nowPlaying?.liked && }
{formatTime(nowPlaying?.progress || 0)}
{!isPlaying && (
)} {isPlaying && ( )}
{formatTime(nowPlaying?.duration || 0)}
); } export default StickyPlayer;