Skip to content

Commit

Permalink
feat: remove keyboard user setting and enable it always
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Feb 23, 2021
1 parent 4dca002 commit 82369c0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 46 deletions.
31 changes: 9 additions & 22 deletions components/pages/posts/navigation/page/Controls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,17 @@ export default {
},
methods: {
...mapActions('booru', ['fetchPosts', 'pidManager']),
...mapActions('booru', ['pidManager']),
getNextPage() {
this.pidManager({ operation: 'add' })
if (!this.getUserSettings.infiniteLoad.value) scrollToTop()
this.fetchPosts()
async getNextPage() {
await this.pidManager({ operation: 'add' })
},
getPrevPage() {
this.pidManager({ operation: 'subtract' })
if (!this.getUserSettings.infiniteLoad.value) scrollToTop()
this.fetchPosts()
async getPrevPage() {
await this.pidManager({ operation: 'subtract' })
},
getSpecificPage() {
async getSpecificPage() {
const specificPage = Number.parseInt(
prompt('What page do you want to go to?')
)
Expand All @@ -120,18 +112,13 @@ export default {
return
}
this.pidManager({ operation: 'set', value: specificPage })
if (!this.getUserSettings.infiniteLoad.value) scrollToTop()
this.fetchPosts()
await this.pidManager({ operation: 'set', value: specificPage })
},
InfiniteLoadHandler: throttle(function () {
InfiniteLoadHandler: throttle(async function () {
console.debug('Loading more posts')
this.pidManager({ operation: 'add' })
this.fetchPosts('concat')
await this.pidManager({ operation: 'add' })
}, 5000),
},
}
Expand Down
24 changes: 9 additions & 15 deletions components/pages/posts/navigation/page/KeyboardNavigationMixin.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
import { mapGetters } from 'vuex'

export default {
computed: {
...mapGetters('user', ['getUserSettings']),
},

methods: {
keyboardPageHandler() {
async keyboardPageHandler() {
switch (event.keyCode) {
case 39:
this.getNextPage()
console.debug('Loading next page via keyboard action.')

await this.getNextPage()

console.debug('Loading next page')
break

case 37:
this.getPrevPage()
console.debug('Loading previous page via keyboard action.')

await this.getPrevPage()

console.debug('Loading prev page')
break
}
},
},

mounted() {
// Navigation with keyboard
if (this.getUserSettings.keyboardControls.value)
document.addEventListener('keyup', this.keyboardPageHandler)
document.addEventListener('keyup', this.keyboardPageHandler)
},

destroyed() {
// Navigation with keyboard
if (this.getUserSettings.keyboardControls.value)
document.removeEventListener('keyup', this.keyboardPageHandler)
document.removeEventListener('keyup', this.keyboardPageHandler)
},
}
9 changes: 0 additions & 9 deletions store/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ export const state = () => ({
defaultValue: true,
},

keyboardControls: {
name: 'Keyboard controls',
description:
"Keyboard's right and left arrows will navigate pages like clicking the control's buttons.",
image: '/img/usage_examples/keyboard-controls',
value: false,
defaultValue: false,
},

hoverControls: {
name: 'Hover controls',
description:
Expand Down

0 comments on commit 82369c0

Please sign in to comment.