a simple web player for subsonic tinysub.devins.page
subsonic navidrome javascript
11
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: incorrect queue index calc after bulk deleting

oh i also fixed how the "clear" action in the footer works. now its more consistent with sort, if you have a couple tracks selected it'll only delete those tracks, but if you have no selected tracks it'll delete everything.

(maybe i should also move the sort button to the queue context menu later? would be more consistent with the clear action)

intergrav 1411ec59 e047e936

+18 -13
+3 -2
src/js/events.js
··· 97 97 98 98 // clear queue 99 99 ui.clearBtn.addEventListener("click", () => { 100 - clearQueue(); 101 - resetPlayerUI(); 100 + (selectionManager?.getSelected()?.length > 0 101 + ? clearSelectedRows 102 + : clearQueue)(); 102 103 }); 103 104 104 105 // queue table: row selection and action button handlers
+15 -11
src/js/queue.js
··· 5 5 function sortQueue(field, ascending) { 6 6 const currentTrack = 7 7 state.queueIndex >= 0 ? state.queue[state.queueIndex] : null; 8 - const selectedIndices = 9 - typeof selectionManager !== "undefined" 10 - ? selectionManager.getSelected() 11 - : []; 8 + const selectedIndices = selectionManager?.getSelected() ?? []; 12 9 const hasSelection = selectedIndices.length > 0; 13 10 14 11 // extract items to sort: either selected songs or entire queue ··· 311 308 312 309 const toRemoveSet = new Set(toRemove); 313 310 const wasCurrentTrackDeleted = toRemoveSet.has(state.queueIndex); 314 - const deletionsBefore = toRemove.filter( 315 - (idx) => idx < state.queueIndex, 316 - ).length; 311 + const originalLength = state.queue.length; 312 + const countDeletionsBefore = (idx) => toRemove.filter((i) => i < idx).length; 317 313 318 314 state.queue = state.queue.filter((_, idx) => !toRemoveSet.has(idx)); 319 315 320 - if (!wasCurrentTrackDeleted && state.queueIndex >= 0) { 321 - state.queueIndex -= deletionsBefore; 322 - } else if (wasCurrentTrackDeleted) { 323 - state.queueIndex = Math.min(state.queueIndex, state.queue.length - 1); 316 + if (!wasCurrentTrackDeleted) { 317 + state.queueIndex -= countDeletionsBefore(state.queueIndex); 318 + } else { 319 + let nextIndex = -1; 320 + for (let i = state.queueIndex + 1; i < originalLength; i++) { 321 + if (!toRemoveSet.has(i)) { 322 + nextIndex = i - countDeletionsBefore(i); 323 + break; 324 + } 325 + } 326 + state.queueIndex = 327 + nextIndex >= 0 ? nextIndex : Math.max(-1, state.queue.length - 1); 324 328 handleCurrentTrackDeleted(); 325 329 } 326 330