feat(web): shared collection header, Play and Shuffle, and the centred page column (M494)
release / govulncheck (push) Successful in 42s
release / web (push) Successful in 1m30s
release / go (push) Successful in 1m48s
release / integration (push) Successful in 5m51s
release / android (push) Successful in 6m53s
release / Build signed APK (releases and dev) (push) Successful in 7m14s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 1m29s
release / Verify release artifacts (tag releases only) (push) Skipped

- CollectionHeader holds cover, title, facts, then Play and Shuffle, for
  album and playlist. The playlist page gains Play and Shuffle; it had
  neither. The cover uses the shared Cover component, so the playlist
  header also gets the fallback image.
- PlayActions is the one Play and Shuffle pair: filled Play, outlined
  Shuffle, on album, playlist and artist pages (operator, 2026-10-08).
  The artist page's round icon button said Play but shuffled; Play now
  keeps the server's order, and Shuffle shuffles.
- PageColumn is the playlist page's centred column, now used by album,
  playlist, Liked, History and Search → Tracks.
- The playlist page builds its queue with playlistTrackToRef, the shared
  converter, in place of its own copy. Its copy skipped only removed
  tracks, so a missing file (#2527) could still be queued from there.
- shuffled() in lib/utils is the one shuffle, replacing three private
  copies (album page, artist page, ArtistCard).
- The album's refetch error now uses text-error-fg. `text-oxblood` is
  not a colour in the theme, so it never rendered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 14:18:44 -04:00
co-authored by Claude Opus 5.5
parent aaa6fa15d6
commit 918db27fec
14 changed files with 418 additions and 236 deletions
+96 -90
View File
@@ -1,4 +1,5 @@
<script lang="ts">
import PageColumn from '#lib/components/PageColumn.svelte';
import { page } from '$app/state';
import { goto } from '$app/navigation';
import { untrack } from 'svelte';
@@ -7,6 +8,9 @@
import { useQueryClient } from '@tanstack/svelte-query';
import PlaylistTrackRow from '#lib/components/PlaylistTrackRow.svelte';
import TrackList from '#lib/components/TrackList.svelte';
import CollectionHeader from '#lib/components/CollectionHeader.svelte';
import { playlistTrackToRef } from '#lib/playlists/playlistTrackToRef.js';
import { shuffled } from '#lib/utils/shuffle.js';
import ApiErrorBanner from '#lib/components/ApiErrorBanner.svelte';
import {
createPlaylistQuery,
@@ -75,23 +79,30 @@
}
}
function onPlay(position: number) {
if (!playlistQuery?.data) return;
const data = playlistQuery.data;
// Skip rows where track_id is null (track was removed from library).
const live = data.tracks.filter((t) => t.track_id !== null).map(toTrackRef);
// Find which `live` index corresponds to the clicked position. Some
// positions in the original list may be unavailable (filtered out),
// so the index in the playable list != the playlist position.
const clickedTrackID = data.tracks.find((t) => t.position === position)?.track_id;
const startIdx = live.findIndex((t) => t.id === clickedTrackID);
// Every entry that can be played, in playlist order. playlistTrackToRef
// drops both kinds of dead entry, removed tracks and missing files
// (#2527), so neither is ever queued.
function playable(data: PlaylistDetail): { refs: TrackRef[]; positions: number[] } {
const refs: TrackRef[] = [];
const positions: number[] = [];
for (const row of data.tracks) {
const ref = playlistTrackToRef(row);
if (ref) {
refs.push(ref);
positions.push(row.position);
}
}
return { refs, positions };
}
function startQueue(data: PlaylistDetail, tracks: TrackRef[], startIdx: number) {
// #968: a system playlist played from its detail page is tagged with its
// source (so play_started advances the rotation, matching the home tile and
// the Android detail screen) and gets the self-heal closure so a stale
// snapshot re-pulls on total failure.
const variant = data.system_variant;
if (variant != null) {
playQueue(live, Math.max(0, startIdx), {
playQueue(tracks, Math.max(0, startIdx), {
source: variant,
refetch: systemPlaylistRefetch({
variant,
@@ -100,30 +111,25 @@
})
});
} else {
playQueue(live, Math.max(0, startIdx));
playQueue(tracks, Math.max(0, startIdx));
}
}
function toTrackRef(t: {
track_id: string | null;
album_id: string | null;
artist_id: string | null;
title: string;
album_title: string;
artist_name: string;
duration_sec: number;
stream_url: string | null;
}): TrackRef {
return {
id: t.track_id!,
title: t.title,
album_id: t.album_id ?? '',
album_title: t.album_title,
artist_id: t.artist_id ?? '',
artist_name: t.artist_name,
duration_sec: t.duration_sec,
stream_url: t.stream_url ?? ''
} as unknown as TrackRef;
function onPlay(position: number) {
if (!playlistQuery?.data) return;
const data = playlistQuery.data;
const { refs, positions } = playable(data);
startQueue(data, refs, positions.indexOf(position));
}
function onPlayAll() {
if (!playlistQuery?.data) return;
startQueue(playlistQuery.data, playable(playlistQuery.data).refs, 0);
}
function onShuffle() {
if (!playlistQuery?.data) return;
startQueue(playlistQuery.data, shuffled(playable(playlistQuery.data).refs), 0);
}
let editing = $state(false);
@@ -229,7 +235,7 @@
<title>{pageTitle(playlistQuery?.data?.name ? `Playlist · ${playlistQuery.data.name}` : 'Playlist')}</title>
</svelte:head>
<div class="mx-auto max-w-4xl px-4 py-6">
<PageColumn>
{#if playlistQuery?.isPending}
<p class="text-text-muted">Loading…</p>
{:else if playlistQuery?.isError}
@@ -255,64 +261,64 @@
</div>
{/if}
{#if !editing}
<header class="mb-6 flex items-start gap-4">
<div class="h-32 w-32 shrink-0 overflow-hidden rounded-md bg-surface-hover">
{#if pl.cover_url}
<img src={pl.cover_url} alt="" class="h-full w-full object-cover" />
<CollectionHeader
title={pl.name}
coverUrl={pl.cover_url}
playDisabled={!pl.tracks.some((t) => playlistTrackToRef(t) !== null)}
onPlay={onPlayAll}
{onShuffle}
>
{#if pl.description}
<p class="text-sm text-text-muted">{pl.description}</p>
{/if}
<p class="text-xs text-text-muted">
{pl.track_count} {pl.track_count === 1 ? 'track' : 'tracks'}
{#if pl.is_public}· public{:else}· private{/if}
{#if !isOwner}· by {pl.owner_username}{/if}
</p>
{#snippet tools()}
{#if pl.refreshable && pl.system_variant}
<button
type="button"
disabled={refreshingSystem}
onclick={() => onRefreshSystem(pl.system_variant as string)}
class="rounded-md border border-border px-3 py-1.5 text-sm text-text-muted hover:text-text-primary"
aria-label="Refresh playlist"
>
{refreshingSystem ? 'Refreshing…' : 'Refresh'}
</button>
{/if}
</div>
<div class="min-w-0 flex-1">
<h1 class="truncate text-2xl font-medium text-text-primary">{pl.name}</h1>
{#if pl.description}
<p class="mt-1 text-sm text-text-muted">{pl.description}</p>
{#if isOwner && pl.is_public}
<button
type="button"
onclick={onCopyLink}
aria-label="Copy public link to this playlist"
title="Copy link"
class="rounded p-2 text-text-muted hover:bg-surface-hover hover:text-text-primary"
>
<LinkIcon size={16} strokeWidth={1} />
</button>
{/if}
<p class="mt-2 text-xs text-text-muted">
{pl.track_count} {pl.track_count === 1 ? 'track' : 'tracks'}
{#if pl.is_public}· public{:else}· private{/if}
{#if !isOwner}· by {pl.owner_username}{/if}
</p>
</div>
{#if pl.refreshable && pl.system_variant}
<button
type="button"
disabled={refreshingSystem}
onclick={() => onRefreshSystem(pl.system_variant as string)}
class="rounded-md border border-border px-3 py-1.5 text-sm text-text-muted hover:text-text-primary"
aria-label="Refresh playlist"
>
{refreshingSystem ? 'Refreshing…' : 'Refresh'}
</button>
{/if}
{#if isOwner && pl.is_public}
<button
type="button"
onclick={onCopyLink}
aria-label="Copy public link to this playlist"
title="Copy link"
class="rounded p-2 text-text-muted hover:bg-surface-hover hover:text-text-primary"
>
<LinkIcon size={16} strokeWidth={1} />
</button>
{/if}
{#if isOwner}
<button
type="button"
onclick={startEdit}
aria-label="Edit playlist"
class="rounded p-2 text-text-muted hover:bg-surface-hover hover:text-text-primary"
>
<Pencil size={16} strokeWidth={1} />
</button>
<button
type="button"
onclick={submitDelete}
aria-label="Delete playlist"
class="rounded p-2 text-text-muted hover:bg-surface-hover hover:text-action-destructive"
>
<Trash2 size={16} strokeWidth={1} />
</button>
{/if}
</header>
{#if isOwner}
<button
type="button"
onclick={startEdit}
aria-label="Edit playlist"
class="rounded p-2 text-text-muted hover:bg-surface-hover hover:text-text-primary"
>
<Pencil size={16} strokeWidth={1} />
</button>
<button
type="button"
onclick={submitDelete}
aria-label="Delete playlist"
class="rounded p-2 text-text-muted hover:bg-surface-hover hover:text-action-destructive"
>
<Trash2 size={16} strokeWidth={1} />
</button>
{/if}
{/snippet}
</CollectionHeader>
{:else}
<section class="mb-6 rounded-md border border-border bg-surface p-4">
<label class="block text-sm font-medium text-text-primary">
@@ -376,4 +382,4 @@
</TrackList>
{/if}
{/if}
</div>
</PageColumn>
+40 -1
View File
@@ -1,4 +1,4 @@
import { describe, expect, test, vi } from 'vitest';
import { afterEach, describe, expect, test, vi } from 'vitest';
import { render, screen, fireEvent, waitFor } from '@testing-library/svelte';
import { mockQuery } from '../../../test-utils/query';
import { emptyQuarantineMock } from '../../../test-utils/mocks/quarantine';
@@ -45,6 +45,7 @@ vi.mock('#lib/api/quarantine.js', () => emptyQuarantineMock());
import PlaylistDetailPage from './+page.svelte';
import { createPlaylistQuery, deletePlaylist, refreshSystem } from '#lib/api/playlists.js';
import { playQueue } from '#lib/player/store.svelte.js';
const mockedQuery = createPlaylistQuery as ReturnType<typeof vi.fn>;
@@ -58,7 +59,45 @@ const ownDetail: PlaylistDetail = {
]
};
afterEach(() => vi.clearAllMocks());
describe('Playlist detail page', () => {
// A missing file (#2527) stays in the list but is never queued: the
// page used to build its queue with its own converter, which only
// skipped removed tracks.
test('Play queues every playable entry and skips a missing file', async () => {
const withMissing: PlaylistDetail = {
...ownDetail,
track_count: 3,
tracks: [
...ownDetail.tracks,
{ ...ownDetail.tracks[1], position: 2, track_id: 't3', title: 'C', stream_url: null, unavailable: true }
]
};
mockedQuery.mockReturnValue(mockQuery({ data: withMissing }));
render(PlaylistDetailPage);
await fireEvent.click(screen.getByRole('button', { name: 'Play Mine' }));
const [queued, start] = (playQueue as ReturnType<typeof vi.fn>).mock.calls[0];
expect(queued.map((t: { id: string }) => t.id)).toEqual(['t1', 't2']);
expect(start).toBe(0);
});
test('clicking a row starts the queue at that track', async () => {
mockedQuery.mockReturnValue(mockQuery({ data: ownDetail }));
render(PlaylistDetailPage);
await fireEvent.click(screen.getByText('B'));
const [queued, start] = (playQueue as ReturnType<typeof vi.fn>).mock.calls.at(-1)!;
expect(queued[start].id).toBe('t2');
});
test('Shuffle queues the same playable entries', async () => {
mockedQuery.mockReturnValue(mockQuery({ data: ownDetail }));
render(PlaylistDetailPage);
await fireEvent.click(screen.getByRole('button', { name: 'Shuffle Mine' }));
const [queued] = (playQueue as ReturnType<typeof vi.fn>).mock.calls.at(-1)!;
expect(queued.map((t: { id: string }) => t.id).sort()).toEqual(['t1', 't2']);
});
test('renders header + tracks for owner', () => {
mockedQuery.mockReturnValue(mockQuery({ data: ownDetail }));
render(PlaylistDetailPage);