From 3ecf59c32a39cf297423f184acaf32fb83987a51 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Fri, 14 Nov 2025 01:22:46 -0800 Subject: [PATCH] auto follow current song in queue --- .../now-playing/components/play-queue.tsx | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/renderer/features/now-playing/components/play-queue.tsx b/src/renderer/features/now-playing/components/play-queue.tsx index 62f7efe6e..ad5ad6530 100644 --- a/src/renderer/features/now-playing/components/play-queue.tsx +++ b/src/renderer/features/now-playing/components/play-queue.tsx @@ -1,9 +1,10 @@ -import { useDebouncedValue } from '@mantine/hooks'; -import { forwardRef, useMemo } from 'react'; +import { useDebouncedValue, useMergedRef } from '@mantine/hooks'; +import { forwardRef, useMemo, useRef } from 'react'; import { ItemTableList } from '/@/renderer/components/item-list/item-table-list/item-table-list'; import { ItemTableListColumn } from '/@/renderer/components/item-list/item-table-list/item-table-list-column'; import { ItemListHandle } from '/@/renderer/components/item-list/types'; +import { usePlayerEvents } from '/@/renderer/features/player/audio-player/hooks/use-player-events'; import { useIsPlayerFetching, usePlayerContext, @@ -28,6 +29,8 @@ export const PlayQueue = forwardRef(({ listKey, sear const queue = usePlayerQueue(); const isFetching = useIsPlayerFetching(); + const tableRef = useRef(null); + const mergedRef = useMergedRef(ref, tableRef); const [debouncedSearchTerm] = useDebouncedValue(searchTerm, 200); @@ -41,6 +44,26 @@ export const PlayQueue = forwardRef(({ listKey, sear const isEmpty = data.length === 0; + usePlayerEvents( + { + onCurrentSongChange: (properties) => { + const currentSong = properties.song; + if (!currentSong || !tableRef.current) { + return; + } + + const songIndex = data.findIndex( + (song) => song._uniqueId === currentSong._uniqueId, + ); + + if (songIndex !== -1) { + tableRef.current.scrollToIndex(songIndex); + } + }, + }, + [data], + ); + return ( @@ -63,7 +86,7 @@ export const PlayQueue = forwardRef(({ listKey, sear type: 'offset', }} itemType={LibraryItem.QUEUE_SONG} - ref={ref} + ref={mergedRef} size={table.size} /> {isEmpty && }