move to a separate save/delete binding approach
this is to address accidental deletions of playlists/tracks that some users faced closes #75 related #15
This commit is contained in:
@@ -191,6 +191,14 @@ impl ListItem for Album {
|
||||
}
|
||||
}
|
||||
|
||||
fn save(&mut self, library: Arc<Library>) {
|
||||
library.save_album(self);
|
||||
}
|
||||
|
||||
fn unsave(&mut self, library: Arc<Library>) {
|
||||
library.unsave_album(self);
|
||||
}
|
||||
|
||||
fn toggle_saved(&mut self, library: Arc<Library>) {
|
||||
if library.is_saved_album(self) {
|
||||
library.unsave_album(self);
|
||||
|
||||
@@ -186,6 +186,14 @@ impl ListItem for Artist {
|
||||
}
|
||||
}
|
||||
|
||||
fn save(&mut self, library: Arc<Library>) {
|
||||
library.follow_artist(self);
|
||||
}
|
||||
|
||||
fn unsave(&mut self, library: Arc<Library>) {
|
||||
library.unfollow_artist(self);
|
||||
}
|
||||
|
||||
fn toggle_saved(&mut self, library: Arc<Library>) {
|
||||
if library.is_followed_artist(self) {
|
||||
library.unfollow_artist(self);
|
||||
|
||||
@@ -154,6 +154,14 @@ impl ListItem for Playlist {
|
||||
}
|
||||
}
|
||||
|
||||
fn save(&mut self, library: Arc<Library>) {
|
||||
library.follow_playlist(self);
|
||||
}
|
||||
|
||||
fn unsave(&mut self, library: Arc<Library>) {
|
||||
library.delete_playlist(&self.id);
|
||||
}
|
||||
|
||||
fn toggle_saved(&mut self, library: Arc<Library>) {
|
||||
// Don't allow users to unsave their own playlists with one keypress
|
||||
if !library.is_followed_playlist(self) {
|
||||
|
||||
@@ -181,6 +181,14 @@ impl ListItem for Track {
|
||||
queue.append(self);
|
||||
}
|
||||
|
||||
fn save(&mut self, library: Arc<Library>) {
|
||||
library.save_tracks(vec![self], true);
|
||||
}
|
||||
|
||||
fn unsave(&mut self, library: Arc<Library>) {
|
||||
library.unsave_tracks(vec![self], true);
|
||||
}
|
||||
|
||||
fn toggle_saved(&mut self, library: Arc<Library>) {
|
||||
if library.is_saved_track(self) {
|
||||
library.unsave_tracks(vec![self], true);
|
||||
|
||||
@@ -18,6 +18,8 @@ pub trait ListItem: Sync + Send + 'static {
|
||||
fn play(&mut self, queue: Arc<Queue>);
|
||||
fn queue(&mut self, queue: Arc<Queue>);
|
||||
fn toggle_saved(&mut self, library: Arc<Library>);
|
||||
fn save(&mut self, library: Arc<Library>);
|
||||
fn unsave(&mut self, library: Arc<Library>);
|
||||
fn open(&self, queue: Arc<Queue>, library: Arc<Library>) -> Option<Box<dyn ViewExt>>;
|
||||
fn share_url(&self) -> Option<String>;
|
||||
|
||||
|
||||
@@ -309,10 +309,19 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
|
||||
};
|
||||
|
||||
if let Some(item) = item.as_mut() {
|
||||
item.toggle_saved(self.library.clone());
|
||||
item.save(self.library.clone());
|
||||
}
|
||||
}
|
||||
Command::Delete => {
|
||||
let mut item = {
|
||||
let content = self.content.read().unwrap();
|
||||
content.get(self.selected).cloned()
|
||||
};
|
||||
|
||||
if let Some(item) = item.as_mut() {
|
||||
item.unsave(self.library.clone());
|
||||
}
|
||||
}
|
||||
Command::Share(mode) => {
|
||||
let url = match mode {
|
||||
TargetMode::Selected => self.content.read().ok().and_then(|content| {
|
||||
|
||||
Reference in New Issue
Block a user