feat: loading skeletons on the bookmarks and collections pages

Both loaders now stream the whole result (the single fetch is also the auth
gate) so the page shows a skeleton while it loads instead of the global nav
bar only: a ListRowSkeleton on bookmarks and a MangaGridSkeleton on the
collections grid, resolving to the sign-in / error / empty / list branches.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
MechaCat02
2026-07-07 07:18:43 +02:00
parent 5b51bcf056
commit 16cdec051a
10 changed files with 212 additions and 63 deletions

View File

@@ -1,26 +1,30 @@
<script lang="ts">
import CollectionsGrid from '$lib/components/CollectionsGrid.svelte';
import MangaGridSkeleton from '$lib/components/MangaGridSkeleton.svelte';
let { data } = $props();
const collections = $derived(data.collections);
</script>
<h1>Collections</h1>
{#if !data.authenticated}
<p class="status">
<a href="/login">Sign in</a> to see and manage your collections.
</p>
{:else if data.error}
<p class="error" role="alert">{data.error}</p>
{:else if collections.length === 0}
<p class="status" data-testid="collections-empty">
You don't have any collections yet. Open any manga and use
<strong>Add to collection</strong> to start one.
</p>
{:else}
<CollectionsGrid {collections} />
{/if}
{#await data.result}
<MangaGridSkeleton count={6} />
{:then r}
{#if !r.authenticated}
<p class="status">
<a href="/login">Sign in</a> to see and manage your collections.
</p>
{:else if r.error}
<p class="error" role="alert">{r.error}</p>
{:else if r.collections.length === 0}
<p class="status" data-testid="collections-empty">
You don't have any collections yet. Open any manga and use
<strong>Add to collection</strong> to start one.
</p>
{:else}
<CollectionsGrid collections={r.collections} />
{/if}
{/await}
<style>
.status {

View File

@@ -5,16 +5,22 @@ import type { PageLoad } from './$types';
export const ssr = false;
export const load: PageLoad = async () => {
try {
const page = await listMyCollections({ limit: 200 });
return { collections: page.items, authenticated: true, error: null };
} catch (e) {
if (e instanceof ApiError && e.status === 401) {
return { collections: [], authenticated: false, error: null };
}
if (e instanceof ApiError) {
return { collections: [], authenticated: true, error: e.message };
}
throw e;
}
// Streamed so the grid shows a skeleton while the single fetch (also the
// auth gate) is in flight.
return {
result: (async () => {
try {
const page = await listMyCollections({ limit: 200 });
return { collections: page.items, authenticated: true, error: null as string | null };
} catch (e) {
if (e instanceof ApiError && e.status === 401) {
return { collections: [], authenticated: false, error: null as string | null };
}
if (e instanceof ApiError) {
return { collections: [], authenticated: true, error: e.message };
}
throw e;
}
})()
};
};