Refactor popular page

This commit is contained in:
Mykyta Poturai 2020-08-18 18:51:56 +03:00
parent 739dddf74c
commit 5bc2e70e88
3 changed files with 13 additions and 22 deletions

View File

@ -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: '',

View File

@ -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)
}
}
})

View File

@ -16,7 +16,8 @@
<ft-icon-button
icon="sync"
class="floatingTopButton"
:size="10"
:size="12"
:theme="primary"
@click="refreshTrendingInfo"
/>
</div>