FreeTube/src/renderer/views/Popular/Popular.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-02-16 19:30:00 +01:00
import Vue from 'vue'
import FtLoader from '../../components/ft-loader/ft-loader.vue'
import FtCard from '../../components/ft-card/ft-card.vue'
import FtElementList from '../../components/ft-element-list/ft-element-list.vue'
import FtIconButton from '../../components/ft-icon-button/ft-icon-button.vue'
2020-02-16 19:30:00 +01:00
export default Vue.extend({
name: 'Popular',
components: {
'ft-loader': FtLoader,
'ft-card': FtCard,
'ft-element-list': FtElementList,
'ft-icon-button': FtIconButton
2020-02-16 19:30:00 +01:00
},
data: function () {
return {
isLoading: false,
shownResults: []
}
},
computed: {
popularCache: function () {
return this.$store.getters.getPopularCache
}
},
2020-02-16 19:30:00 +01:00
mounted: function () {
2020-08-18 17:51:56 +02:00
this.shownResults = this.popularCache
if (!this.shownResults || this.shownResults.length < 1) {
2020-08-22 22:10:52 +02:00
this.fetchPopularInfo()
2020-08-18 17:51:56 +02:00
}
2020-02-16 19:30:00 +01:00
},
methods: {
2020-08-22 22:10:52 +02:00
fetchPopularInfo: async function () {
2020-02-16 19:30:00 +01:00
const searchPayload = {
resource: 'popular',
id: '',
params: {}
}
2020-08-18 17:51:56 +02:00
this.isLoading = true
const result = await this.$store.dispatch('invidiousAPICall', searchPayload).catch((err) => {
console.log(err)
})
2020-02-16 19:30:00 +01:00
if (!result) {
2020-08-18 17:51:56 +02:00
this.isLoading = false
return
}
2020-02-16 19:30:00 +01:00
console.log(result)
2020-02-16 19:30:00 +01:00
2020-08-18 17:51:56 +02:00
this.shownResults = result.filter((item) => {
return item.type === 'video' || item.type === 'shortVideo' || item.type === 'channel' || item.type === 'playlist'
2020-02-16 19:30:00 +01:00
})
this.isLoading = false
2020-08-18 17:51:56 +02:00
this.$store.commit('setPopularCache', this.shownResults)
2020-02-16 19:30:00 +01:00
}
}
})