From 6ed6634f932549e657852795d5d0a49404020dd7 Mon Sep 17 00:00:00 2001 From: Eliot Berriot <contact@eliotberriot.com> Date: Mon, 23 Apr 2018 18:32:27 +0200 Subject: [PATCH] Fixed #151: queue reorder or track deletion restarting currently playing track --- changes/changelog.d/151.bugfix | 1 + front/src/components/Sidebar.vue | 5 +++-- front/src/components/audio/Player.vue | 2 +- front/src/components/audio/Track.vue | 6 ++++++ front/src/store/queue.js | 4 ++-- front/test/unit/specs/store/queue.spec.js | 4 +--- 6 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 changes/changelog.d/151.bugfix diff --git a/changes/changelog.d/151.bugfix b/changes/changelog.d/151.bugfix new file mode 100644 index 00000000..801da2a9 --- /dev/null +++ b/changes/changelog.d/151.bugfix @@ -0,0 +1 @@ +Fixed queue reorder or track deletion restarting currently playing track (#151) diff --git a/front/src/components/Sidebar.vue b/front/src/components/Sidebar.vue index 3f793fe0..b751dae7 100644 --- a/front/src/components/Sidebar.vue +++ b/front/src/components/Sidebar.vue @@ -143,8 +143,9 @@ export default { ...mapActions({ cleanTrack: 'queue/cleanTrack' }), - reorder: function (oldValue, newValue) { - this.$store.commit('queue/reorder', {oldValue, newValue}) + reorder: function (event) { + this.$store.commit('queue/reorder', { + oldIndex: event.oldIndex, newIndex: event.newIndex}) }, scrollToCurrent () { let current = $(this.$el).find('[data-tab="queue"] .active')[0] diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue index ad90a599..28ace828 100644 --- a/front/src/components/audio/Player.vue +++ b/front/src/components/audio/Player.vue @@ -4,7 +4,7 @@ <audio-track ref="currentAudio" v-if="renderAudio && currentTrack" - :key="(currentIndex, currentTrack.id)" + :key="currentTrack.id" :is-current="true" :start-time="$store.state.player.currentTime" :autoplay="$store.state.player.playing" diff --git a/front/src/components/audio/Track.vue b/front/src/components/audio/Track.vue index 5b826d2d..08a055f5 100644 --- a/front/src/components/audio/Track.vue +++ b/front/src/components/audio/Track.vue @@ -86,9 +86,15 @@ export default { } }, updateDuration: function (e) { + if (!this.$refs.audio) { + return + } this.$store.commit('player/duration', this.$refs.audio.duration) }, loaded: function () { + if (!this.$refs.audio) { + return + } this.$refs.audio.volume = this.volume this.$store.commit('player/resetErrorCount') if (this.isCurrent) { diff --git a/front/src/store/queue.js b/front/src/store/queue.js index 2890dd1e..b0a4f732 100644 --- a/front/src/store/queue.js +++ b/front/src/store/queue.js @@ -92,10 +92,10 @@ export default { if (current) { dispatch('player/stop', null, {root: true}) } + commit('splice', {start: index, size: 1}) if (index < state.currentIndex) { - dispatch('currentIndex', state.currentIndex - 1) + commit('currentIndex', state.currentIndex - 1) } - commit('splice', {start: index, size: 1}) if (current) { // we play next track, which now have the same index dispatch('currentIndex', index) diff --git a/front/test/unit/specs/store/queue.spec.js b/front/test/unit/specs/store/queue.spec.js index 0df7608e..3a59117d 100644 --- a/front/test/unit/specs/store/queue.spec.js +++ b/front/test/unit/specs/store/queue.spec.js @@ -158,9 +158,7 @@ describe('store/queue', () => { payload: 1, params: {state: {currentIndex: 2}}, expectedMutations: [ - { type: 'splice', payload: {start: 1, size: 1} } - ], - expectedActions: [ + { type: 'splice', payload: {start: 1, size: 1} }, { type: 'currentIndex', payload: 1 } ] }, done) -- GitLab