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 = { const state = {
isSideNavOpen: false, isSideNavOpen: false,
sessionSearchHistory: [], sessionSearchHistory: [],
popularCache: undefined, popularCache: null,
searchSettings: { searchSettings: {
sortBy: 'relevance', sortBy: 'relevance',
time: '', time: '',

View File

@ -24,12 +24,14 @@ export default Vue.extend({
} }
}, },
mounted: function () { mounted: function () {
this.getTrendingInfo() this.shownResults = this.popularCache
if (!this.shownResults || this.shownResults.length < 1) {
this.fetchTrendingInfo()
}
}, },
methods: { methods: {
refreshTrendingInfo: async function () { refreshTrendingInfo: function () {
await this.fetchTrendingInfo() this.fetchTrendingInfo()
await this.getTrendingInfo()
}, },
fetchTrendingInfo: async function () { fetchTrendingInfo: async function () {
const searchPayload = { const searchPayload = {
@ -38,35 +40,23 @@ export default Vue.extend({
params: {} params: {}
} }
this.isLoading = true
const result = await this.$store.dispatch('invidiousAPICall', searchPayload).catch((err) => { const result = await this.$store.dispatch('invidiousAPICall', searchPayload).catch((err) => {
console.log(err) console.log(err)
}) })
if (!result) { if (!result) {
this.isLoading = false
return return
} }
console.log(result) 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' 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.isLoading = false
this.$store.commit('setPopularCache', this.shownResults)
} }
} }
}) })

View File

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