From adbcca00de4ce9c55db8e8a02dbad7bd5472c5c7 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Sun, 7 Dec 2025 16:48:22 -0800 Subject: [PATCH] fix sidebar playlist handlers (#1318) --- .../player/context/player-context.tsx | 9 +- .../components/sidebar-playlist-list.tsx | 143 ++++++++++-------- 2 files changed, 88 insertions(+), 64 deletions(-) diff --git a/src/renderer/features/player/context/player-context.tsx b/src/renderer/features/player/context/player-context.tsx index 4ccaa7d9f..3845b37bb 100644 --- a/src/renderer/features/player/context/player-context.tsx +++ b/src/renderer/features/player/context/player-context.tsx @@ -289,7 +289,14 @@ export const PlayerProvider = ({ children }: { children: React.ReactNode }) => { toast.hide(toastId); } - const sortedSongs = sortSongsByFetchedOrder(songs, id, itemType); + let sortedSongs: Song[] = []; + + // Playlists should use the native order of the playlist + if (itemType === LibraryItem.PLAYLIST) { + sortedSongs = songs; + } else { + sortedSongs = sortSongsByFetchedOrder(songs, id, itemType); + } const filters = useSettingsStore.getState().playback.filters; const filteredSongs = filterSongsByPlayerFilters(sortedSongs, filters); diff --git a/src/renderer/features/sidebar/components/sidebar-playlist-list.tsx b/src/renderer/features/sidebar/components/sidebar-playlist-list.tsx index 45c412aac..a276177ee 100644 --- a/src/renderer/features/sidebar/components/sidebar-playlist-list.tsx +++ b/src/renderer/features/sidebar/components/sidebar-playlist-list.tsx @@ -12,10 +12,15 @@ import { ContextMenuController } from '/@/renderer/features/context-menu/context import { usePlayer } from '/@/renderer/features/player/context/player-context'; import { playlistsQueries } from '/@/renderer/features/playlists/api/playlists-api'; import { CreatePlaylistForm } from '/@/renderer/features/playlists/components/create-playlist-form'; +import { + LONG_PRESS_PLAY_BEHAVIOR, + PlayTooltip, +} from '/@/renderer/features/shared/components/play-button-group'; +import { usePlayButtonClick } from '/@/renderer/features/shared/hooks/use-play-button-click'; import { SidebarItem } from '/@/renderer/features/sidebar/components/sidebar-item'; import { useDragDrop } from '/@/renderer/hooks/use-drag-drop'; import { AppRoute } from '/@/renderer/router/routes'; -import { useCurrentServer } from '/@/renderer/store'; +import { useCurrentServer, useCurrentServerId } from '/@/renderer/store'; import { Accordion } from '/@/shared/components/accordion/accordion'; import { ActionIcon, ActionIconGroup } from '/@/shared/components/action-icon/action-icon'; import { ButtonProps } from '/@/shared/components/button/button'; @@ -36,11 +41,10 @@ interface PlaylistRowButtonProps extends Omit, item: Playlist) => void; - onPlay: (id: string, playType: Play) => void; to: string; } -const PlaylistRowButton = ({ item, name, onContextMenu, onPlay, to }: PlaylistRowButtonProps) => { +const PlaylistRowButton = ({ item, name, onContextMenu, to }: PlaylistRowButtonProps) => { const url = { pathname: generatePath(AppRoute.PLAYLISTS_DETAIL_SONGS, { playlistId: to }), state: { item }, @@ -143,6 +147,16 @@ const PlaylistRowButton = ({ item, name, onContextMenu, onPlay, to }: PlaylistRo isEnabled: true, }); + const player = usePlayer(); + const serverId = useCurrentServerId(); + + const handlePlay = useCallback( + (id: string, type: Play) => { + player.addToQueueByFetch(serverId, [id], LibraryItem.PLAYLIST, type); + }, + [player, serverId], + ); + return (
{name} - {isHovered && } + {isHovered && }
); }; @@ -177,66 +191,71 @@ const RowControls = ({ id: string; onPlay: (id: string, playType: Play) => void; }) => { - const { t } = useTranslation(); + const handlePlayNext = usePlayButtonClick({ + onClick: () => { + onPlay(id, Play.NEXT); + }, + onLongPress: () => { + onPlay(id, LONG_PRESS_PLAY_BEHAVIOR[Play.NEXT]); + }, + }); + + const handlePlayNow = usePlayButtonClick({ + onClick: () => { + onPlay(id, Play.NOW); + }, + onLongPress: () => { + onPlay(id, LONG_PRESS_PLAY_BEHAVIOR[Play.NOW]); + }, + }); + + const handlePlayLast = usePlayButtonClick({ + onClick: () => { + onPlay(id, Play.LAST); + }, + onLongPress: () => { + onPlay(id, LONG_PRESS_PLAY_BEHAVIOR[Play.LAST]); + }, + }); return ( - { - onPlay(id, Play.NOW); - }} - size="xs" - tooltip={{ - label: t('player.play', { postProcess: 'sentenceCase' }), - }} - variant="subtle" - /> - { - onPlay(id, Play.SHUFFLE); - }} - size="xs" - tooltip={{ - label: t('player.shuffle', { postProcess: 'sentenceCase' }), - }} - variant="subtle" - /> - { - onPlay(id, Play.LAST); - }} - size="xs" - tooltip={{ - label: t('player.addLast', { postProcess: 'sentenceCase' }), - }} - variant="subtle" - /> - { - onPlay(id, Play.NEXT); - }} - size="xs" - tooltip={{ - label: t('player.addNext', { postProcess: 'sentenceCase' }), - }} - variant="subtle" - /> + + + + + + + + + ); }; @@ -353,7 +372,6 @@ export const SidebarPlaylistList = () => { key={index} name={item.name} onContextMenu={handleContextMenu} - onPlay={handlePlayPlaylist} to={item.id} /> ))} @@ -438,7 +456,6 @@ export const SidebarSharedPlaylistList = () => { key={index} name={item.name} onContextMenu={handleContextMenu} - onPlay={handlePlayPlaylist} to={item.id} /> ))}