Persist sorting orders for playlists

Closes #436
This commit is contained in:
Henrik Friedrichsen
2021-03-05 21:38:57 +01:00
parent b1c0ed6fae
commit ca8f1a8545
2 changed files with 21 additions and 0 deletions

View File

@@ -33,6 +33,9 @@ impl PlaylistView {
let spotify = queue.get_spotify();
let list = ListView::new(Arc::new(RwLock::new(tracks)), queue, library.clone());
if let Some(order) = library.cfg.state().playlist_orders.get(&playlist.id) {
list.sort(&order.key, &order.direction);
}
Self {
playlist,
@@ -74,6 +77,15 @@ impl ViewExt for PlaylistView {
}
if let Command::Sort(key, direction) = cmd {
self.library.cfg.with_state_mut(|mut state| {
let order = crate::config::SortingOrder {
key: key.clone(),
direction: direction.clone(),
};
state
.playlist_orders
.insert(self.playlist.id.clone(), order);
});
self.list.sort(key, direction);
return Ok(CommandResult::Consumed(None));
}