From 6b8dc1b53c06f41b9a5753db7edd41800847c768 Mon Sep 17 00:00:00 2001 From: Bat Date: Sat, 31 Mar 2018 14:14:58 +0100 Subject: [PATCH 1/4] Reset player position before playing previous track --- front/src/components/audio/Player.vue | 6 ++---- front/src/components/audio/Track.vue | 10 +++++++++- front/src/store/queue.js | 9 ++++----- front/test/unit/specs/store/queue.spec.js | 8 -------- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue index 75a01c52e..2b0032cf7 100644 --- a/front/src/components/audio/Player.vue +++ b/front/src/components/audio/Player.vue @@ -58,9 +58,8 @@
- + class="two wide column control"> +
{ return state.currentIndex < state.tracks.length - 1 - }, - hasPrevious: state => { - return state.currentIndex > 0 } }, actions: { @@ -103,9 +100,11 @@ export default { dispatch('next') } }, - previous ({state, dispatch}) { - if (state.currentIndex > 0) { + previous ({state, dispatch, rootState}) { + if (state.currentIndex > 0 && rootState.player.currentTime < 3) { dispatch('currentIndex', state.currentIndex - 1) + } else { + dispatch('currentIndex', state.currentIndex) } }, next ({state, dispatch, commit, rootState}) { diff --git a/front/test/unit/specs/store/queue.spec.js b/front/test/unit/specs/store/queue.spec.js index b445229ec..a46ca35bf 100644 --- a/front/test/unit/specs/store/queue.spec.js +++ b/front/test/unit/specs/store/queue.spec.js @@ -81,14 +81,6 @@ describe('store/queue', () => { const state = { tracks: [1, 2, 3], currentIndex: 2 } expect(store.getters['hasNext'](state)).to.equal(false) }) - it('hasPrevious true', () => { - const state = { currentIndex: 1 } - expect(store.getters['hasPrevious'](state)).to.equal(true) - }) - it('hasPrevious false', () => { - const state = { currentIndex: 0 } - expect(store.getters['hasPrevious'](state)).to.equal(false) - }) }) describe('actions', () => { it('append at end', (done) => { From 80af4268e366463e789d8888258a2da8398eaf84 Mon Sep 17 00:00:00 2001 From: Bat Date: Sat, 31 Mar 2018 14:29:20 +0100 Subject: [PATCH 2/4] Tests --- front/test/unit/specs/store/queue.spec.js | 27 ++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/front/test/unit/specs/store/queue.spec.js b/front/test/unit/specs/store/queue.spec.js index a46ca35bf..2bc5cde4e 100644 --- a/front/test/unit/specs/store/queue.spec.js +++ b/front/test/unit/specs/store/queue.spec.js @@ -204,22 +204,33 @@ describe('store/queue', () => { expectedActions: [] }, done) }) - it('previous when at beginning does nothing', (done) => { + it('previous when at beginning', (done) => { testAction({ action: store.actions.previous, params: {state: {currentIndex: 0}}, - expectedActions: [] - }, done) - }) - it('previous', (done) => { - testAction({ - action: store.actions.previous, - params: {state: {currentIndex: 1}}, expectedActions: [ { type: 'currentIndex', payload: 0 } ] }, done) }) + it('previous after less than 3 seconds of playback', (done) => { + testAction({ + action: store.actions.previous, + params: {state: {currentIndex: 1}, rootState: {player: {currentTime: 1}}}, + expectedActions: [ + { type: 'currentIndex', payload: 0 } + ] + }, done) + }) + it('previous after more than 3 seconds of playback', (done) => { + testAction({ + action: store.actions.previous, + params: {state: {currentIndex: 1}, rootState: {player: {currentTime: 3}}}, + expectedActions: [ + { type: 'currentIndex', payload: 1 } + ] + }, done) + }) it('next on last track when looping on queue', (done) => { testAction({ action: store.actions.next, From eea1abad5c5aaf021cc2969e0de2aa2f647e67c3 Mon Sep 17 00:00:00 2001 From: Bat Date: Sat, 31 Mar 2018 14:30:45 +0100 Subject: [PATCH 3/4] Changelog --- changes/changelog.d/146.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/changelog.d/146.feature diff --git a/changes/changelog.d/146.feature b/changes/changelog.d/146.feature new file mode 100644 index 000000000..2a7617644 --- /dev/null +++ b/changes/changelog.d/146.feature @@ -0,0 +1 @@ +Previous Track button restart playback after 3 seconds (#146) From 69a3f34784430923eb71b7336f29a117dffe3826 Mon Sep 17 00:00:00 2001 From: Bat Date: Sun, 1 Apr 2018 16:21:52 +0100 Subject: [PATCH 4/4] Disable previous button if queue is empty --- front/src/components/audio/Player.vue | 6 ++++-- front/src/store/queue.js | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue index 2b0032cf7..31f6dc35a 100644 --- a/front/src/components/audio/Player.vue +++ b/front/src/components/audio/Player.vue @@ -58,8 +58,9 @@
- + class="two wide column control" + :disabled="emptyQueue"> +
{ return state.currentIndex < state.tracks.length - 1 - } + }, + isEmpty: state => state.tracks.length === 0 }, actions: { append ({commit, state, dispatch}, {track, index, skipPlay}) {