Files
minstrel/web/src/lib/components/AlphaLibrary.svelte
T
bvandeusenandClaude Opus 5.5 6996561cb1
release / web (push) Successful in 1m19s
release / go (push) Successful in 1m45s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m56s
release / android (push) Successful in 4m34s
release / Build signed APK (push) Successful in 5m3s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 25s
release / Verify release artifacts (tag releases only) (push) Skipped
refactor: one cover fallback icon on Android, one paged-query type on the web
Ten Android covers wrote out the same muted icon for missing artwork;
they now call CoverFallbackIcon beside CoverTile, and ShelfPlaylistCards'
NoArtIcon wrapper is gone. AlbumDrillDown and AlphaLibrary each declared
the infinite-query shape they read; both now take PagedQuery<T> from
api/types. Folds the two small copies the M664 DRY close-out found (#8006).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 11:48:17 -05:00

121 lines
4.1 KiB
Svelte
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script lang="ts" generics="T">
import type { Snippet } from 'svelte';
import { plural } from '#lib/utils/plural.js';
import AlphabeticalGrid from './AlphabeticalGrid.svelte';
import ApiErrorBanner from './ApiErrorBanner.svelte';
import ListContinuation from './ListContinuation.svelte';
import QuickFilter from './QuickFilter.svelte';
import EmptyState from './EmptyState.svelte';
import { user } from '#lib/auth/user.svelte.js';
import { useDelayed } from '#lib/utils/useDelayed.svelte.js';
import type { PagedQuery } from '#lib/api/types.js';
// A whole-library A–Z page (Library › Albums, Library › Artists): the
// count, a filter over what has loaded, the lettered grid paged as you
// scroll, and the empty states. A filter that matches nothing loaded links
// to the full search, since the rest of the library may not have loaded.
let {
query,
title,
one,
many,
matches,
getKey,
searchPath,
item
}: {
query: PagedQuery<T>;
title: string;
/** The noun for one and for many: 'album', 'albums'. */
one: string;
many: string;
/** Whether an item matches the filter text (already lower-cased). */
matches: (it: T, q: string) => boolean;
getKey: (it: T) => string;
/** The full-library search for this noun, e.g. '/search/albums'. */
searchPath: string;
item: Snippet<[T]>;
} = $props();
const items = $derived(query.data?.pages?.flatMap((p) => p.items) ?? []);
const total = $derived(query.data?.pages?.[0]?.total ?? 0);
const showSkeleton = useDelayed(() => query.isPending);
// A failed first page replaces the list; a failed later page keeps it.
const failed = $derived(query.isError && !query.isFetchNextPageError);
let filter = $state('');
const filtered = $derived.by(() => {
const q = filter.trim().toLowerCase();
return q ? items.filter((it) => matches(it, q)) : items;
});
</script>
<div class="space-y-4">
<header class="flex flex-wrap items-end justify-between gap-3">
<div>
<h1 class="font-display text-2xl font-medium text-text-primary">{title}</h1>
{#if !query.isPending && !failed}
<p class="text-sm text-text-secondary">{plural(total, one, many)}</p>
{/if}
</div>
{#if items.length > 0}
<QuickFilter bind:value={filter} placeholder={`Filter ${many}`} />
{/if}
</header>
{#if failed}
<ApiErrorBanner error={query.error} onRetry={query.refetch} />
{:else if showSkeleton.value && items.length === 0}
<p class="text-text-secondary">Loading…</p>
{:else if !query.isPending && total === 0}
<!-- Library folders are server config (library.scan_paths), not a
setting, so only an admin can act: they run a scan from Admin.
Everyone else is told whose job it is. -->
{#if user.value?.is_admin}
<EmptyState
title={`No ${many} yet`}
hint={`Library folders are set in the server's config. Once they're scanned, ${many} appear here.`}
>
{#snippet actions()}
<a
href="/admin"
class="inline-flex items-center rounded-md bg-action-secondary px-4 py-2 text-sm text-action-fg hover:opacity-90"
>
Run a scan
</a>
{/snippet}
</EmptyState>
{:else}
<EmptyState
title={`No ${many} yet`}
hint={`Once your server's admin has scanned the library, ${many} appear here.`}
/>
{/if}
{:else if filter.trim() && filtered.length === 0}
<p class="text-text-secondary">
No {many} in your loaded library match
<span class="font-medium">'{filter.trim()}'</span>.
<a href={`${searchPath}?q=${encodeURIComponent(filter.trim())}`} class="text-accent-fg hover:underline">
Search the full library →
</a>
</p>
{:else}
<AlphabeticalGrid
items={filtered}
{getKey}
hasMore={query.hasNextPage}
onLoadMore={() => query.fetchNextPage()}
{item}
/>
<ListContinuation
hasMore={query.hasNextPage}
loading={query.isFetchingNextPage}
failed={query.isFetchNextPageError}
onMore={() => query.fetchNextPage()}
endLabel="End of library"
/>
{/if}
</div>