From 5f87e3cd79a7c1fc32041210457aed042cb0f458 Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Mon, 22 Mar 2021 21:32:25 +0100 Subject: [PATCH] show display name owning the current library as suggested in #470 --- src/library.rs | 6 +++++- src/ui/library.rs | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/library.rs b/src/library.rs index 86f7351..e9dce42 100644 --- a/src/library.rs +++ b/src/library.rs @@ -34,6 +34,7 @@ pub struct Library { pub shows: Arc>>, pub is_done: Arc>, pub user_id: Option, + pub display_name: Option, ev: EventManager, spotify: Arc, pub cfg: Arc, @@ -41,7 +42,9 @@ pub struct Library { impl Library { pub fn new(ev: &EventManager, spotify: Arc, cfg: Arc) -> Self { - let user_id = spotify.current_user().map(|u| u.id); + let current_user = spotify.current_user(); + let user_id = current_user.as_ref().map(|u| u.id.clone()); + let display_name = current_user.as_ref().and_then(|u| u.display_name.clone()); let library = Self { tracks: Arc::new(RwLock::new(Vec::new())), @@ -51,6 +54,7 @@ impl Library { shows: Arc::new(RwLock::new(Vec::new())), is_done: Arc::new(RwLock::new(false)), user_id, + display_name, ev: ev.clone(), spotify, cfg, diff --git a/src/ui/library.rs b/src/ui/library.rs index aa16546..bbbc093 100644 --- a/src/ui/library.rs +++ b/src/ui/library.rs @@ -14,6 +14,7 @@ use crate::ui::tabview::TabView; pub struct LibraryView { tabs: TabView, + display_name: Option, } impl LibraryView { @@ -45,7 +46,10 @@ impl LibraryView { ListView::new(library.shows.clone(), queue, library.clone()), ); - Self { tabs } + Self { + tabs, + display_name: library.display_name.clone(), + } } } @@ -55,7 +59,11 @@ impl ViewWrapper for LibraryView { impl ViewExt for LibraryView { fn title(&self) -> String { - "Library".to_string() + if let Some(name) = &self.display_name { + format!("Library of {}", name) + } else { + "Library".to_string() + } } fn on_command(&mut self, s: &mut Cursive, cmd: &Command) -> Result {