fix genre page only showing 10 albums

This commit is contained in:
Thomas Amland 2020-12-13 11:56:01 +01:00
parent e077fabdca
commit b65eb4580c
3 changed files with 47 additions and 10 deletions

View File

@ -19,9 +19,9 @@
</ContentLoader> </ContentLoader>
</template> </template>
<template v-else> <template v-else>
<ContentLoader v-slot :loading="albums == null"> <InfiniteList v-slot="{ items }" :load="loadAlbums">
<AlbumList :items="albums" /> <AlbumList :items="items" />
</ContentLoader> </InfiniteList>
</template> </template>
</div> </div>
</template> </template>
@ -29,11 +29,13 @@
import Vue from 'vue' import Vue from 'vue'
import AlbumList from '@/library/album/AlbumList.vue' import AlbumList from '@/library/album/AlbumList.vue'
import TrackList from '@/library/TrackList.vue' import TrackList from '@/library/TrackList.vue'
import InfiniteList from '@/shared/components/InfiniteList.vue'
export default Vue.extend({ export default Vue.extend({
components: { components: {
AlbumList, AlbumList,
TrackList, TrackList,
InfiniteList,
}, },
props: { props: {
id: { type: String, required: true }, id: { type: String, required: true },
@ -41,17 +43,18 @@
}, },
data() { data() {
return { return {
albums: null as null | any[],
tracks: null as null | any[], tracks: null as null | any[],
} }
}, },
created() { created() {
this.$api.getAlbumsByGenre(this.id).then(result => {
this.albums = result
})
this.$api.getTracksByGenre(this.id).then(result => { this.$api.getTracksByGenre(this.id).then(result => {
this.tracks = result this.tracks = result
}) })
},
methods: {
loadAlbums(offset: number) {
return this.$api.getAlbumsByGenre(this.id, 50, offset)
}
} }
}) })
</script> </script>

View File

@ -115,12 +115,12 @@ export class API {
.sort((a: any, b:any) => b.albumCount - a.albumCount) .sort((a: any, b:any) => b.albumCount - a.albumCount)
} }
async getAlbumsByGenre(id: string) { async getAlbumsByGenre(id: string, size: number, offset = 0) {
const params = { const params = {
type: 'byGenre', type: 'byGenre',
genre: id, genre: id,
count: 500, size,
offset: 0, offset,
} }
const response = await this.get('rest/getAlbumList2', params) const response = await this.get('rest/getAlbumList2', params)
return (response.albumList2?.album || []).map(this.normalizeAlbum, this) return (response.albumList2?.album || []).map(this.normalizeAlbum, this)

View File

@ -0,0 +1,34 @@
<template>
<div>
<slot :items="items" />
<InfiniteLoader :loading="loading" :has-more="hasMore" @load-more="loadMore" />
</div>
</template>
<script lang="ts">
import Vue from 'vue'
export default Vue.extend({
props: {
load: { type: Function, required: true },
},
data() {
return {
items: [] as any[],
loading: false,
offset: 0 as number,
hasMore: true,
}
},
methods: {
loadMore() {
this.loading = true
this.load(this.offset).then((items: any[]) => {
this.items.push(...items)
this.offset += items.length
this.hasMore = items.length > 0
this.loading = false
})
}
}
})
</script>