From 4ba2cb29c6cf2ce6fb7943b09e8a68f7f0ccfcad Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Sat, 9 Apr 2022 15:34:55 -0400 Subject: [PATCH] Fix: trending cache (#2125) * fix trending cache * fix displaying trending from cache * fix trending "resync" --- src/renderer/store/modules/utils.js | 2 +- src/renderer/views/Trending/Trending.js | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/renderer/store/modules/utils.js b/src/renderer/store/modules/utils.js index 5cc78f7ba..0f057667c 100644 --- a/src/renderer/store/modules/utils.js +++ b/src/renderer/store/modules/utils.js @@ -982,7 +982,7 @@ const mutations = { state.popularCache = value }, - setTrendingCache (state, value, page) { + setTrendingCache (state, { value, page }) { state.trendingCache[page] = value }, diff --git a/src/renderer/views/Trending/Trending.js b/src/renderer/views/Trending/Trending.js index fa17c6920..cf03f44f8 100644 --- a/src/renderer/views/Trending/Trending.js +++ b/src/renderer/views/Trending/Trending.js @@ -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() } @@ -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 () { @@ -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) => { @@ -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 @@ -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) => {