From b9b39caf86dd08f24a1b5fdfe06eea321979b812 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Sun, 30 Nov 2025 17:33:49 -0800 Subject: [PATCH] add play controls to expanded album list item --- .../expanded-album-list-item.module.css | 14 +++++ .../components/expanded-album-list-item.tsx | 52 ++++++++++++++++++- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/renderer/features/albums/components/expanded-album-list-item.module.css b/src/renderer/features/albums/components/expanded-album-list-item.module.css index 16f0a8719..dd10d0a95 100644 --- a/src/renderer/features/albums/components/expanded-album-list-item.module.css +++ b/src/renderer/features/albums/components/expanded-album-list-item.module.css @@ -105,6 +105,20 @@ height: 100%; } +.play-button-group { + position: relative; + z-index: 10; + display: flex; + align-items: center; + justify-content: center; + opacity: 0; + transition: opacity 0.2s ease-in-out; +} + +.container:hover .play-button-group { + opacity: 1; +} + .background-image { position: absolute; right: 0; diff --git a/src/renderer/features/albums/components/expanded-album-list-item.tsx b/src/renderer/features/albums/components/expanded-album-list-item.tsx index 06660556b..9c0f6d2e1 100644 --- a/src/renderer/features/albums/components/expanded-album-list-item.tsx +++ b/src/renderer/features/albums/components/expanded-album-list-item.tsx @@ -17,6 +17,8 @@ import { } from '/@/renderer/components/item-list/helpers/item-list-state'; import { ItemListItem } from '/@/renderer/components/item-list/types'; import { albumQueries } from '/@/renderer/features/albums/api/album-api'; +import { usePlayer } from '/@/renderer/features/player/context/player-context'; +import { PlayButtonGroup } from '/@/renderer/features/shared/components/play-button-group'; import { useFastAverageColor } from '/@/renderer/hooks'; import { useDragDrop } from '/@/renderer/hooks/use-drag-drop'; import { ActionIcon } from '/@/shared/components/action-icon/action-icon'; @@ -29,6 +31,7 @@ import { Text } from '/@/shared/components/text/text'; import { useMergedRef } from '/@/shared/hooks/use-merged-ref'; import { LibraryItem, Song } from '/@/shared/types/domain-types'; import { DragOperation, DragTarget, DragTargetMap } from '/@/shared/types/drag-and-drop'; +import { Play } from '/@/shared/types/types'; interface AlbumTracksTableProps { isDark?: boolean; @@ -50,11 +53,22 @@ interface ExpandedAlbumListItemProps { interface TrackRowProps { controls: ReturnType; internalState: ItemListStateActions; + player: ReturnType; serverId: string; song: NonNullable[0]; + songIndex: number; + songs: Song[]; } -const TrackRow = ({ controls, internalState, serverId, song }: TrackRowProps) => { +const TrackRow = ({ + controls, + internalState, + player, + serverId, + song, + songIndex, + songs, +}: TrackRowProps) => { const rowId = internalState.extractRowId(song); const isSelected = useItemSelectionState(internalState, rowId); const isDraggingState = useItemDraggingState(internalState, rowId); @@ -107,6 +121,13 @@ const TrackRow = ({ controls, internalState, serverId, song }: TrackRowProps) => const containerRef = useRef(null); const mergedRef = useMergedRef(containerRef, dragRef); + const handleDoubleClick = useCallback(() => { + if (songs && songIndex !== undefined) { + player.addToQueueByData(songs, Play.NOW); + player.mediaPlayByIndex(songIndex); + } + }, [player, songs, songIndex]); + return ( itemType: LibraryItem.SONG, }) } + onDoubleClick={handleDoubleClick} ref={mergedRef} size="sm" > @@ -150,18 +172,24 @@ const AlbumTracksTable = ({ isDark, serverId, songs }: AlbumTracksTableProps) => const internalState = useItemListState(getDataFn, extractRowId); const controls = useDefaultItemListControls(); + const player = usePlayer(); + + const fullSongs = songs as Song[] | undefined; return (
- {songs?.map((song) => ( + {songs?.map((song, index) => ( ))}
@@ -178,6 +206,8 @@ export const ExpandedAlbumListItem = ({ internalState, item }: ExpandedAlbumList }), ); + const player = usePlayer(); + const color = useFastAverageColor({ algorithm: 'sqrt', id: item.id, @@ -185,6 +215,19 @@ export const ExpandedAlbumListItem = ({ internalState, item }: ExpandedAlbumList srcLoaded: true, }); + const handlePlay = useCallback( + (playType: Play) => { + if (!data) { + return; + } + + if (data.songs) { + player.addToQueueByData(data.songs, playType); + } + }, + [data, player], + ); + if (color.isLoading) { return null; } @@ -271,6 +314,11 @@ export const ExpandedAlbumListItem = ({ internalState, item }: ExpandedAlbumList backgroundImage: `url(${data?.imageUrl})`, }} /> + {data?.songs && data.songs.length > 0 && ( +
+ +
+ )}