diff --git a/changes/changelog.d/1485.bugfix b/changes/changelog.d/1485.bugfix new file mode 100644 index 0000000000000000000000000000000000000000..7d0ffb379c1afe504114f91fd1c3bd7fcc623db1 --- /dev/null +++ b/changes/changelog.d/1485.bugfix @@ -0,0 +1 @@ +Fixed before last track starts playing when last track removed (#1485) diff --git a/front/src/store/queue.js b/front/src/store/queue.js index 5acff3efb3bae9a43288b2f68c84eab5be9bb1d9..e096a6f0adc2f5ef0324ca5afd9c19db00072017 100644 --- a/front/src/store/queue.js +++ b/front/src/store/queue.js @@ -97,18 +97,18 @@ export default { cleanTrack ({state, dispatch, commit}, index) { // are we removing current playin track - let current = index === state.currentIndex + const current = index === state.currentIndex if (current) { dispatch('player/stop', null, {root: true}) } commit('splice', {start: index, size: 1}) if (index < state.currentIndex) { commit('currentIndex', state.currentIndex - 1) - } else if (index > 0 && index === state.tracks.length) { + } else if (index > 0 && index === state.tracks.length && current) { // kind of a edge case: if you delete the last track of the queue - // we set current index to the previous one to avoid the queue tab from - // being stuck because the player disappeared - // cf #1092 + // while it's playing we set current index to the previous one to + // avoid the queue tab from being stuck because the player + // disappeared cf #1092 commit('currentIndex', state.tracks.length - 1) } else if (current) { // we play next track, which now have the same index diff --git a/front/tests/unit/specs/store/queue.spec.js b/front/tests/unit/specs/store/queue.spec.js index 7af57d97d6eaab82188b2cdb72bd58cceb60c34e..c3ac0be4b43dfc8844d7d4d9bba2915a3593f964 100644 --- a/front/tests/unit/specs/store/queue.spec.js +++ b/front/tests/unit/specs/store/queue.spec.js @@ -164,6 +164,20 @@ describe('store/queue', () => { ] }) }) + it('cleanTrack current is last', () => { + testAction({ + action: store.actions.cleanTrack, + payload: 5, + params: { state: { currentIndex: 5, tracks: [1, 2, 3, 4, 5] } }, + expectedMutations: [ + { type: 'splice', payload: { start: 5, size: 1 } }, + { type: 'currentIndex', payload: 4 } + ], + expectedActions: [ + { type: 'player/stop', payload: null, options: { root: true } } + ] + }) + }) it('previous when at beginning', () => { testAction({ action: store.actions.previous,