Skip to content

Commit 3fe9216

Browse files
committed
avoid unnecessary api calls on page end
1 parent 1bf7198 commit 3fe9216

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

src/library/album/AlbumLibrary.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
return this.$api.getAlbums(this.sort as AlbumSort, 50, this.offset).then(albums => {
5959
this.albums.push(...albums)
6060
this.offset += albums.length
61-
this.hasMore = albums.length > 0
61+
this.hasMore = albums.length >= 50
6262
this.loading = false
6363
})
6464
}

src/library/search/SearchResult.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<TrackList :tracks="result.tracks" />
3131
</div>
3232

33-
<EmptyIndicator v-if="!loading && !hasResult" label="No results" />
33+
<EmptyIndicator v-if="!loading && !hasResult && !hasMore" label="No results" />
3434

3535
<InfiniteLoader :loading="loading" :has-more="hasMore" @load-more="loadMore" />
3636
</div>
@@ -89,15 +89,15 @@
8989
methods: {
9090
async loadMore() {
9191
this.loading = true
92-
const result = await this.$api.search(this.query, this.type, this.offset)
92+
const result = await this.$api.search(this.query, this.type, 20, this.offset)
9393
const size = result.albums.length + result.artists.length + result.tracks.length
9494
9595
this.result.albums.push(...result.albums)
9696
this.result.artists.push(...result.artists)
9797
this.result.tracks.push(...result.tracks)
9898
9999
this.offset += size
100-
this.hasMore = size > 0
100+
this.hasMore = size >= 20
101101
this.loading = false
102102
}
103103
}

src/shared/api.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,7 @@ export class API {
390390
await this.fetch('rest/unstar', params)
391391
}
392392

393-
async search(query: string, type?: string, offset?: number): Promise<SearchResult> {
394-
const size = 20
393+
async search(query: string, type: string | null, size: number, offset?: number): Promise<SearchResult> {
395394
const params = {
396395
query,
397396
albumCount: !type || type === 'album' ? size : 0,

0 commit comments

Comments
 (0)