File tree Expand file tree Collapse file tree 3 files changed +60
-1
lines changed Expand file tree Collapse file tree 3 files changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -25,11 +25,16 @@ export default Vue.extend({
25
25
}
26
26
} ,
27
27
mounted : function ( ) {
28
+ document . addEventListener ( 'keydown' , this . keyboardShortcutHandler )
29
+
28
30
this . shownResults = this . popularCache
29
31
if ( ! this . shownResults || this . shownResults . length < 1 ) {
30
32
this . fetchPopularInfo ( )
31
33
}
32
34
} ,
35
+ beforeDestroy : function ( ) {
36
+ document . removeEventListener ( 'keydown' , this . keyboardShortcutHandler )
37
+ } ,
33
38
methods : {
34
39
fetchPopularInfo : async function ( ) {
35
40
const searchPayload = {
@@ -56,6 +61,21 @@ export default Vue.extend({
56
61
this . $store . commit ( 'setPopularCache' , this . shownResults )
57
62
} ,
58
63
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
+
59
79
...mapActions ( [
60
80
'invidiousAPICall'
61
81
] )
Original file line number Diff line number Diff line change @@ -98,6 +98,8 @@ export default Vue.extend({
98
98
}
99
99
} ,
100
100
mounted : async function ( ) {
101
+ document . addEventListener ( 'keydown' , this . keyboardShortcutHandler )
102
+
101
103
this . isLoading = true
102
104
const dataLimit = sessionStorage . getItem ( 'subscriptionLimit' )
103
105
if ( dataLimit !== null ) {
@@ -132,6 +134,9 @@ export default Vue.extend({
132
134
this . isLoading = false
133
135
}
134
136
} ,
137
+ beforeDestroy : function ( ) {
138
+ document . removeEventListener ( 'keydown' , this . keyboardShortcutHandler )
139
+ } ,
135
140
methods : {
136
141
goToChannel : function ( id ) {
137
142
this . $router . push ( { path : `/channel/${ id } ` } )
@@ -471,6 +476,21 @@ export default Vue.extend({
471
476
sessionStorage . setItem ( 'subscriptionLimit' , this . dataLimit )
472
477
} ,
473
478
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
+
474
494
...mapActions ( [
475
495
'showToast' ,
476
496
'invidiousAPICall' ,
Original file line number Diff line number Diff line change @@ -42,12 +42,17 @@ export default Vue.extend({
42
42
}
43
43
} ,
44
44
mounted : function ( ) {
45
+ document . addEventListener ( 'keydown' , this . keyboardShortcutHandler )
46
+
45
47
if ( this . trendingCache [ this . currentTab ] && this . trendingCache [ this . currentTab ] . length > 0 ) {
46
48
this . getTrendingInfoCache ( )
47
49
} else {
48
50
this . getTrendingInfo ( )
49
51
}
50
52
} ,
53
+ beforeDestroy : function ( ) {
54
+ document . removeEventListener ( 'keydown' , this . keyboardShortcutHandler )
55
+ } ,
51
56
methods : {
52
57
changeTab : function ( tab ) {
53
58
this . currentTab = tab
@@ -125,7 +130,6 @@ export default Vue.extend({
125
130
} )
126
131
} )
127
132
} ,
128
-
129
133
getTrendingInfoInvidious : function ( ) {
130
134
this . isLoading = true
131
135
@@ -176,6 +180,21 @@ export default Vue.extend({
176
180
} )
177
181
} ,
178
182
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
+
179
198
...mapActions ( [
180
199
'showToast' ,
181
200
'invidiousAPICall' ,
You can’t perform that action at this time.
0 commit comments