diff --git a/src/renderer/features/now-playing/components/play-queue.tsx b/src/renderer/features/now-playing/components/play-queue.tsx index 6daadb5f8..c816addb1 100644 --- a/src/renderer/features/now-playing/components/play-queue.tsx +++ b/src/renderer/features/now-playing/components/play-queue.tsx @@ -104,8 +104,6 @@ export const PlayQueue = forwardRef(({ listKey, sear }; }, [getQueue, queueType, tableRef]); - console.log(groups); - const filteredData: QueueSong[] = useMemo(() => { if (debouncedSearchTerm) { const searched = searchSongs(data, debouncedSearchTerm); diff --git a/src/renderer/store/player.store.ts b/src/renderer/store/player.store.ts index b1851f15e..6d29a2aa3 100644 --- a/src/renderer/store/player.store.ts +++ b/src/renderer/store/player.store.ts @@ -773,6 +773,9 @@ export const usePlayerStoreBase = create()( recalculatePlayerIndex(state, newQueue); state.queue.default = newQueue; } else { + const currentTrack = state.getCurrentSong() as QueueSong | undefined; + const currentTrackUniqueId = currentTrack?._uniqueId; + const priorityIndex = state.queue.priority.findIndex( (id) => id === uniqueId, ); @@ -803,7 +806,11 @@ export const usePlayerStoreBase = create()( ); const combinedQueue = [...newPriorityQueue, ...newDefaultQueue]; - recalculatePlayerIndex(state, combinedQueue); + recalculatePlayerIndexByUniqueId( + state, + currentTrackUniqueId, + combinedQueue, + ); state.queue.priority = newPriorityQueue; state.queue.default = newDefaultQueue; @@ -837,7 +844,11 @@ export const usePlayerStoreBase = create()( ); const combinedQueue = [...newPriorityQueue, ...newDefaultQueue]; - recalculatePlayerIndex(state, combinedQueue); + recalculatePlayerIndexByUniqueId( + state, + currentTrackUniqueId, + combinedQueue, + ); state.queue.default = newDefaultQueue; state.queue.priority = newPriorityQueue; @@ -1529,6 +1540,21 @@ function recalculatePlayerIndex(state: any, queue: string[]) { state.player.index = Math.max(0, index); } +function recalculatePlayerIndexByUniqueId( + state: any, + currentTrackUniqueId: string | undefined, + queue: string[], +) { + if (!currentTrackUniqueId) { + return; + } + + const recalculatedIndex = queue.findIndex((id) => id === currentTrackUniqueId); + if (recalculatedIndex !== -1) { + state.player.index = recalculatedIndex; + } +} + function toQueueSong(item: Song): QueueSong { return { ...item,