Skip to content

Commit

Permalink
Fix: trending cache (#2125)
Browse files Browse the repository at this point in the history
* fix trending cache

* fix displaying trending from cache

* fix trending "resync"
  • Loading branch information
ChunkyProgrammer authored Apr 9, 2022
1 parent 06a7298 commit 4ba2cb2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/renderer/store/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ const mutations = {
state.popularCache = value
},

setTrendingCache (state, value, page) {
setTrendingCache (state, { value, page }) {
state.trendingCache[page] = value
},

Expand Down
22 changes: 18 additions & 4 deletions src/renderer/views/Trending/Trending.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default Vue.extend({
},
mounted: function () {
if (this.trendingCache[this.currentTab] && this.trendingCache[this.currentTab].length > 0) {
this.shownResults = this.trendingCache
this.getTrendingInfoCache()
} else {
this.getTrendingInfo()
}
Expand Down Expand Up @@ -92,7 +92,11 @@ export default Vue.extend({
currentTabNode.attr('aria-selected', 'false')
newTabNode.attr('aria-selected', 'true')
this.currentTab = tab
this.getTrendingInfo()
if (this.trendingCache[this.currentTab] && this.trendingCache[this.currentTab].length > 0) {
this.getTrendingInfoCache()
} else {
this.getTrendingInfo()
}
},

getTrendingInfo () {
Expand Down Expand Up @@ -127,7 +131,8 @@ export default Vue.extend({

this.shownResults = returnData
this.isLoading = false
this.$store.commit('setTrendingCache', this.shownResults, this.currentTab)
const currentTab = this.currentTab
this.$store.commit('setTrendingCache', { value: returnData, page: currentTab })
}).then(() => {
document.querySelector(`#${this.currentTab}Tab`).focus()
}).catch((err) => {
Expand All @@ -151,6 +156,14 @@ export default Vue.extend({
})
},

getTrendingInfoCache: function() {
this.isLoading = true
setTimeout(() => {
this.shownResults = this.trendingCache[this.currentTab]
this.isLoading = false
})
},

getTrendingInfoInvidious: function () {
this.isLoading = true

Expand All @@ -177,7 +190,8 @@ export default Vue.extend({

this.shownResults = returnData
this.isLoading = false
this.$store.commit('setTrendingCache', this.shownResults, this.trendingCache)
const currentTab = this.currentTab
this.$store.commit('setTrendingCache', { value: returnData, page: currentTab })
}).then(() => {
document.querySelector(`#${this.currentTab}Tab`).focus()
}).catch((err) => {
Expand Down

0 comments on commit 4ba2cb2

Please sign in to comment.