add infinite loading to album view

This commit is contained in:
Thomas Amland
2020-09-20 17:33:21 +02:00
parent 6c290689c4
commit 4be81d0e35
6 changed files with 83 additions and 16 deletions
+21 -10
View File
@@ -7,9 +7,8 @@
</router-link>
</li>
</ul>
<ContentLoader #default :loading="albums == null">
<AlbumList :items="albums" />
</ContentLoader>
<AlbumList :items="albums" />
<InfiniteLoader :key="sort" :loading="loading" :has-more="hasMore" @loadMore="loadMore" />
</div>
</template>
<script lang="ts">
@@ -26,7 +25,10 @@
},
data() {
return {
albums: null as null | Album[],
albums: [] as | Album[],
loading: false,
offset: 0 as number,
hasMore: true,
}
},
computed: {
@@ -42,14 +44,23 @@
},
watch: {
sort: {
immediate: true,
handler(value: AlbumSort) {
this.albums = null
this.$api.getAlbums(value).then(albums => {
this.albums = albums
})
handler() {
this.albums = []
this.offset = 0
this.hasMore = true
}
}
},
methods: {
loadMore() {
this.loading = true
this.$api.getAlbums(this.sort as AlbumSort, 50, this.offset).then(albums => {
this.albums.push(...albums)
this.offset += albums.length
this.hasMore = albums.length > 0
this.loading = false
})
}
}
})
</script>