From 2e0364444b6e9a56b55d8ab4e979902d60a8a168 Mon Sep 17 00:00:00 2001 From: r-freeman Date: Fri, 6 Jan 2023 23:16:19 +0000 Subject: [PATCH] Refactored SpotifyPlayer --- src/components/SpotifyPlayer.jsx | 70 +++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/src/components/SpotifyPlayer.jsx b/src/components/SpotifyPlayer.jsx index 293da81..fce1960 100644 --- a/src/components/SpotifyPlayer.jsx +++ b/src/components/SpotifyPlayer.jsx @@ -85,34 +85,64 @@ function usePlayerState(path, options) { } } -function Song({artist, title, songUrl, album, albumImageUrl, isPlaying}) { +function Song({as: Component = 'div', artist, title, songUrl, album, albumImageUrl, isPlaying}) { return ( -
+ {isPlaying && } - {album}
-

- - {title} - -

-

{artist}

+ +
-
+ ) } -function SongSkeleton() { +Song.Album = function SongAlbum({album, albumImageUrl}) { return ( -
+ {album} + ) +} + +Song.Title = function SongTitle({as: Component = 'h2', title, songUrl, className}) { + return ( + + + {title} + + + ) +} + +Song.Artist = function SongArtist({as: Component = 'p', artist}) { + return ( + + {artist} + + ) +} + +Song.Skeleton = function SongSkeleton({as: Component = 'div'}) { + return ( +
@@ -120,7 +150,7 @@ function SongSkeleton() {

-
+ ) } @@ -138,7 +168,7 @@ function LastPlayed() { return ( <> {isLoading - ? + ? : song?.title && } @@ -154,7 +184,7 @@ export function SpotifyPlayer() { return (
{isLoading - ? + ? : song?.isPlaying ? :