From 993febd2040b6c3f6c78bca16b6f30697a5a1050 Mon Sep 17 00:00:00 2001 From: filipriec Date: Sun, 23 Mar 2025 11:28:39 +0100 Subject: [PATCH] admin panel keyindings --- client/config.toml | 4 +++ client/src/config/binds/config.rs | 8 ++++-- client/src/modes/handlers/event.rs | 39 ++++++++++++++++++++++++++++++ client/src/ui/handlers/ui.rs | 1 + 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/client/config.toml b/client/config.toml index f49d354..62c45b4 100644 --- a/client/config.toml +++ b/client/config.toml @@ -8,6 +8,10 @@ next_option = ["j", "Right"] previous_option = ["k", "Left"] select = ["Enter"] +[keybindings.admin] +move_up = ["k"] +move_down = ["j"] + [keybindings.common] save = ["ctrl+s"] quit = ["ctrl+q"] diff --git a/client/src/config/binds/config.rs b/client/src/config/binds/config.rs index 0029ca3..a0e9b5a 100644 --- a/client/src/config/binds/config.rs +++ b/client/src/config/binds/config.rs @@ -28,6 +28,8 @@ pub struct ModeKeybindings { #[serde(default)] pub intro: HashMap>, #[serde(default)] + pub admin: HashMap>, + #[serde(default)] pub read_only: HashMap>, #[serde(default)] pub edit: HashMap>, @@ -58,9 +60,11 @@ impl Config { /// Gets an action for a key in Admin mode, checking common and global bindings pub fn get_admin_action(&self, key: KeyCode, modifiers: KeyModifiers) -> Option<&str> { - self.get_action_for_key_in_mode(&self.keybindings.common, key, modifiers) + self.get_action_for_key_in_mode(&self.keybindings.admin, key, modifiers) + .or_else(|| self.get_action_for_key_in_mode(&self.keybindings.common, key, modifiers)) + .or_else(|| self.get_action_for_key_in_mode(&self.keybindings.intro, key, modifiers)) .or_else(|| self.get_action_for_key_in_mode(&self.keybindings.global, key, modifiers)) - } + } /// Gets an action for a key in Read-Only mode, also checking common keybindings. pub fn get_read_only_action_for_key(&self, key: KeyCode, modifiers: KeyModifiers) -> Option<&str> { diff --git a/client/src/modes/handlers/event.rs b/client/src/modes/handlers/event.rs index 3ec1d83..c4c84c8 100644 --- a/client/src/modes/handlers/event.rs +++ b/client/src/modes/handlers/event.rs @@ -48,6 +48,7 @@ impl EventHandler { total_count: u64, current_position: &mut u64, intro_state: &mut crate::components::intro::intro::IntroState, + admin_state: &mut crate::components::admin::admin_panel::AdminPanelState, ) -> Result<(bool, String), Box> { if app_state.ui.show_intro { if let Event::Key(key) = event { @@ -70,6 +71,44 @@ impl EventHandler { let key_code = key.code; let modifiers = key.modifiers; + // Handle admin panel first if visible + if app_state.ui.show_admin { + if let Some(action) = config.get_admin_action(key_code, modifiers) { + match action { + "move_up" => admin_state.previous(), + "move_down" => admin_state.next(), + "select" => { + // Handle selection logic + }, + "quit" => app_state.ui.show_admin = false, + // Handle common actions + "save" => { + let message = common::save( + form_state, + grpc_client, + &mut app_state.ui.is_saved, + current_position, + total_count, + ).await?; + return Ok((false, message)); + }, + "revert" => { + let message = common::revert( + form_state, + grpc_client, + current_position, + total_count, + ).await?; + return Ok((false, message)); + }, + _ => {} + } + return Ok((false, format!("Admin: {}", action))); + } + // Block other keybindings when admin panel is visible + return Ok((false, String::new())); + } + if UiStateHandler::toggle_sidebar( &mut app_state.ui, config, diff --git a/client/src/ui/handlers/ui.rs b/client/src/ui/handlers/ui.rs index a4de230..39a0016 100644 --- a/client/src/ui/handlers/ui.rs +++ b/client/src/ui/handlers/ui.rs @@ -94,6 +94,7 @@ pub async fn run_ui() -> Result<(), Box> { total_count, &mut current_position, &mut intro_state, + &mut admin_panel_state, ).await?; app_state.current_position = current_position;