Skip to content

Commit

Permalink
Add shortcuts for refresh buttons on Subscription, Trending, and Popu…
Browse files Browse the repository at this point in the history
…lar views (FreeTubeApp#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
  • Loading branch information
Aiz0 committed Oct 9, 2022
1 parent aa4a01b commit 7ca6440
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/renderer/views/Popular/Popular.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ export default Vue.extend({
}
},
mounted: function () {
document.addEventListener('keydown', this.keyboardShortcutHandler)

this.shownResults = this.popularCache
if (!this.shownResults || this.shownResults.length < 1) {
this.fetchPopularInfo()
}
},
beforeDestroy: function () {
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: {
fetchPopularInfo: async function () {
const searchPayload = {
Expand All @@ -56,6 +61,21 @@ export default Vue.extend({
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([
'invidiousAPICall'
])
Expand Down
20 changes: 20 additions & 0 deletions src/renderer/views/Subscriptions/Subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export default Vue.extend({
}
},
mounted: async function () {
document.addEventListener('keydown', this.keyboardShortcutHandler)

this.isLoading = true
const dataLimit = sessionStorage.getItem('subscriptionLimit')
if (dataLimit !== null) {
Expand Down Expand Up @@ -132,6 +134,9 @@ export default Vue.extend({
this.isLoading = false
}
},
beforeDestroy: function () {
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: {
goToChannel: function (id) {
this.$router.push({ path: `/channel/${id}` })
Expand Down Expand Up @@ -471,6 +476,21 @@ export default Vue.extend({
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([
'showToast',
'invidiousAPICall',
Expand Down
21 changes: 20 additions & 1 deletion src/renderer/views/Trending/Trending.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ export default Vue.extend({
}
},
mounted: function () {
document.addEventListener('keydown', this.keyboardShortcutHandler)

if (this.trendingCache[this.currentTab] && this.trendingCache[this.currentTab].length > 0) {
this.getTrendingInfoCache()
} else {
this.getTrendingInfo()
}
},
beforeDestroy: function () {
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: {
changeTab: function (tab) {
this.currentTab = tab
Expand Down Expand Up @@ -125,7 +130,6 @@ export default Vue.extend({
})
})
},

getTrendingInfoInvidious: function () {
this.isLoading = true

Expand Down Expand Up @@ -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([
'showToast',
'invidiousAPICall',
Expand Down

0 comments on commit 7ca6440

Please sign in to comment.