Skip to content

Commit 7ca6440

Browse files
authored
Add shortcuts for refresh buttons on Subscription, Trending, and Popular 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
1 parent aa4a01b commit 7ca6440

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

src/renderer/views/Popular/Popular.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@ export default Vue.extend({
2525
}
2626
},
2727
mounted: function () {
28+
document.addEventListener('keydown', this.keyboardShortcutHandler)
29+
2830
this.shownResults = this.popularCache
2931
if (!this.shownResults || this.shownResults.length < 1) {
3032
this.fetchPopularInfo()
3133
}
3234
},
35+
beforeDestroy: function () {
36+
document.removeEventListener('keydown', this.keyboardShortcutHandler)
37+
},
3338
methods: {
3439
fetchPopularInfo: async function () {
3540
const searchPayload = {
@@ -56,6 +61,21 @@ export default Vue.extend({
5661
this.$store.commit('setPopularCache', this.shownResults)
5762
},
5863

64+
// This function should always be at the bottom of this file
65+
keyboardShortcutHandler: function (event) {
66+
if (event.ctrlKey || document.activeElement.classList.contains('ft-input')) {
67+
return
68+
}
69+
switch (event.key) {
70+
case 'r':
71+
case 'R':
72+
if (!this.isLoading) {
73+
this.fetchPopularInfo()
74+
}
75+
break
76+
}
77+
},
78+
5979
...mapActions([
6080
'invidiousAPICall'
6181
])

src/renderer/views/Subscriptions/Subscriptions.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ export default Vue.extend({
9898
}
9999
},
100100
mounted: async function () {
101+
document.addEventListener('keydown', this.keyboardShortcutHandler)
102+
101103
this.isLoading = true
102104
const dataLimit = sessionStorage.getItem('subscriptionLimit')
103105
if (dataLimit !== null) {
@@ -132,6 +134,9 @@ export default Vue.extend({
132134
this.isLoading = false
133135
}
134136
},
137+
beforeDestroy: function () {
138+
document.removeEventListener('keydown', this.keyboardShortcutHandler)
139+
},
135140
methods: {
136141
goToChannel: function (id) {
137142
this.$router.push({ path: `/channel/${id}` })
@@ -471,6 +476,21 @@ export default Vue.extend({
471476
sessionStorage.setItem('subscriptionLimit', this.dataLimit)
472477
},
473478

479+
// This function should always be at the bottom of this file
480+
keyboardShortcutHandler: function (event) {
481+
if (event.ctrlKey || document.activeElement.classList.contains('ft-input')) {
482+
return
483+
}
484+
switch (event.key) {
485+
case 'r':
486+
case 'R':
487+
if (!this.isLoading) {
488+
this.getSubscriptions()
489+
}
490+
break
491+
}
492+
},
493+
474494
...mapActions([
475495
'showToast',
476496
'invidiousAPICall',

src/renderer/views/Trending/Trending.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ export default Vue.extend({
4242
}
4343
},
4444
mounted: function () {
45+
document.addEventListener('keydown', this.keyboardShortcutHandler)
46+
4547
if (this.trendingCache[this.currentTab] && this.trendingCache[this.currentTab].length > 0) {
4648
this.getTrendingInfoCache()
4749
} else {
4850
this.getTrendingInfo()
4951
}
5052
},
53+
beforeDestroy: function () {
54+
document.removeEventListener('keydown', this.keyboardShortcutHandler)
55+
},
5156
methods: {
5257
changeTab: function (tab) {
5358
this.currentTab = tab
@@ -125,7 +130,6 @@ export default Vue.extend({
125130
})
126131
})
127132
},
128-
129133
getTrendingInfoInvidious: function () {
130134
this.isLoading = true
131135

@@ -176,6 +180,21 @@ export default Vue.extend({
176180
})
177181
},
178182

183+
// This function should always be at the bottom of this file
184+
keyboardShortcutHandler: function (event) {
185+
if (event.ctrlKey || document.activeElement.classList.contains('ft-input')) {
186+
return
187+
}
188+
switch (event.key) {
189+
case 'r':
190+
case 'R':
191+
if (!this.isLoading) {
192+
this.getTrendingInfo()
193+
}
194+
break
195+
}
196+
},
197+
179198
...mapActions([
180199
'showToast',
181200
'invidiousAPICall',

0 commit comments

Comments
 (0)