Merge pull request #77 from Deedone/master

Adding caches
This commit is contained in:
Preston 2020-08-24 17:14:13 -04:00 committed by GitHub
commit 34a77c3051
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 98 additions and 30 deletions

View File

@ -3,6 +3,8 @@ import FtToastEvents from '../../components/ft-toast/ft-toast-events'
const state = { const state = {
isSideNavOpen: false, isSideNavOpen: false,
sessionSearchHistory: [], sessionSearchHistory: [],
popularCache: null,
trendingCache: null,
searchSettings: { searchSettings: {
sortBy: 'relevance', sortBy: 'relevance',
time: '', time: '',
@ -42,6 +44,14 @@ const getters = {
return state.sessionSearchHistory return state.sessionSearchHistory
}, },
getPopularCache () {
return state.popularCache
},
getTrendingCache () {
return state.trendingCache
},
getSearchSettings () { getSearchSettings () {
return state.searchSettings return state.searchSettings
} }
@ -261,6 +271,14 @@ const mutations = {
} }
}, },
setPopularCache (state, value) {
state.popularCache = value
},
setTrendingCache (state, value) {
state.trendingCache = value
},
setSearchSortBy (state, value) { setSearchSortBy (state, value) {
state.searchSettings.sortBy = value state.searchSettings.sortBy = value
}, },

View File

@ -4,6 +4,12 @@
margin-bottom: 60px; margin-bottom: 60px;
} }
.floatingTopButton {
position: absolute;
top: 70px;
right: 10px;
}
@media only screen and (max-width: 680px) { @media only screen and (max-width: 680px) {
.card { .card {
width: 90%; width: 90%;

View File

@ -2,13 +2,15 @@ import Vue from 'vue'
import FtLoader from '../../components/ft-loader/ft-loader.vue' import FtLoader from '../../components/ft-loader/ft-loader.vue'
import FtCard from '../../components/ft-card/ft-card.vue' import FtCard from '../../components/ft-card/ft-card.vue'
import FtElementList from '../../components/ft-element-list/ft-element-list.vue' import FtElementList from '../../components/ft-element-list/ft-element-list.vue'
import FtIconButton from '../../components/ft-icon-button/ft-icon-button.vue'
export default Vue.extend({ export default Vue.extend({
name: 'Popular', name: 'Popular',
components: { components: {
'ft-loader': FtLoader, 'ft-loader': FtLoader,
'ft-card': FtCard, 'ft-card': FtCard,
'ft-element-list': FtElementList 'ft-element-list': FtElementList,
'ft-icon-button': FtIconButton
}, },
data: function () { data: function () {
return { return {
@ -16,35 +18,42 @@ export default Vue.extend({
shownResults: [] shownResults: []
} }
}, },
computed: {
popularCache: function () {
return this.$store.getters.getPopularCache
}
},
mounted: function () { mounted: function () {
this.getTrendingInfo() this.shownResults = this.popularCache
if (!this.shownResults || this.shownResults.length < 1) {
this.fetchPopularInfo()
}
}, },
methods: { methods: {
getTrendingInfo: function () { fetchPopularInfo: async function () {
this.isLoading = true
const searchPayload = { const searchPayload = {
resource: 'popular', resource: 'popular',
id: '', id: '',
params: {} params: {}
} }
this.$store.dispatch('invidiousAPICall', searchPayload).then((result) => { this.isLoading = true
if (!result) { const result = await this.$store.dispatch('invidiousAPICall', searchPayload).catch((err) => {
return
}
console.log(result)
const returnData = result.filter((item) => {
return item.type === 'video' || item.type === 'shortVideo' || item.type === 'channel' || item.type === 'playlist'
})
this.shownResults = this.shownResults.concat(returnData)
this.isLoading = false
}).catch((err) => {
console.log(err) console.log(err)
}) })
if (!result) {
this.isLoading = false
return
}
console.log(result)
this.shownResults = result.filter((item) => {
return item.type === 'video' || item.type === 'shortVideo' || item.type === 'channel' || item.type === 'playlist'
})
this.isLoading = false
this.$store.commit('setPopularCache', this.shownResults)
} }
} }
}) })

View File

@ -13,6 +13,13 @@
:data="shownResults" :data="shownResults"
/> />
</ft-card> </ft-card>
<ft-icon-button
icon="sync"
class="floatingTopButton"
:size="12"
theme="primary"
@click="fetchPopularInfo"
/>
</div> </div>
</template> </template>

View File

@ -4,6 +4,12 @@
margin-bottom: 60px; margin-bottom: 60px;
} }
.floatingTopButton {
position: absolute;
top: 70px;
right: 10px;
}
@media only screen and (max-width: 680px) { @media only screen and (max-width: 680px) {
.card { .card {
width: 90%; width: 90%;

View File

@ -2,6 +2,7 @@ import Vue from 'vue'
import FtCard from '../../components/ft-card/ft-card.vue' import FtCard from '../../components/ft-card/ft-card.vue'
import FtLoader from '../../components/ft-loader/ft-loader.vue' import FtLoader from '../../components/ft-loader/ft-loader.vue'
import FtElementList from '../../components/ft-element-list/ft-element-list.vue' import FtElementList from '../../components/ft-element-list/ft-element-list.vue'
import FtIconButton from '../../components/ft-icon-button/ft-icon-button.vue'
import ytrend from 'yt-trending-scraper' import ytrend from 'yt-trending-scraper'
@ -10,7 +11,8 @@ export default Vue.extend({
components: { components: {
'ft-card': FtCard, 'ft-card': FtCard,
'ft-loader': FtLoader, 'ft-loader': FtLoader,
'ft-element-list': FtElementList 'ft-element-list': FtElementList,
'ft-icon-button': FtIconButton
}, },
data: function () { data: function () {
return { return {
@ -30,23 +32,34 @@ export default Vue.extend({
}, },
invidiousInstance: function () { invidiousInstance: function () {
return this.$store.getters.getInvidiousInstance return this.$store.getters.getInvidiousInstance
},
trendingCache () {
return this.$store.getters.getTrendingCache
} }
}, },
mounted: function () { mounted: function () {
if (!this.usingElectron) { if (this.trendingCache && this.trendingCache.length > 0) {
this.getVideoInformationInvidious() this.shownResults = this.trendingCache
} else { } else {
switch (this.backendPreference) { this.getTrendingInfo()
case 'local':
this.getTrendingInfoLocal()
break
case 'invidious':
this.getTrendingInfoInvidious()
break
}
} }
}, },
methods: { methods: {
getTrendingInfo () {
if (!this.usingElectron) {
this.getVideoInformationInvidious()
} else {
switch (this.backendPreference) {
case 'local':
this.getTrendingInfoLocal()
break
case 'invidious':
this.getTrendingInfoInvidious()
break
}
}
},
getTrendingInfoLocal: function () { getTrendingInfoLocal: function () {
this.isLoading = true this.isLoading = true
@ -59,6 +72,7 @@ export default Vue.extend({
this.shownResults = this.shownResults.concat(returnData) this.shownResults = this.shownResults.concat(returnData)
this.isLoading = false this.isLoading = false
this.$store.commit('setTrendingCache', this.shownResults)
}).catch((err) => { }).catch((err) => {
console.log(err) console.log(err)
const errorMessage = this.$t('Local API Error (Click to copy)') const errorMessage = this.$t('Local API Error (Click to copy)')
@ -102,6 +116,7 @@ export default Vue.extend({
this.shownResults = this.shownResults.concat(returnData) this.shownResults = this.shownResults.concat(returnData)
this.isLoading = false this.isLoading = false
this.$store.commit('setTrendingCache', this.shownResults)
}).catch((err) => { }).catch((err) => {
console.log(err) console.log(err)
const errorMessage = this.$t('Invidious API Error (Click to copy)') const errorMessage = this.$t('Invidious API Error (Click to copy)')

View File

@ -13,6 +13,13 @@
:data="shownResults" :data="shownResults"
/> />
</ft-card> </ft-card>
<ft-icon-button
icon="sync"
class="floatingTopButton"
:size="12"
theme="primary"
@click="getTrendingInfo"
/>
</div> </div>
</template> </template>