From 2df69f12f9a0a2a06e4dc66ecb9e9bc9a45429de Mon Sep 17 00:00:00 2001 From: Paul Mineev Date: Tue, 21 Jun 2022 23:32:29 -0700 Subject: [PATCH] minor fix for pause state, fix typing --- components/Pause.tsx | 9 ++--- components/Player.tsx | 73 ++++++++++++++++++---------------------- components/TrackInfo.tsx | 13 +++---- lib/spotify.ts | 23 +++++++++---- 4 files changed, 61 insertions(+), 57 deletions(-) diff --git a/components/Pause.tsx b/components/Pause.tsx index de4eb53..f8b1d3f 100644 --- a/components/Pause.tsx +++ b/components/Pause.tsx @@ -1,4 +1,4 @@ -import { h, Fragment } from "preact"; +import { h, Fragment } from 'preact' export default function Pause() { return ( @@ -10,8 +10,9 @@ export default function Pause() { align-items: center; box-sizing: border-box; border: 1px solid #ccc; - width: 100%; - height: 100%; + width: 22px; + height: 22px; + margin: -1px; border-radius: 50%; } .pause:before, @@ -26,5 +27,5 @@ export default function Pause() { `}
- ); + ) } diff --git a/components/Player.tsx b/components/Player.tsx index a59d9ac..c740e66 100644 --- a/components/Player.tsx +++ b/components/Player.tsx @@ -1,30 +1,21 @@ -import { Fragment, h } from "preact"; +import { h } from 'preact' -import Pause from "./Pause"; -import Cover from "./Cover"; -import Progress from "./Progress"; -import Equalizer from "./Equalizer"; -import TrackInfo from "./TrackInfo"; -import SpotifyLogo from "./SpotifyLogo"; -import { RefreshIcon } from "./RefreshIcon"; +import Pause from './Pause' +import Cover from './Cover' +import Progress from './Progress' +import Equalizer from './Equalizer' +import TrackInfo from './TrackInfo' +import SpotifyLogo from './SpotifyLogo' +import { RefreshIcon } from './RefreshIcon' +import { TrackInfo as TTrackInfo } from '../lib/spotify' -const width = 540; -const height = 52; +const width = 540 +const height = 52 -export type Props = { - track?: string; - artist?: string; - duration?: number; - progress?: number | null; - isPlaying?: boolean; - coverUrl?: string; -}; +export type Props = TTrackInfo | ({ isPlaying: false } & Partial>) -export default function Player(props: Props) { - const { track, artist, coverUrl, progress, duration } = props; - const hasTrack = track && artist; - const isPlaying = Boolean(props.isPlaying); - const hasProgress = isPlaying && typeof progress === "number" && typeof duration === "number"; +export default function Player(p: Props) { + const hasTrack = typeof p.artist === 'string' && typeof p.track === 'string' return ( -
+
- {coverUrl ? : } + {p.coverUrl ? : }
- +
- {hasTrack && ( -
- {isPlaying ? ( + {hasTrack && + (p.isPlaying ? ( +
- ) : ( +
+ ) : ( +
- )} -
- )} - {hasProgress && ( +
+ ))} + {p.isPlaying && (
- +
)}
- ); + ) } diff --git a/components/TrackInfo.tsx b/components/TrackInfo.tsx index 43616df..0415533 100644 --- a/components/TrackInfo.tsx +++ b/components/TrackInfo.tsx @@ -1,9 +1,10 @@ -import { h, Fragment } from "preact"; +import { h, Fragment } from 'preact' -export default function TrackInfo({ - track = "Not playing", - artist = "Spotify", -}) { +type Props = { + track?: string + artist?: string +} +export default function TrackInfo({ track = 'Not playing', artist = 'Spotify' }: Props) { return (