new backend pagination approach (#49)
* new backend pagination approach * prettier
This commit is contained in:
@@ -115,13 +115,14 @@ export const getArtistReleasesInfiniteQuery = (getArtistId: Getter<string>) =>
|
||||
);
|
||||
return response;
|
||||
},
|
||||
getNextPageParam: (lastPage, allPages) => {
|
||||
const wasLastPageEmpty =
|
||||
lastPage.albums.length === 0 && lastPage.singles.length === 0 && lastPage.eps.length === 0;
|
||||
if (!lastPage.has_more || wasLastPageEmpty) {
|
||||
getNextPageParam: (lastPage) => {
|
||||
if (!lastPage.has_more) {
|
||||
return undefined;
|
||||
}
|
||||
return allPages.length * BATCH_SIZE;
|
||||
if (lastPage.next_offset != null) {
|
||||
return lastPage.next_offset;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
@@ -162,8 +162,12 @@ export type ArtistReleases = {
|
||||
albums: ReleaseGroup[];
|
||||
singles: ReleaseGroup[];
|
||||
eps: ReleaseGroup[];
|
||||
total_count: number;
|
||||
offset: number;
|
||||
limit: number;
|
||||
returned_count: number;
|
||||
next_offset: number | null;
|
||||
has_more: boolean;
|
||||
source_total_count: number | null;
|
||||
};
|
||||
|
||||
export type UserPreferences = {
|
||||
|
||||
@@ -128,8 +128,6 @@
|
||||
releasesQuery.data?.pages.flatMap((page) => [...page.albums, ...page.singles, ...page.eps])
|
||||
.length || 0
|
||||
);
|
||||
// Total count is not reliable, since it contains items that are filtered out
|
||||
const totalReleaseCount = $derived(releasesQuery.data?.pages[0].total_count || 0);
|
||||
|
||||
$effect(() => {
|
||||
if (hasMoreReleases && !releasesQuery.isFetchingNextPage) {
|
||||
@@ -340,8 +338,7 @@
|
||||
<span class="font-semibold text-base" style="color: {colors.accent};"
|
||||
>Loading releases...</span
|
||||
>
|
||||
<span class="text-sm text-base-content/70"
|
||||
>Loaded {loadedReleaseCount} of {totalReleaseCount} potential releases</span
|
||||
<span class="text-sm text-base-content/70">Loading {loadedReleaseCount} releases</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user