Resolve "Removing last track in queue jumps player to new last track (instead of continuing current track) (#1485)"

This commit is contained in:
Marcos Peña 2021-10-28 08:17:33 +00:00 committed by JuniorJPDJ
parent 6adae1de66
commit 0cf83f3000
3 changed files with 20 additions and 5 deletions

View File

@ -0,0 +1 @@
Fixed before last track starts playing when last track removed (#1485)

View File

@ -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

View File

@ -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,