Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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