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:
@@ -104,8 +104,6 @@ export const PlayQueue = forwardRef<ItemListHandle, QueueProps>(({ listKey, sear
|
|||||||
};
|
};
|
||||||
}, [getQueue, queueType, tableRef]);
|
}, [getQueue, queueType, tableRef]);
|
||||||
|
|
||||||
console.log(groups);
|
|
||||||
|
|
||||||
const filteredData: QueueSong[] = useMemo(() => {
|
const filteredData: QueueSong[] = useMemo(() => {
|
||||||
if (debouncedSearchTerm) {
|
if (debouncedSearchTerm) {
|
||||||
const searched = searchSongs(data, debouncedSearchTerm);
|
const searched = searchSongs(data, debouncedSearchTerm);
|
||||||
|
|||||||
@@ -773,6 +773,9 @@ export const usePlayerStoreBase = create<PlayerState>()(
|
|||||||
recalculatePlayerIndex(state, newQueue);
|
recalculatePlayerIndex(state, newQueue);
|
||||||
state.queue.default = newQueue;
|
state.queue.default = newQueue;
|
||||||
} else {
|
} else {
|
||||||
|
const currentTrack = state.getCurrentSong() as QueueSong | undefined;
|
||||||
|
const currentTrackUniqueId = currentTrack?._uniqueId;
|
||||||
|
|
||||||
const priorityIndex = state.queue.priority.findIndex(
|
const priorityIndex = state.queue.priority.findIndex(
|
||||||
(id) => id === uniqueId,
|
(id) => id === uniqueId,
|
||||||
);
|
);
|
||||||
@@ -803,7 +806,11 @@ export const usePlayerStoreBase = create<PlayerState>()(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const combinedQueue = [...newPriorityQueue, ...newDefaultQueue];
|
const combinedQueue = [...newPriorityQueue, ...newDefaultQueue];
|
||||||
recalculatePlayerIndex(state, combinedQueue);
|
recalculatePlayerIndexByUniqueId(
|
||||||
|
state,
|
||||||
|
currentTrackUniqueId,
|
||||||
|
combinedQueue,
|
||||||
|
);
|
||||||
|
|
||||||
state.queue.priority = newPriorityQueue;
|
state.queue.priority = newPriorityQueue;
|
||||||
state.queue.default = newDefaultQueue;
|
state.queue.default = newDefaultQueue;
|
||||||
@@ -837,7 +844,11 @@ export const usePlayerStoreBase = create<PlayerState>()(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const combinedQueue = [...newPriorityQueue, ...newDefaultQueue];
|
const combinedQueue = [...newPriorityQueue, ...newDefaultQueue];
|
||||||
recalculatePlayerIndex(state, combinedQueue);
|
recalculatePlayerIndexByUniqueId(
|
||||||
|
state,
|
||||||
|
currentTrackUniqueId,
|
||||||
|
combinedQueue,
|
||||||
|
);
|
||||||
|
|
||||||
state.queue.default = newDefaultQueue;
|
state.queue.default = newDefaultQueue;
|
||||||
state.queue.priority = newPriorityQueue;
|
state.queue.priority = newPriorityQueue;
|
||||||
@@ -1529,6 +1540,21 @@ function recalculatePlayerIndex(state: any, queue: string[]) {
|
|||||||
state.player.index = Math.max(0, index);
|
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 {
|
function toQueueSong(item: Song): QueueSong {
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
|
|||||||
Reference in New Issue
Block a user