Make initial rooms sort order configurable
This commit is contained in:
parent
61a9cc10f1
commit
7dfa8c6048
4 changed files with 38 additions and 2 deletions
|
|
@ -6,6 +6,14 @@ use serde::Deserialize;
|
|||
|
||||
use crate::macros::ok_or_return;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum RoomsSortOrder {
|
||||
#[default]
|
||||
Alphabet,
|
||||
Importance,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize)]
|
||||
pub struct EuphRoom {
|
||||
// TODO Mark favourite rooms via printable ascii characters
|
||||
|
|
@ -29,6 +37,8 @@ pub struct Config {
|
|||
pub ephemeral: bool,
|
||||
#[serde(default)]
|
||||
pub offline: bool,
|
||||
#[serde(default)]
|
||||
pub rooms_sort_order: RoomsSortOrder,
|
||||
// TODO Invoke external notification command?
|
||||
pub euph: Euph,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use tokio::sync::mpsc;
|
|||
use toss::styled::Styled;
|
||||
use toss::terminal::Terminal;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::config::{Config, RoomsSortOrder};
|
||||
use crate::euph::EuphRoomEvent;
|
||||
use crate::vault::Vault;
|
||||
|
||||
|
|
@ -38,6 +38,15 @@ enum Order {
|
|||
Importance,
|
||||
}
|
||||
|
||||
impl Order {
|
||||
fn from_rooms_sort_order(order: RoomsSortOrder) -> Self {
|
||||
match order {
|
||||
RoomsSortOrder::Alphabet => Self::Alphabet,
|
||||
RoomsSortOrder::Importance => Self::Importance,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Rooms {
|
||||
config: &'static Config,
|
||||
|
||||
|
|
@ -63,7 +72,7 @@ impl Rooms {
|
|||
ui_event_tx,
|
||||
state: State::ShowList,
|
||||
list: ListState::new(),
|
||||
order: Order::Alphabet,
|
||||
order: Order::from_rooms_sort_order(config.rooms_sort_order),
|
||||
euph_rooms: HashMap::new(),
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue