From 3626095d97d435fca47ea75eb0292292052494c5 Mon Sep 17 00:00:00 2001 From: "L.Ryland" <41134883+L-Ryland@users.noreply.github.com> Date: Tue, 12 Apr 2022 22:18:37 +0800 Subject: [PATCH] feat: add playing status on sidebar playlists (#1517) * udpate playing status on sidebar playlists * update player mode logic & delete unused codes * change sidebar svg to volume-half * format code and relevant optimizations * justify-between * change object visit mode to dot. * delete duplited `flex` class * add playlist id check in case playlist id conflicts with album. --- src/renderer/components/Lyric/Player.tsx | 3 +- src/renderer/components/Sidebar.tsx | 32 ++++++++++------ src/renderer/components/SvgIcon.tsx | 48 +++++++++++++++++++++++- src/renderer/utils/player.ts | 6 ++- 4 files changed, 73 insertions(+), 16 deletions(-) diff --git a/src/renderer/components/Lyric/Player.tsx b/src/renderer/components/Lyric/Player.tsx index a7ec88f..2f60544 100644 --- a/src/renderer/components/Lyric/Player.tsx +++ b/src/renderer/components/Lyric/Player.tsx @@ -30,7 +30,8 @@ const PlayingTrack = () => { [playerSnapshot.trackListSource] ) - const hasListSource = playerSnapshot.mode !== PlayerMode.FM && trackListSource?.type + const hasListSource = + playerSnapshot.mode !== PlayerMode.FM && trackListSource?.type const toTrackListSource = () => { if (!hasListSource) return diff --git a/src/renderer/components/Sidebar.tsx b/src/renderer/components/Sidebar.tsx index 1b27ab7..6196f04 100644 --- a/src/renderer/components/Sidebar.tsx +++ b/src/renderer/components/Sidebar.tsx @@ -3,17 +3,10 @@ import SvgIcon from './SvgIcon' import useUserPlaylists from '@/renderer/hooks/useUserPlaylists' import { scrollToTop } from '@/renderer/utils/common' import { prefetchPlaylist } from '@/renderer/hooks/usePlaylist' +import { player } from '@/renderer/store' +import { Mode, TrackListSourceType } from '@/renderer/utils/player' -interface Tab { - name: string - icon: string - route: string -} -interface PrimaryTab extends Tab { - icon: string -} - -const primaryTabs: PrimaryTab[] = [ +const primaryTabs = [ { name: '主页', icon: 'home', @@ -29,7 +22,7 @@ const primaryTabs: PrimaryTab[] = [ icon: 'music-library', route: '/library', }, -] +] as const const PrimaryTabs = () => { return ( @@ -62,6 +55,16 @@ const PrimaryTabs = () => { const Playlists = () => { const { data: playlists } = useUserPlaylists() + const playerSnapshot = useSnapshot(player) + const currentPlaylistID = useMemo( + () => playerSnapshot.trackListSource?.id, + [playerSnapshot.trackListSource] + ) + const playlistMode = useMemo( + () => playerSnapshot.trackListSource?.type, + [playerSnapshot.trackListSource] + ) + const mode = useMemo(() => playerSnapshot.mode, [playerSnapshot.mode]) return (
@@ -73,12 +76,17 @@ const Playlists = () => { to={`/playlist/${playlist.id}`} className={({ isActive }: { isActive: boolean }) => classNames( - 'btn-hover-animation line-clamp-1 my-px mx-3 flex cursor-default items-center rounded-lg px-3 py-[0.38rem] text-sm text-black opacity-70 transition-colors duration-200 after:scale-[0.97] after:bg-black/[.06] dark:text-white dark:after:bg-white/20', + 'btn-hover-animation line-clamp-1 my-px mx-3 flex cursor-default items-center justify-between rounded-lg px-3 py-[0.38rem] text-sm text-black opacity-70 transition-colors duration-200 after:scale-[0.97] after:bg-black/[.06] dark:text-white dark:after:bg-white/20', isActive && 'after:scale-100 after:opacity-100' ) } > {playlist.name} + {playlistMode === TrackListSourceType.PLAYLIST && + mode === Mode.PLAYLIST && + currentPlaylistID === playlist.id && ( + + )} ))}
diff --git a/src/renderer/components/SvgIcon.tsx b/src/renderer/components/SvgIcon.tsx index 6f72b72..4552fdf 100644 --- a/src/renderer/components/SvgIcon.tsx +++ b/src/renderer/components/SvgIcon.tsx @@ -1,4 +1,50 @@ -const SvgIcon = ({ name, className }: { name: string; className?: string }) => { +type SvgName = + | 'back' + | 'dislike' + | 'dj' + | 'email' + | 'explicit' + | 'eye-off' + | 'eye' + | 'fm' + | 'forward' + | 'heart-outline' + | 'heart' + | 'home' + | 'lock' + | 'lyrics' + | 'more' + | 'music-library' + | 'music-note' + | 'next' + | 'pause' + | 'phone' + | 'play-fill' + | 'play' + | 'playlist' + | 'podcast' + | 'previous' + | 'qrcode' + | 'repeat' + | 'repeat-1' + | 'search' + | 'settings' + | 'shuffle' + | 'user' + | 'volume-half' + | 'volume-mute' + | 'volume' + | 'windows-close' + | 'windows-maximize' + | 'windows-un-maximize' + | 'x' +const SvgIcon = ({ + name, + className, +}: { + name: SvgName + className?: string +}) => { const symbolId = `#icon-${name}` return (