Skip to content

Commit

Permalink
add UI for album's release year (#305)
Browse files Browse the repository at this point in the history
Co-authored-by: Thang Pham <phamducthang1234@gmail.com>
  • Loading branch information
rubenvandeven and aome510 authored Dec 9, 2023
1 parent ac7a952 commit 2f9fe63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions spotify_player/src/state/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ impl Album {
artists: from_simplified_artists_to_artists(album.artists),
})
}

/// gets the album's release year
pub fn year(&self) -> String {
self.release_date
.split('-')
.next()
.unwrap_or("")
.to_string()
}
}

impl From<rspotify_model::FullAlbum> for Album {
Expand All @@ -327,9 +336,10 @@ impl std::fmt::Display for Album {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{} • {}",
"{} • {} ({})",
self.name,
map_join(&self.artists, |a| &a.name, ", ")
map_join(&self.artists, |a| &a.name, ", "),
self.year()
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion spotify_player/src/ui/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ fn render_artist_context_page_windows(
let (album_list, n_albums) = {
let album_items = albums
.into_iter()
.map(|a| (a.name.clone(), false))
.map(|a| (format!("{1} • {0}", a.name, a.year()), false))
.collect::<Vec<_>>();

utils::construct_list_widget(
Expand Down

0 comments on commit 2f9fe63

Please sign in to comment.