From 98c1ee01fdc45728368e404321bfce37ac6478bb Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 23 Oct 2021 16:49:34 -0500 Subject: [PATCH] Add: add hotkeys to modals, player, and ereader #121, Fix: audio player track not resizing on window resize #123, Add: sortable columns on manage tracks page #128 --- client/components/AudioPlayer.vue | 47 +++++++++++++++---- client/components/app/StreamContainer.vue | 2 +- client/components/modals/EditModal.vue | 24 +++++++++- client/components/modals/Modal.vue | 7 +++ .../components/modals/edit-tabs/Details.vue | 4 +- client/components/readers/Reader.vue | 39 +++++++-------- client/components/tables/LibrariesTable.vue | 8 +++- client/layouts/default.vue | 36 +++++++++++--- client/package.json | 2 +- client/pages/audiobook/_id/edit.vue | 47 ++++++++++++++++--- client/plugins/constants.js | 19 ++++---- package.json | 2 +- 12 files changed, 176 insertions(+), 61 deletions(-) diff --git a/client/components/AudioPlayer.vue b/client/components/AudioPlayer.vue index bc1b0844..b4ce3d22 100644 --- a/client/components/AudioPlayer.vue +++ b/client/components/AudioPlayer.vue @@ -451,7 +451,8 @@ export default { }) }, showChapters() { - this.showChaptersModal = true + if (!this.chapters.length) return + this.showChaptersModal = !this.showChaptersModal }, play() { if (!this.$refs.audio) { @@ -486,6 +487,9 @@ export default { this.playbackRate = this.$store.getters['user/getUserSetting']('playbackRate') || 1 this.audioEl = this.$refs.audio + this.setTrackWidth() + }, + setTrackWidth() { if (this.$refs.track) { this.trackWidth = this.$refs.track.clientWidth } else { @@ -512,21 +516,48 @@ export default { this.$refs.volumeControl.toggleMute() } }, - hotkey(keyCode) { - if (keyCode === this.$hotkeys.PLAY_PAUSE) this.playPauseClick() - else if (keyCode === this.$hotkeys.JUMP_FORWARD) this.forward10() - else if (keyCode === this.$hotkeys.JUMP_BACKWARD) this.backward10() - else if (keyCode === this.$hotkeys.VOLUME_UP) this.volumeUp() - else if (keyCode === this.$hotkeys.VOLUME_DOWN) this.volumeDown() - else if (keyCode === this.$hotkeys.MUTE) this.toggleMute() + increasePlaybackRate() { + var rates = [0.25, 0.5, 0.8, 1, 1.3, 1.5, 2, 2.5, 3] + var currentRateIndex = rates.findIndex((r) => r === this.playbackRate) + if (currentRateIndex >= rates.length - 1) return + this.playbackRate = rates[currentRateIndex + 1] || 1 + this.playbackRateChanged(this.playbackRate) + }, + decreasePlaybackRate() { + var rates = [0.25, 0.5, 0.8, 1, 1.3, 1.5, 2, 2.5, 3] + var currentRateIndex = rates.findIndex((r) => r === this.playbackRate) + if (currentRateIndex <= 0) return + this.playbackRate = rates[currentRateIndex - 1] || 1 + this.playbackRateChanged(this.playbackRate) + }, + closePlayer() { + if (this.loading) return + this.$emit('close') + }, + hotkey(action) { + if (action === 'Space') this.playPauseClick() + else if (action === 'ArrowRight') this.forward10() + else if (action === 'ArrowLeft') this.backward10() + else if (action === 'ArrowUp') this.volumeUp() + else if (action === 'ArrowDown') this.volumeDown() + else if (action === 'KeyM') this.toggleMute() + else if (action === 'KeyL') this.showChapters() + else if (action === 'Shift-ArrowUp') this.increasePlaybackRate() + else if (action === 'Shift-ArrowDown') this.decreasePlaybackRate() + else if (action === 'Escape') this.closePlayer() + }, + windowResize() { + this.setTrackWidth() } }, mounted() { + window.addEventListener('resize', this.windowResize) this.$store.commit('user/addSettingsListener', { id: 'audioplayer', meth: this.settingsUpdated }) this.init() this.$eventBus.$on('player-hotkey', this.hotkey) }, beforeDestroy() { + window.removeEventListener('resize', this.windowResize) this.$store.commit('user/removeSettingsListener', 'audioplayer') this.$eventBus.$off('player-hotkey', this.hotkey) } diff --git a/client/components/app/StreamContainer.vue b/client/components/app/StreamContainer.vue index 04e5b69d..721138b0 100644 --- a/client/components/app/StreamContainer.vue +++ b/client/components/app/StreamContainer.vue @@ -14,7 +14,7 @@ close - + diff --git a/client/components/modals/EditModal.vue b/client/components/modals/EditModal.vue index 543a65e6..3ba9a523 100644 --- a/client/components/modals/EditModal.vue +++ b/client/components/modals/EditModal.vue @@ -93,6 +93,9 @@ export default { this.fetchOnShow = false this.audiobook = null this.init() + this.registerListeners() + } else { + this.unregisterListeners() } } } @@ -179,7 +182,8 @@ export default { } }, goNextBook() { - if (this.currentBookshelfIndex >= this.bookshelfBookIds.length) return + if (this.currentBookshelfIndex >= this.bookshelfBookIds.length - 1) return + var nextBookId = this.bookshelfBookIds[this.currentBookshelfIndex + 1] var nextBook = this.$store.getters['audiobooks/getAudiobook'](nextBookId) if (nextBook) { @@ -212,9 +216,25 @@ export default { this.processing = false this.show = false } + }, + hotkey(action) { + if (action === 'ArrowRight') { + this.goNextBook() + } else if (action === 'ArrowLeft') { + this.goPrevBook() + } + }, + registerListeners() { + this.$eventBus.$on('modal-hotkey', this.hotkey) + }, + unregisterListeners() { + this.$eventBus.$off('modal-hotkey', this.hotkey) } }, - mounted() {} + mounted() {}, + beforeDestroy() { + this.unregisterListeners() + } } diff --git a/client/components/modals/Modal.vue b/client/components/modals/Modal.vue index 838b3a88..e3c42ff2 100644 --- a/client/components/modals/Modal.vue +++ b/client/components/modals/Modal.vue @@ -83,6 +83,11 @@ export default { this.show = false } }, + hotkey(action) { + if (action === 'Escape') { + this.show = false + } + }, setShow() { document.body.appendChild(this.el) setTimeout(() => { @@ -90,6 +95,7 @@ export default { }, 10) document.documentElement.classList.add('modal-open') + this.$eventBus.$on('modal-hotkey', this.hotkey) this.$store.commit('setOpenModal', this.name) }, setHide() { @@ -97,6 +103,7 @@ export default { this.el.remove() document.documentElement.classList.remove('modal-open') + this.$eventBus.$off('modal-hotkey', this.hotkey) this.$store.commit('setOpenModal', null) } }, diff --git a/client/components/modals/edit-tabs/Details.vue b/client/components/modals/edit-tabs/Details.vue index bf92a54d..c3786f27 100644 --- a/client/components/modals/edit-tabs/Details.vue +++ b/client/components/modals/edit-tabs/Details.vue @@ -60,8 +60,8 @@ Save Metadata - - Re-Scan + + Re-Scan
diff --git a/client/components/readers/Reader.vue b/client/components/readers/Reader.vue index bcb3a7c0..ac41776a 100644 --- a/client/components/readers/Reader.vue +++ b/client/components/readers/Reader.vue @@ -1,7 +1,7 @@