From 93482ac2a5f7a073f505ba130a3074b97e6da6ca Mon Sep 17 00:00:00 2001 From: V Date: Tue, 4 Jul 2023 17:53:17 +0200 Subject: [PATCH] SpotifyControls: improve open in app capabilities & styles --- .../spotifyControls/PlayerComponent.tsx | 35 ++++++++++--------- src/plugins/spotifyControls/spotifyStyles.css | 4 +-- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/plugins/spotifyControls/PlayerComponent.tsx b/src/plugins/spotifyControls/PlayerComponent.tsx index c0ba0fe4..43c499ab 100644 --- a/src/plugins/spotifyControls/PlayerComponent.tsx +++ b/src/plugins/spotifyControls/PlayerComponent.tsx @@ -21,7 +21,6 @@ import "./spotifyStyles.css"; import ErrorBoundary from "@components/ErrorBoundary"; import { Flex } from "@components/Flex"; import { ImageIcon, LinkIcon, OpenExternalIcon } from "@components/Icons"; -import { Link } from "@components/Link"; import { debounce } from "@utils/debounce"; import { openImageModal } from "@utils/discord"; import { classes, copyWithToast } from "@utils/misc"; @@ -254,6 +253,16 @@ function AlbumContextMenu({ track }: { track: Track; }) { ); } +function makeLinkProps(name: string, condition: unknown, path: string) { + if (!condition) return {}; + + return { + role: "link", + onClick: () => SpotifyStore.openExternal(path), + onContextMenu: makeContextMenu(name, path) + } satisfies React.HTMLAttributes; +} + function Info({ track }: { track: Track; }) { const img = track?.album?.image; @@ -289,12 +298,8 @@ function Info({ track }: { track: Track; }) { variant="text-sm/semibold" id={cl("song-title")} className={cl("ellipoverflow")} - role={track.id ? "link" : undefined} title={track.name} - onClick={track.id ? () => { - SpotifyStore.openExternal(`/track/${track.id}`); - } : void 0} - onContextMenu={track.id ? makeContextMenu("Song", `/track/${track.id}`) : void 0} + {...makeLinkProps("Song", track.id, `/track/${track.id}`)} > {track.name} @@ -303,16 +308,14 @@ function Info({ track }: { track: Track; }) { by  {track.artists.map((a, i) => ( - {a.name} - + {i !== track.artists.length - 1 && {", "}} ))} @@ -321,17 +324,15 @@ function Info({ track }: { track: Track; }) { {track.album.name && ( on  - {track.album.name} - + )} diff --git a/src/plugins/spotifyControls/spotifyStyles.css b/src/plugins/spotifyControls/spotifyStyles.css index 008f34e2..a9b98516 100644 --- a/src/plugins/spotifyControls/spotifyStyles.css +++ b/src/plugins/spotifyControls/spotifyStyles.css @@ -131,8 +131,8 @@ color: var(--header-secondary); } -.vc-spotify-artist:hover, -#vc-spotify-album-title:hover, +.vc-spotify-artist[role="link"]:hover, +#vc-spotify-album-title[role="link"]:hover, #vc-spotify-song-title[role="link"]:hover { text-decoration: underline; cursor: pointer;