@@ -6,6 +6,7 @@ use std::{fs, process};
|
||||
use cursive::theme::Theme;
|
||||
use platform_dirs::AppDirs;
|
||||
|
||||
use crate::command::{SortDirection, SortKey};
|
||||
use crate::playable::Playable;
|
||||
use crate::queue;
|
||||
|
||||
@@ -53,12 +54,19 @@ pub struct ConfigTheme {
|
||||
pub search_match: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct SortingOrder {
|
||||
pub key: SortKey,
|
||||
pub direction: SortDirection,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct UserState {
|
||||
pub volume: u16,
|
||||
pub shuffle: bool,
|
||||
pub repeat: queue::RepeatSetting,
|
||||
pub queue: Vec<Playable>,
|
||||
pub playlist_orders: HashMap<String, SortingOrder>,
|
||||
}
|
||||
|
||||
impl Default for UserState {
|
||||
@@ -68,6 +76,7 @@ impl Default for UserState {
|
||||
shuffle: false,
|
||||
repeat: queue::RepeatSetting::None,
|
||||
queue: Vec::new(),
|
||||
playlist_orders: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user