fix priority queue reorder above current song

This commit is contained in:
jeffvli
2025-11-18 00:38:23 -08:00
parent f3bb4187d7
commit 18a7875504
2 changed files with 28 additions and 4 deletions
@@ -104,8 +104,6 @@ export const PlayQueue = forwardRef<ItemListHandle, QueueProps>(({ listKey, sear
};
}, [getQueue, queueType, tableRef]);
console.log(groups);
const filteredData: QueueSong[] = useMemo(() => {
if (debouncedSearchTerm) {
const searched = searchSongs(data, debouncedSearchTerm);
+28 -2
View File
@@ -773,6 +773,9 @@ export const usePlayerStoreBase = create<PlayerState>()(
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<PlayerState>()(
);
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<PlayerState>()(
);
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,