import { HiMusicNote } from 'react-icons/hi' import { truncate } from '@/utils/truncate' import { useEffect, useState } from 'react' import io from 'socket.io-client' import Image from 'next/image' import Link from 'next/link' interface SpotifyData { song?: { artist: string[] title: string url: string image: string progress: number length: number } } export const NowPlayingCard = () => { const [spotify, setSpotify] = useState({}) useEffect(() => { const socket = io('wss://ws.albert.lol') socket.on('nowPlayingData', (data) => { setSpotify(data as SpotifyData) }) return () => { socket.disconnect() } }, []) const calcProgress = () => { if (spotify.song && spotify.song.length > 0) { const progressPercentage = (spotify.song.progress / spotify.song.length) * 100 return `${progressPercentage}%` } return '0%' } return (
{spotify.song ? ( <> Song cover art
Listening to{' '} {truncate(`${spotify.song.title}`, 20)}
) : ( <>
Not listening to anything
)}
) }