Fix removing listview item even if not succesfully deleted (#404)

* Fix deleting listview item if not deleted

* Refactor
This commit is contained in:
André Andersson
2021-01-23 22:42:42 +01:00
committed by GitHub
parent 5b40fc6ddc
commit ab60556644
2 changed files with 15 additions and 9 deletions

View File

@@ -75,13 +75,18 @@ impl Playlist {
track_pos_pairs: &[(Track, usize)],
spotify: Arc<Spotify>,
library: Arc<Library>,
) {
if spotify.delete_tracks(&self.id, track_pos_pairs) {
if let Some(tracks) = &mut self.tracks {
for (_track, pos) in track_pos_pairs {
tracks.remove(*pos);
) -> bool {
match spotify.delete_tracks(&self.id, track_pos_pairs) {
false => false,
true => {
if let Some(tracks) = &mut self.tracks {
for (_track, pos) in track_pos_pairs {
tracks.remove(*pos);
}
library.playlist_update(&self);
}
library.playlist_update(&self);
true
}
}
}

View File

@@ -62,12 +62,13 @@ impl ViewExt for PlaylistView {
};
let track = tracks.get(pos);
if let Some(t) = track {
self.playlist.delete_tracks(
if self.playlist.delete_tracks(
&[(t.clone(), pos)],
self.spotify.clone(),
self.library.clone(),
);
self.list.remove(pos);
) {
self.list.remove(pos);
}
}
return Ok(CommandResult::Consumed(None));
}