feat: implement Labels section in Artist Network sidebar
- Add labels field to ArtistDetail type - Extract unique labels from artist albums in convertQobuzArtist - Update appendArtistAlbums to merge new labels - Display labels in sidebar with click navigation to label view - Use Tag icon from lucide-svelte
This commit is contained in:
1 parent
e9eff7403d
commit
9f104433f3
4 files changed
+52
-2
No files matched your search
@@ -392,6 +392,27 @@ function categorizeAlbum(album: QobuzAlbum, mainArtistId: number): 'tributes' |
|
||||
return 'albums';
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract unique labels from albums
|
||||
*/
|
||||
function extractLabelsFromAlbums(albums: QobuzAlbum[]): { id: number; name: string }[] {
|
||||
const labelMap = new Map<number, string>();
|
||||
|
||||
for (const album of albums) {
|
||||
if (album.label?.id && album.label?.name) {
|
||||
// Only add if we haven't seen this label ID before
|
||||
if (!labelMap.has(album.label.id)) {
|
||||
labelMap.set(album.label.id, album.label.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert to array and sort by name
|
||||
return Array.from(labelMap.entries())
|
||||
.map(([id, name]) => ({ id, name }))
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Qobuz API artist response to UI ArtistDetail model
|
||||
*/
|
||||
@@ -443,6 +464,7 @@ export function convertQobuzArtist(artist: QobuzArtist): ArtistDetail {
|
||||
tributes,
|
||||
others,
|
||||
playlists: toArtistPlaylists(artist.playlists),
|
||||
labels: extractLabelsFromAlbums(albumItems),
|
||||
totalAlbums: artist.albums?.total || artist.albums_count || 0,
|
||||
albumsFetched
|
||||
};
|
||||
@@ -507,6 +529,13 @@ export function appendArtistAlbums(
|
||||
}
|
||||
}
|
||||
|
||||
// Merge new labels from new albums
|
||||
const existingLabelIds = new Set(artist.labels.map(l => l.id));
|
||||
const newLabels = extractLabelsFromAlbums(newAlbums)
|
||||
.filter(l => !existingLabelIds.has(l.id));
|
||||
const labels = [...artist.labels, ...newLabels]
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
return {
|
||||
...artist,
|
||||
albums,
|
||||
@@ -514,6 +543,7 @@ export function appendArtistAlbums(
|
||||
liveAlbums,
|
||||
tributes,
|
||||
others,
|
||||
labels,
|
||||
totalAlbums: totalAlbums ?? artist.totalAlbums,
|
||||
albumsFetched: albumsFetched ?? artist.albumsFetched + newAlbums.length
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user