Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/library/artist/ArtistDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@
<TrackList :tracks="item.topTracks" no-artist />
</template>

<template v-if="albums.length > 0">
<div class="d-flex justify-content-between mt-5 mb-2">
<template v-for="({ releaseType, albums: releaseTypeAlbums }) in albums">
<div :key="releaseType" class="d-flex justify-content-between mt-5 mb-2">
<h3 class="my-0">
Albums
{{ releaseType }}
</h3>
<b-button variant="link" class="p-0" @click="toggleAlbumSortOrder">
<Icon icon="arrow-up-down" />
</b-button>
</div>
<AlbumList :items="albums">
<AlbumList :key="releaseType" :items="releaseTypeAlbums">
<template #text="{ year }">
{{ year || 'Unknown' }}
</template>
Expand Down Expand Up @@ -132,8 +132,21 @@
isFavourite(): boolean {
return !!this.favouriteStore.artists[this.id]
},
albums(): Album[] {
return orderBy(this.item?.albums ?? [], 'year', this.mainStore.artistAlbumSortOrder)
albums(): { releaseType: string, albums: Album[] }[] {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could probably be made a bit more efficient and/or extracted out

needs to

  • group flat album list by type
  • sort those group by Albums at the top, etc

const sorted: Album[] = (orderBy(this.item?.albums ?? [], 'year', this.mainStore.artistAlbumSortOrder) || [])
const grouped = Object.groupBy(sorted, ({ isCompilation, releaseTypes }) =>
isCompilation ? 'Compilation' : (releaseTypes[0] || 'Album')
) || {}

const groupOrder = ['Album', 'EP', 'Single']
const groups = Object.entries(grouped).sort(([aType], [bType]) => {
const [a, b] = [groupOrder.indexOf(aType), groupOrder.indexOf(bType)]
if (a === -1 && b === -1) return 0
if (a === -1) return 1
if (b === -1) return -1
return a - b
})
return groups.map(([releaseType, albums]) => ({ releaseType, albums: albums || [] }))
},
},
watch: {
Expand Down
6 changes: 5 additions & 1 deletion src/shared/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export interface Album {
lastFmUrl?: string
musicBrainzUrl?: string
tracks?: Track[]
isCompilation: boolean
releaseTypes: string[]
}

export interface Artist {
Expand Down Expand Up @@ -591,7 +593,9 @@ export class API {
musicBrainzUrl: item.musicBrainzId
? `https://musicbrainz.org/release/${item.musicBrainzId}`
: undefined,
tracks: (item.song || []).map(this.normalizeTrack, this)
tracks: (item.song || []).map(this.normalizeTrack, this),
isCompilation: !!item.isCompilation,
releaseTypes: item.releaseTypes.length ? item.releaseTypes : [],
}
}

Expand Down