web-player: normalize tracks, albums and playlists into single domain types at the server boundary
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { createApiClient, optionalUser, unwrapOrError } from '$lib/server/api';
|
||||
import { toPage } from '$lib/server/mappers';
|
||||
import { fetchFollowList } from '$lib/server/follows';
|
||||
import { FOLLOW_LIST_PAGE_SIZE } from '$lib/config';
|
||||
|
||||
@@ -19,7 +20,9 @@ export const load: PageServerLoad = async ({ params, locals, url, fetch, parent
|
||||
return {
|
||||
list: params.list,
|
||||
profile,
|
||||
users: forbidden ? null : unwrapOrError(listRes, 'No se pudo cargar la lista.'),
|
||||
users: forbidden
|
||||
? null
|
||||
: toPage(unwrapOrError(listRes, 'No se pudo cargar la lista.'), (item) => item),
|
||||
forbidden,
|
||||
viewerId: viewer?.sub ?? null
|
||||
};
|
||||
|
||||
@@ -20,13 +20,13 @@
|
||||
|
||||
$effect(() => {
|
||||
items = data.users?.items ?? [];
|
||||
page = Number(data.users?.pageNumber ?? 1);
|
||||
page = data.users?.pageNumber ?? 1;
|
||||
hasMore = data.users?.hasNextPage ?? false;
|
||||
});
|
||||
|
||||
const isFollowers = $derived(data.list === 'followers');
|
||||
const title = $derived(isFollowers ? 'Seguidores' : 'Siguiendo');
|
||||
const total = $derived(Number(data.users?.totalItemCount ?? 0));
|
||||
const total = $derived(data.users?.totalItemCount ?? 0);
|
||||
|
||||
async function loadMore() {
|
||||
if (loadingMore) return;
|
||||
@@ -36,7 +36,7 @@
|
||||
if (!res.ok) throw new Error(String(res.status));
|
||||
const next = (await res.json()) as NonNullable<typeof data.users>;
|
||||
items = appendUnique(items, next.items, (u) => u.id);
|
||||
page = Number(next.pageNumber);
|
||||
page = next.pageNumber;
|
||||
hasMore = next.hasNextPage;
|
||||
} catch {
|
||||
hasMore = false;
|
||||
|
||||
Reference in New Issue
Block a user