Fix: trending cache (#2125)
* fix trending cache * fix displaying trending from cache * fix trending "resync"
This commit is contained in:
		
							parent
							
								
									06a7298ded
								
							
						
					
					
						commit
						4ba2cb29c6
					
				| 
						 | 
					@ -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
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
				
			||||||
 | 
					      if (this.trendingCache[this.currentTab] && this.trendingCache[this.currentTab].length > 0) {
 | 
				
			||||||
 | 
					        this.getTrendingInfoCache()
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
        this.getTrendingInfo()
 | 
					        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) => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue