mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-10 04:30:25 +02:00
fix priority queue reorder above current song
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user