Fix watchlist badge — source-aware ID selection and hide when no usable ID
This commit is contained in:
parent
d401dc8af1
commit
a8de75ce26
1 changed files with 21 additions and 14 deletions
|
|
@ -32592,11 +32592,13 @@ function createLibraryArtistCard(artist) {
|
||||||
if (artist.qobuz_id) {
|
if (artist.qobuz_id) {
|
||||||
badgeSources.push({ cls: 'qobuz-card-icon', logo: QOBUZ_LOGO_URL, fallback: 'Qz', title: 'View on Qobuz', url: `https://www.qobuz.com/artist/${artist.qobuz_id}` });
|
badgeSources.push({ cls: 'qobuz-card-icon', logo: QOBUZ_LOGO_URL, fallback: 'Qz', title: 'View on Qobuz', url: `https://www.qobuz.com/artist/${artist.qobuz_id}` });
|
||||||
}
|
}
|
||||||
// Add watchlist indicator as the last badge
|
// Add watchlist indicator — only if artist has a usable ID for the active source
|
||||||
const hasExternalId = artist.itunes_artist_id || artist.spotify_artist_id;
|
const hasActiveSourceId = currentMusicSourceName === 'Apple Music'
|
||||||
|
? (artist.itunes_artist_id || artist.spotify_artist_id)
|
||||||
|
: (artist.spotify_artist_id || artist.itunes_artist_id);
|
||||||
if (artist.is_watched) {
|
if (artist.is_watched) {
|
||||||
badgeSources.push({ cls: 'watch-card-icon watched', logo: null, fallback: '👁️', fallbackExpanded: 'Watching', title: 'On your watchlist', url: null, isWatch: true });
|
badgeSources.push({ cls: 'watch-card-icon watched', logo: null, fallback: '👁️', fallbackExpanded: 'Watching', title: 'On your watchlist', url: null, isWatch: true });
|
||||||
} else if (hasExternalId) {
|
} else if (hasActiveSourceId) {
|
||||||
badgeSources.push({ cls: 'watch-card-icon', logo: null, fallback: '👁️', fallbackExpanded: 'Watch', title: 'Add to Watchlist', url: null, isWatch: true, unwatched: true });
|
badgeSources.push({ cls: 'watch-card-icon', logo: null, fallback: '👁️', fallbackExpanded: 'Watch', title: 'Add to Watchlist', url: null, isWatch: true, unwatched: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32853,15 +32855,18 @@ async function toggleLibraryCardWatchlist(btn, artist) {
|
||||||
if (btn.disabled) return;
|
if (btn.disabled) return;
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
|
|
||||||
const icon = btn.querySelector('.watchlist-icon');
|
// Support both badge-style (.watch-icon-label) and button-style (.watchlist-text)
|
||||||
const text = btn.querySelector('.watchlist-text');
|
const label = btn.querySelector('.watch-icon-label') || btn.querySelector('.watchlist-text');
|
||||||
const isWatching = btn.classList.contains('watching');
|
const isWatching = btn.classList.contains('watched') || btn.classList.contains('watching');
|
||||||
|
|
||||||
text.textContent = '...';
|
if (label) label.textContent = '...';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Determine external ID: prefer iTunes, fallback Spotify
|
// Use the ID matching the active metadata source
|
||||||
const artistId = artist.itunes_artist_id || artist.spotify_artist_id;
|
const artistId = currentMusicSourceName === 'Apple Music'
|
||||||
|
? (artist.itunes_artist_id || artist.spotify_artist_id)
|
||||||
|
: (artist.spotify_artist_id || artist.itunes_artist_id);
|
||||||
|
if (!artistId) throw new Error('No iTunes or Spotify ID available for this artist');
|
||||||
|
|
||||||
if (isWatching) {
|
if (isWatching) {
|
||||||
const response = await fetch('/api/watchlist/remove', {
|
const response = await fetch('/api/watchlist/remove', {
|
||||||
|
|
@ -32872,9 +32877,10 @@ async function toggleLibraryCardWatchlist(btn, artist) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (!data.success) throw new Error(data.error);
|
if (!data.success) throw new Error(data.error);
|
||||||
|
|
||||||
btn.classList.remove('watching');
|
btn.classList.remove('watched', 'watching');
|
||||||
|
btn.style.opacity = '0.4';
|
||||||
btn.title = 'Add to Watchlist';
|
btn.title = 'Add to Watchlist';
|
||||||
text.textContent = 'Watch';
|
if (label) label.textContent = 'Watch';
|
||||||
showToast(`Removed ${artist.name} from watchlist`, 'success');
|
showToast(`Removed ${artist.name} from watchlist`, 'success');
|
||||||
} else {
|
} else {
|
||||||
const response = await fetch('/api/watchlist/add', {
|
const response = await fetch('/api/watchlist/add', {
|
||||||
|
|
@ -32885,9 +32891,10 @@ async function toggleLibraryCardWatchlist(btn, artist) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (!data.success) throw new Error(data.error);
|
if (!data.success) throw new Error(data.error);
|
||||||
|
|
||||||
btn.classList.add('watching');
|
btn.classList.add('watched');
|
||||||
|
btn.style.opacity = '';
|
||||||
btn.title = 'Remove from Watchlist';
|
btn.title = 'Remove from Watchlist';
|
||||||
text.textContent = 'Watching';
|
if (label) label.textContent = 'Watching';
|
||||||
showToast(`Added ${artist.name} to watchlist`, 'success');
|
showToast(`Added ${artist.name} to watchlist`, 'success');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32896,7 +32903,7 @@ async function toggleLibraryCardWatchlist(btn, artist) {
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error toggling library card watchlist:', error);
|
console.error('Error toggling library card watchlist:', error);
|
||||||
text.textContent = isWatching ? 'Watching' : 'Watch';
|
if (label) label.textContent = isWatching ? 'Watching' : 'Watch';
|
||||||
showToast(`Error: ${error.message}`, 'error');
|
showToast(`Error: ${error.message}`, 'error');
|
||||||
} finally {
|
} finally {
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue