Sync currentArtistId on library upgrade + hide Similar Artists in Enhanced view

Two bugs from the source-artist click flow:

1. After the backend's library upgrade kicks in (clicking a Deezer
   result for an artist you already own routes through the library
   path), the response's data.artist.id is the library PK while
   artistDetailPageState.currentArtistId still held the source id.
   Toggling Enhanced view then fired
   /api/library/artist/<source_id>/enhanced which 404'd because the
   source id isn't a library PK.
   loadArtistDetailData now updates currentArtistId from
   data.artist.id whenever they differ — Enhanced view, completion
   checks, server sync etc. all use the right id.

2. The Similar Artists section is part of the standard view and was
   staying visible when Enhanced view toggled on. toggleEnhancedView
   now hides #ad-similar-artists-section in the same flow that
   hides .discography-sections.
This commit is contained in:
Broque Thomas 2026-04-22 19:27:17 -07:00
parent 9106617538
commit 77567a5eda

View file

@ -803,6 +803,18 @@ async function loadArtistDetailData(artistId, artistName) {
// Populate the page with data (which updates the hero section and sets textContent)
populateArtistDetailPage(data);
// Library upgrade — if the backend resolved this source-artist click to
// an existing library record (e.g. clicking a Deezer result for an
// artist already in your Plex), data.artist.id is the library PK.
// Update currentArtistId so subsequent library-only API calls (Enhanced
// view, completion checks, server sync) hit the right id. Also flip
// the body source flag from 'source' back to 'library' so the
// library-only UI re-shows.
if (data.artist && data.artist.id && String(data.artist.id) !== String(artistDetailPageState.currentArtistId)) {
console.log(`📚 Library upgrade: ${artistDetailPageState.currentArtistId}${data.artist.id}`);
artistDetailPageState.currentArtistId = data.artist.id;
}
// Keep the resolved metadata source for album-track lookups.
artistDetailPageState.currentArtistSource = data.discography?.source || data.artist?.source || null;
@ -2417,6 +2429,10 @@ function toggleEnhancedView(enabled) {
if (i < dividers.length - 1) d.style.display = enabled ? 'none' : '';
});
// Similar Artists is part of the standard view — hide it in Enhanced.
const similarSection = document.getElementById('ad-similar-artists-section');
if (similarSection) similarSection.style.display = enabled ? 'none' : '';
if (enabled) {
standardSections.classList.add('hidden');
enhancedContainer.classList.remove('hidden');