albums: one page for every record, and streamed history rows that actually open

Three things were wrong with opening an album, and only one of them was the
one that got reported.

The reported half: clicking a local record in the sidebar's history went to
the old in-library album view. Local albums carry no catalog identity of any
kind -- `albums.mbid` is null and is not even in the DTO -- so there was
nothing to route with. openAlbumByName already existed for exactly this
(the now-playing links use it, and it requires BOTH artist and title to match
normalized, which is the namesake guard); it now reports whether it resolved
and caches settled answers, so a second click is instant.

The unreported half, and the reason "half of them are not working": every
STREAMED row was dead. catalog_album_id is TEXT in SQLite, so it arrives as a
string, and `catalog_album` takes a u64 -- the invoke was rejected outright
with "invalid type: string ... expected u64". Terrestrials, OK Human and 9 all
failed silently on click. The id is coerced in checkedAlbumPayload now, where
both other string sources (page seeds) pass through too.

And the part that made the first half unfixable: a record no catalog carries
had nowhere to go. Panda Bear's "A ? of WHEN" is not on Deezer, so no amount
of resolving would ever open it. Local albums now render on the SAME page,
composed from the library's own data -- its tracks, durations, bitrates and
the cover already on disk -- under a namespaced `lib:` id that can never
collide with a Deezer one. Playback stays local: Play and any row queue the
files you already have rather than sending a record you own back through the
resolver. Save is not offered (it is already saved), previews are absent
(there is nothing to preview), and the attribution footer credits your
library rather than claiming Deezer + MusicBrainz.

With that, the old view has no callers and is deleted: the album-page block,
its CSS, and the members that only it used. Nothing anywhere routes to it.
Verified live: all six history rows open the new page, a Home card opens it,
Play queues 14 local FLACs without streaming, and the back arrow returns.
This commit is contained in:
KeelrLeek committed 2026-08-01 07:43:50 -05:00
1 parent 3c5bccf1b6
commit dde8c7510b
9 files changed
+252 -365

No files matched your search

+51 -10
View File
@@ -19,6 +19,7 @@
openCatalogAlbum,
openAlbumFromPreviewItem,
toggleShuffle,
playAlbum,
ui,
} from "../lib/state.svelte.js";
import { openPreview } from "../lib/preview/previewSession.svelte.js";
@@ -32,10 +33,17 @@
const page = $derived(catalog.albumPage); // { album, tracks, album_plays, … }
const album = $derived(page?.album ?? null);
/** A LOCAL library record on this same page. Everything remote is simply
* absent — no listeners, no editions, no prose, no cover upgrade to chase
* — and playback goes to the files on disk instead of the resolver. */
const isLocal = $derived(Boolean(page?.local));
// Upgrade this album's cover to the highest verified-same-artwork source.
let coveredId = null;
$effect(() => {
// A local cover is already the file on disk — there is no better
// source to go looking for, and the upgrade path expects a URL.
if (isLocal) return;
if (album?.cover && album.id !== coveredId) {
coveredId = album.id;
resolveCovers([album], album.artist);
@@ -566,7 +574,20 @@
else flagSaveError(`t${t.id}`);
}
const playTrack = (t) =>
const playTrack = (t) => {
// A local record plays the file you already have — queueing the whole
// album from the clicked row, the way the library always did — rather
// than sending a track you own back through the resolver.
if (isLocal) {
const at = page.libraryTracks.findIndex((lt) => lt.path === t.path);
playAlbum(
page.libraryTracks,
`${album.artist} — ${album.title}`,
at < 0 ? 0 : at,
page.artPath,
);
return;
}
streamSong(album.artist, t.title, {
cover: t.cover ?? album.cover,
trackId: t.id,
@@ -574,6 +595,7 @@
album: album.title || null,
expectSecs: t.duration_secs ?? null,
});
};
function year(a) {
return a?.release_date?.slice(0, 4) ?? "";
@@ -736,17 +758,30 @@
class="pill"
disabled={hasUnreleased}
title={hasUnreleased ? "Not released yet" : ""}
onclick={() => streamCatalogAlbum(album)}
onclick={() =>
isLocal
? playAlbum(
page.libraryTracks,
`${album.artist} — ${album.title}`,
0,
page.artPath,
)
: streamCatalogAlbum(album)}
>
<Icon name="play" size={12} /> Play
</button>
<button class="pill ghost" disabled={hasUnreleased} onclick={saveAlbumAction}>
<Icon
name={saved.album === "ok" ? "check" : saved.album === "err" ? "x" : "download"}
size={13}
/>
{saved.album === "ok" ? "Saved" : saved.album === "err" ? "No sources" : "Save"}
</button>
<!-- Save is "fetch this from the network into your
library". A local record is already there, so the
control has nothing to do and is not offered. -->
{#if !isLocal}
<button class="pill ghost" disabled={hasUnreleased} onclick={saveAlbumAction}>
<Icon
name={saved.album === "ok" ? "check" : saved.album === "err" ? "x" : "download"}
size={13}
/>
{saved.album === "ok" ? "Saved" : saved.album === "err" ? "No sources" : "Save"}
</button>
{/if}
<button
class="iconbtn"
class:on={player.shuffle}
@@ -936,10 +971,16 @@
{#if nTracks}<span class="gpill">{nTracks}</span>{/if}
{#if runtime}<span class="gpill">{runtime}</span>{/if}
</div>
<!-- Attribution has to be true of THIS page: a local record's
facts were read off the files, not fetched from a catalogue. -->
<p class="srcs">
{#if info?.description}<b>Words</b> Wikipedia · {/if}
{#if albumPlays || albumListeners}<b>Counts</b> Last.fm · {/if}
<b>Catalogue</b> Deezer + MusicBrainz
{#if isLocal}
<b>Catalogue</b> your library
{:else}
<b>Catalogue</b> Deezer + MusicBrainz
{/if}
</p>
{/if}
{/if}