Return album appearances

This commit is contained in:
Antoine Gersant 2024-07-31 17:07:44 -07:00
parent ae9f94ce4f
commit 7a1d433c8a
3 changed files with 27 additions and 7 deletions

View file

@ -304,17 +304,34 @@ impl Index {
pub(self) fn get_artist(&self, artist_id: ArtistID) -> Option<collection::Artist> {
self.artists.get(&artist_id).map(|a| {
let mut albums = a
.albums
.iter()
.filter_map(|album_id| self.get_album(*album_id))
.collect::<Vec<_>>();
let albums = {
let mut albums = a
.albums
.iter()
.filter_map(|album_id| self.get_album(*album_id))
.collect::<Vec<_>>();
albums.sort_by(|a, b| (a.year, &a.name).partial_cmp(&(b.year, &b.name)).unwrap());
albums
};
albums.sort_by(|a, b| (a.year, &a.name).partial_cmp(&(b.year, &b.name)).unwrap());
let album_appearances = {
let mut album_appearances = a
.album_appearances
.iter()
.filter_map(|album_id| self.get_album(*album_id))
.collect::<Vec<_>>();
album_appearances.sort_by(|a, b| {
(&a.artists, a.year, &a.name)
.partial_cmp(&(&b.artists, b.year, &b.name))
.unwrap()
});
album_appearances
};
collection::Artist {
name: a.name.clone(),
albums: albums,
albums,
album_appearances,
}
})
}

View file

@ -68,6 +68,7 @@ pub struct Directory {
pub struct Artist {
pub name: Option<String>,
pub albums: Vec<Album>,
pub album_appearances: Vec<Album>,
}
#[derive(Debug, Default, PartialEq, Eq)]

View file

@ -305,6 +305,7 @@ impl From<collection::File> for BrowserEntry {
pub struct Artist {
pub name: Option<String>,
pub albums: Vec<AlbumHeader>,
pub album_appearances: Vec<AlbumHeader>,
}
impl From<collection::Artist> for Artist {
@ -312,6 +313,7 @@ impl From<collection::Artist> for Artist {
Self {
name: a.name,
albums: a.albums.into_iter().map(|a| a.into()).collect(),
album_appearances: a.album_appearances.into_iter().map(|a| a.into()).collect(),
}
}
}