Add shortcuts for refresh buttons on Subscription, Trending, and Popular views (#2689)

* add shortcut to subscription refresh button

* add shortcut to most popular refresh button

* add shortcut to trending refresh button

* prevent refresh if currently loading
This commit is contained in:
Aiz 2022-10-09 13:10:57 +00:00 committed by GitHub
parent aa4a01b9ab
commit 7ca6440a88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 1 deletions

View File

@ -25,11 +25,16 @@ export default Vue.extend({
} }
}, },
mounted: function () { mounted: function () {
document.addEventListener('keydown', this.keyboardShortcutHandler)
this.shownResults = this.popularCache this.shownResults = this.popularCache
if (!this.shownResults || this.shownResults.length < 1) { if (!this.shownResults || this.shownResults.length < 1) {
this.fetchPopularInfo() this.fetchPopularInfo()
} }
}, },
beforeDestroy: function () {
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: { methods: {
fetchPopularInfo: async function () { fetchPopularInfo: async function () {
const searchPayload = { const searchPayload = {
@ -56,6 +61,21 @@ export default Vue.extend({
this.$store.commit('setPopularCache', this.shownResults) this.$store.commit('setPopularCache', this.shownResults)
}, },
// This function should always be at the bottom of this file
keyboardShortcutHandler: function (event) {
if (event.ctrlKey || document.activeElement.classList.contains('ft-input')) {
return
}
switch (event.key) {
case 'r':
case 'R':
if (!this.isLoading) {
this.fetchPopularInfo()
}
break
}
},
...mapActions([ ...mapActions([
'invidiousAPICall' 'invidiousAPICall'
]) ])

View File

@ -98,6 +98,8 @@ export default Vue.extend({
} }
}, },
mounted: async function () { mounted: async function () {
document.addEventListener('keydown', this.keyboardShortcutHandler)
this.isLoading = true this.isLoading = true
const dataLimit = sessionStorage.getItem('subscriptionLimit') const dataLimit = sessionStorage.getItem('subscriptionLimit')
if (dataLimit !== null) { if (dataLimit !== null) {
@ -132,6 +134,9 @@ export default Vue.extend({
this.isLoading = false this.isLoading = false
} }
}, },
beforeDestroy: function () {
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: { methods: {
goToChannel: function (id) { goToChannel: function (id) {
this.$router.push({ path: `/channel/${id}` }) this.$router.push({ path: `/channel/${id}` })
@ -471,6 +476,21 @@ export default Vue.extend({
sessionStorage.setItem('subscriptionLimit', this.dataLimit) sessionStorage.setItem('subscriptionLimit', this.dataLimit)
}, },
// This function should always be at the bottom of this file
keyboardShortcutHandler: function (event) {
if (event.ctrlKey || document.activeElement.classList.contains('ft-input')) {
return
}
switch (event.key) {
case 'r':
case 'R':
if (!this.isLoading) {
this.getSubscriptions()
}
break
}
},
...mapActions([ ...mapActions([
'showToast', 'showToast',
'invidiousAPICall', 'invidiousAPICall',

View File

@ -42,12 +42,17 @@ export default Vue.extend({
} }
}, },
mounted: function () { mounted: function () {
document.addEventListener('keydown', this.keyboardShortcutHandler)
if (this.trendingCache[this.currentTab] && this.trendingCache[this.currentTab].length > 0) { if (this.trendingCache[this.currentTab] && this.trendingCache[this.currentTab].length > 0) {
this.getTrendingInfoCache() this.getTrendingInfoCache()
} else { } else {
this.getTrendingInfo() this.getTrendingInfo()
} }
}, },
beforeDestroy: function () {
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: { methods: {
changeTab: function (tab) { changeTab: function (tab) {
this.currentTab = tab this.currentTab = tab
@ -125,7 +130,6 @@ export default Vue.extend({
}) })
}) })
}, },
getTrendingInfoInvidious: function () { getTrendingInfoInvidious: function () {
this.isLoading = true this.isLoading = true
@ -176,6 +180,21 @@ export default Vue.extend({
}) })
}, },
// This function should always be at the bottom of this file
keyboardShortcutHandler: function (event) {
if (event.ctrlKey || document.activeElement.classList.contains('ft-input')) {
return
}
switch (event.key) {
case 'r':
case 'R':
if (!this.isLoading) {
this.getTrendingInfo()
}
break
}
},
...mapActions([ ...mapActions([
'showToast', 'showToast',
'invidiousAPICall', 'invidiousAPICall',