show display name owning the current library

as suggested in #470
This commit is contained in:
Henrik Friedrichsen
2021-03-22 21:32:25 +01:00
parent 9e9476d94c
commit 5f87e3cd79
2 changed files with 15 additions and 3 deletions

View File

@@ -34,6 +34,7 @@ pub struct Library {
pub shows: Arc<RwLock<Vec<Show>>>,
pub is_done: Arc<RwLock<bool>>,
pub user_id: Option<String>,
pub display_name: Option<String>,
ev: EventManager,
spotify: Arc<Spotify>,
pub cfg: Arc<Config>,
@@ -41,7 +42,9 @@ pub struct Library {
impl Library {
pub fn new(ev: &EventManager, spotify: Arc<Spotify>, cfg: Arc<Config>) -> 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,

View File

@@ -14,6 +14,7 @@ use crate::ui::tabview::TabView;
pub struct LibraryView {
tabs: TabView,
display_name: Option<String>,
}
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<CommandResult, String> {