diff --git a/src/components/SpotifyCard.tsx b/src/components/SpotifyCard.tsx index d6b3529..f437e32 100644 --- a/src/components/SpotifyCard.tsx +++ b/src/components/SpotifyCard.tsx @@ -6,18 +6,17 @@ 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 - } + is_playing?: boolean + title: string + artists: { name: string[] } + album: { image: string } + url: string + progress: number + duration: number } export const NowPlayingCard = () => { - const [spotify, setSpotify] = useState({}) + const [spotify, setSpotify] = useState() useEffect(() => { const socket = io('wss://ws.albert.lol') @@ -31,18 +30,9 @@ export const NowPlayingCard = () => { } }, []) - const Progress = () => { - if (spotify.song && spotify.song.length > 0) { - const progressPercentage = - (spotify.song.progress / spotify.song.length) * 100 - return `${progressPercentage}%` - } - return '0%' - } - return (
- {spotify.song ? ( + {spotify?.is_playing ? ( <> { quality={100} className='select-none rounded-md' draggable={false} - src={spotify.song.image} + src={spotify.album.image} />
- +

- {truncate(`${spotify.song.title}`, 30)} + {truncate(`${spotify.title}`, 30)}

{truncate( - spotify.song.artist.map((artist) => artist).join(', '), + spotify.artists?.name.map((artist) => artist).join(', '), 30 )}

@@ -70,7 +60,9 @@ export const NowPlayingCard = () => {
diff --git a/src/pages/api/spotify.ts b/src/pages/api/spotify.ts index b9cdf5e..e8de1d7 100644 --- a/src/pages/api/spotify.ts +++ b/src/pages/api/spotify.ts @@ -21,21 +21,26 @@ export default async function handler( ) { try { const song = await spotify.getCurrentSong() - if (!song || !song.isPlaying) { + if (!song.is_playing) { return res.status(200).json({ - nowplaying: false, + is_playing: false, }) } res.status(200).json({ - nowplaying: true, - song: { - artist: song.artists.name, - title: song.title, - url: song.url, + is_playing: true, + album: { + name: song.album.name, image: song.album.image, - progress: song.progress, - length: song.length, + release: song.album.release, }, + artists: { + name: song.artists.name, + url: song.artists.url, + }, + url: song.url, + title: song.title, + progress: song.progress, + duration: song.duration, }) } catch (error) { res diff --git a/src/utils/result.ts b/src/utils/result.ts index c3c45e8..eb471ed 100644 --- a/src/utils/result.ts +++ b/src/utils/result.ts @@ -10,7 +10,7 @@ export class SongResultMap { const { item } = result return { - progress: result.progress_ms, + is_playing: result.is_playing, title: item.name, album: { name: item.album.name, @@ -22,8 +22,8 @@ export class SongResultMap { url: item.artists.map((x: Artist) => x.external_urls.spotify), }, url: item.external_urls.spotify, - length: item.duration_ms, - isPlaying: result.is_playing, + progress: result.progress_ms, + duration: item.duration_ms, } } } diff --git a/src/utils/type.ts b/src/utils/type.ts index fbd8c91..207ea08 100644 --- a/src/utils/type.ts +++ b/src/utils/type.ts @@ -11,6 +11,6 @@ export type SongResult = { } url: string title: string - length: number - isPlaying: boolean + duration: number + is_playing: boolean }