properly handle adding list queries from song list to queue

This commit is contained in:
jeffvli
2025-11-26 23:33:07 -08:00
parent 9e0c4d4b2a
commit 6b307b3bd4
@@ -413,7 +413,7 @@ export const PlayerProvider = ({ children }: { children: React.ReactNode }) => {
}; };
// Paginate through all items to collect IDs // Paginate through all items to collect IDs
const allIds: string[] = []; const allResults: Song[] | string[] = [];
const pageSize = 500; // Fetch in chunks const pageSize = 500; // Fetch in chunks
let startIndex = 0; let startIndex = 0;
@@ -434,8 +434,12 @@ export const PlayerProvider = ({ children }: { children: React.ReactNode }) => {
})) as { items: any[] }; })) as { items: any[] };
if (pageResult?.items) { if (pageResult?.items) {
const pageIds = pageResult.items.map((item: any) => item.id); if (itemType === LibraryItem.SONG) {
allIds.push(...pageIds); allResults.push(...pageResult.items);
} else {
const pageIds = pageResult.items.map((item: any) => item.id);
allResults.push(...pageIds);
}
} }
// If we got fewer items than requested, we've reached the end // If we got fewer items than requested, we've reached the end
@@ -450,12 +454,16 @@ export const PlayerProvider = ({ children }: { children: React.ReactNode }) => {
clearTimeout(timeoutIds.current[fetchId] as ReturnType<typeof setTimeout>); clearTimeout(timeoutIds.current[fetchId] as ReturnType<typeof setTimeout>);
delete timeoutIds.current[fetchId]; delete timeoutIds.current[fetchId];
} }
if (toastId) { if (toastId) {
toast.hide(toastId); toast.hide(toastId);
} }
// Now call addToQueueByFetch with all collected IDs (skip confirmation since we already confirmed) if (itemType === LibraryItem.SONG) {
await addToQueueByFetch(serverId, allIds, itemType, type, true); addToQueueByData(allResults as Song[], type);
} else {
await addToQueueByFetch(serverId, allResults as string[], itemType, type, true);
}
} catch (err: any) { } catch (err: any) {
if (instanceOfCancellationError(err)) { if (instanceOfCancellationError(err)) {
return; return;
@@ -475,7 +483,7 @@ export const PlayerProvider = ({ children }: { children: React.ReactNode }) => {
}); });
} }
}, },
[confirmLargeFetch, queueFetchConfirmThreshold, queryClient, addToQueueByFetch, t], [queryClient, confirmLargeFetch, t, addToQueueByData, addToQueueByFetch],
); );
const clearQueue = useCallback(() => { const clearQueue = useCallback(() => {