Refactor popular page
This commit is contained in:
		
							parent
							
								
									739dddf74c
								
							
						
					
					
						commit
						5bc2e70e88
					
				|  | @ -3,7 +3,7 @@ import FtToastEvents from '../../components/ft-toast/ft-toast-events' | |||
| const state = { | ||||
|   isSideNavOpen: false, | ||||
|   sessionSearchHistory: [], | ||||
|   popularCache: undefined, | ||||
|   popularCache: null, | ||||
|   searchSettings: { | ||||
|     sortBy: 'relevance', | ||||
|     time: '', | ||||
|  |  | |||
|  | @ -24,12 +24,14 @@ export default Vue.extend({ | |||
|     } | ||||
|   }, | ||||
|   mounted: function () { | ||||
|     this.getTrendingInfo() | ||||
|     this.shownResults = this.popularCache | ||||
|     if (!this.shownResults || this.shownResults.length < 1) { | ||||
|       this.fetchTrendingInfo() | ||||
|     } | ||||
|   }, | ||||
|   methods: { | ||||
|     refreshTrendingInfo: async function () { | ||||
|       await this.fetchTrendingInfo() | ||||
|       await this.getTrendingInfo() | ||||
|     refreshTrendingInfo: function () { | ||||
|       this.fetchTrendingInfo() | ||||
|     }, | ||||
|     fetchTrendingInfo: async function () { | ||||
|       const searchPayload = { | ||||
|  | @ -38,35 +40,23 @@ export default Vue.extend({ | |||
|         params: {} | ||||
|       } | ||||
| 
 | ||||
|       this.isLoading = true | ||||
|       const result = await this.$store.dispatch('invidiousAPICall', searchPayload).catch((err) => { | ||||
|         console.log(err) | ||||
|       }) | ||||
| 
 | ||||
|       if (!result) { | ||||
|         this.isLoading = false | ||||
|         return | ||||
|       } | ||||
| 
 | ||||
|       console.log(result) | ||||
| 
 | ||||
|       const returnData = result.filter((item) => { | ||||
|       this.shownResults = result.filter((item) => { | ||||
|         return item.type === 'video' || item.type === 'shortVideo' || item.type === 'channel' || item.type === 'playlist' | ||||
|       }) | ||||
|       this.$store.commit('setPopularCache', returnData) | ||||
|       return returnData | ||||
|     }, | ||||
| 
 | ||||
|     getTrendingInfo: async function () { | ||||
|       this.isLoading = true | ||||
|       let data = this.popularCache | ||||
|       if (!data || data.length < 1) { | ||||
|         data = await this.fetchTrendingInfo() | ||||
|       } | ||||
|       if (!data) { | ||||
|         return | ||||
|       } | ||||
| 
 | ||||
|       this.shownResults = this.shownResults.concat(data) | ||||
|       this.isLoading = false | ||||
|       this.$store.commit('setPopularCache', this.shownResults) | ||||
|     } | ||||
|   } | ||||
| }) | ||||
|  |  | |||
|  | @ -16,7 +16,8 @@ | |||
|     <ft-icon-button | ||||
|       icon="sync" | ||||
|       class="floatingTopButton" | ||||
|       :size="10" | ||||
|       :size="12" | ||||
|       :theme="primary" | ||||
|       @click="refreshTrendingInfo" | ||||
|     /> | ||||
|   </div> | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue