diff --git a/changes/changelog.d/146.feature b/changes/changelog.d/146.feature new file mode 100644 index 0000000000000000000000000000000000000000..2a7617644fcc2d2ba25b86ea2cca0b9fe81657ed --- /dev/null +++ b/changes/changelog.d/146.feature @@ -0,0 +1 @@ +Previous Track button restart playback after 3 seconds (#146) diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue index 75a01c52e015b419d4c919b90bfe97e7db8ab02b..31f6dc35ac3478a9b3c84b15a76ea9adcc044882 100644 --- a/front/src/components/audio/Player.vue +++ b/front/src/components/audio/Player.vue @@ -59,8 +59,8 @@ <div title="Previous track" class="two wide column control" - :disabled="!hasPrevious"> - <i @click="previous" :class="['ui', {'disabled': !hasPrevious}, 'step', 'backward', 'big', 'icon']" ></i> + :disabled="emptyQueue"> + <i @click="previous" :class="['ui', 'backward', {'disabled': emptyQueue}, 'big', 'icon']"></i> </div> <div v-if="!playing" @@ -205,7 +205,7 @@ export default { ...mapGetters({ currentTrack: 'queue/currentTrack', hasNext: 'queue/hasNext', - hasPrevious: 'queue/hasPrevious', + emptyQueue: 'queue/isEmpty', durationFormatted: 'player/durationFormatted', currentTimeFormatted: 'player/currentTimeFormatted', progress: 'player/progress' diff --git a/front/src/components/audio/Track.vue b/front/src/components/audio/Track.vue index 370d8ae2d3a6c5a4076c5220f5e6d0f1f7f80e66..68dd34459870f432d7ca5c9e3b35a6d7966b225d 100644 --- a/front/src/components/audio/Track.vue +++ b/front/src/components/audio/Track.vue @@ -31,7 +31,8 @@ export default { }, data () { return { - sourceErrors: 0 + sourceErrors: 0, + isUpdatingTime: false } }, computed: { @@ -99,6 +100,7 @@ export default { } }, updateProgress: _.throttle(function () { + this.isUpdatingTime = true if (this.$refs.audio) { this.$store.dispatch('player/updateProgress', this.$refs.audio.currentTime) } @@ -130,6 +132,12 @@ export default { }, volume: function (newValue) { this.$refs.audio.volume = newValue + }, + currentTime (newValue) { + if (!this.isUpdatingTime) { + this.setCurrentTime(newValue) + } + this.isUpdatingTime = false } } } diff --git a/front/src/store/queue.js b/front/src/store/queue.js index a864405cf675a1f90f485ae53845240c06fdaae5..6a26fa1e9a0dc70609b0ea6fcba6e5b11745f277 100644 --- a/front/src/store/queue.js +++ b/front/src/store/queue.js @@ -49,9 +49,7 @@ export default { hasNext: state => { return state.currentIndex < state.tracks.length - 1 }, - hasPrevious: state => { - return state.currentIndex > 0 - } + isEmpty: state => state.tracks.length === 0 }, actions: { append ({commit, state, dispatch}, {track, index, skipPlay}) { @@ -103,9 +101,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 b445229ec44fa680be900eba1007dfe6aa1f6bbe..2bc5cde4efec16a0cfdcf40ce36b1385780b93a1 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) => { @@ -212,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: [] + expectedActions: [ + { type: 'currentIndex', payload: 0 } + ] }, done) }) - it('previous', (done) => { + it('previous after less than 3 seconds of playback', (done) => { testAction({ action: store.actions.previous, - params: {state: {currentIndex: 1}}, + 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,