Fix: trending cache (#2125)

* fix trending cache

* fix displaying trending from cache

* fix trending "resync"
This commit is contained in:
ChunkyProgrammer 2022-04-09 15:34:55 -04:00 committed by GitHub
parent 06a7298ded
commit 4ba2cb29c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View File

@ -982,7 +982,7 @@ const mutations = {
state.popularCache = value state.popularCache = value
}, },
setTrendingCache (state, value, page) { setTrendingCache (state, { value, page }) {
state.trendingCache[page] = value state.trendingCache[page] = value
}, },

View File

@ -53,7 +53,7 @@ export default Vue.extend({
}, },
mounted: function () { mounted: function () {
if (this.trendingCache[this.currentTab] && this.trendingCache[this.currentTab].length > 0) { if (this.trendingCache[this.currentTab] && this.trendingCache[this.currentTab].length > 0) {
this.shownResults = this.trendingCache this.getTrendingInfoCache()
} else { } else {
this.getTrendingInfo() this.getTrendingInfo()
} }
@ -92,7 +92,11 @@ export default Vue.extend({
currentTabNode.attr('aria-selected', 'false') currentTabNode.attr('aria-selected', 'false')
newTabNode.attr('aria-selected', 'true') newTabNode.attr('aria-selected', 'true')
this.currentTab = tab this.currentTab = tab
this.getTrendingInfo() if (this.trendingCache[this.currentTab] && this.trendingCache[this.currentTab].length > 0) {
this.getTrendingInfoCache()
} else {
this.getTrendingInfo()
}
}, },
getTrendingInfo () { getTrendingInfo () {
@ -127,7 +131,8 @@ export default Vue.extend({
this.shownResults = returnData this.shownResults = returnData
this.isLoading = false this.isLoading = false
this.$store.commit('setTrendingCache', this.shownResults, this.currentTab) const currentTab = this.currentTab
this.$store.commit('setTrendingCache', { value: returnData, page: currentTab })
}).then(() => { }).then(() => {
document.querySelector(`#${this.currentTab}Tab`).focus() document.querySelector(`#${this.currentTab}Tab`).focus()
}).catch((err) => { }).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 () { getTrendingInfoInvidious: function () {
this.isLoading = true this.isLoading = true
@ -177,7 +190,8 @@ export default Vue.extend({
this.shownResults = returnData this.shownResults = returnData
this.isLoading = false this.isLoading = false
this.$store.commit('setTrendingCache', this.shownResults, this.trendingCache) const currentTab = this.currentTab
this.$store.commit('setTrendingCache', { value: returnData, page: currentTab })
}).then(() => { }).then(() => {
document.querySelector(`#${this.currentTab}Tab`).focus() document.querySelector(`#${this.currentTab}Tab`).focus()
}).catch((err) => { }).catch((err) => {