Skip to content

Commit 2f9fe63

Browse files
add UI for album's release year (#305)
Co-authored-by: Thang Pham <[email protected]>
1 parent ac7a952 commit 2f9fe63

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

spotify_player/src/state/model.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,15 @@ impl Album {
310310
artists: from_simplified_artists_to_artists(album.artists),
311311
})
312312
}
313+
314+
/// gets the album's release year
315+
pub fn year(&self) -> String {
316+
self.release_date
317+
.split('-')
318+
.next()
319+
.unwrap_or("")
320+
.to_string()
321+
}
313322
}
314323

315324
impl From<rspotify_model::FullAlbum> for Album {
@@ -327,9 +336,10 @@ impl std::fmt::Display for Album {
327336
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
328337
write!(
329338
f,
330-
"{} • {}",
339+
"{} • {} ({})",
331340
self.name,
332-
map_join(&self.artists, |a| &a.name, ", ")
341+
map_join(&self.artists, |a| &a.name, ", "),
342+
self.year()
333343
)
334344
}
335345
}

spotify_player/src/ui/page.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ fn render_artist_context_page_windows(
618618
let (album_list, n_albums) = {
619619
let album_items = albums
620620
.into_iter()
621-
.map(|a| (a.name.clone(), false))
621+
.map(|a| (format!("{1} • {0}", a.name, a.year()), false))
622622
.collect::<Vec<_>>();
623623

624624
utils::construct_list_widget(

0 commit comments

Comments
 (0)