diff --git a/client/src/state/pages/add_logic.rs b/client/src/state/pages/add_logic.rs index ebff0fb..b987d7d 100644 --- a/client/src/state/pages/add_logic.rs +++ b/client/src/state/pages/add_logic.rs @@ -1,6 +1,6 @@ // src/state/pages/add_logic.rs use crate::config::binds::config::{EditorConfig, EditorKeybindingMode}; -use canvas::canvas::{CanvasState, ActionContext, CanvasAction}; // External library +use canvas::canvas::{CanvasState, ActionContext, CanvasAction, AppMode}; use crate::components::common::text_editor::{TextEditor, VimState}; use std::cell::RefCell; use std::rc::Rc; @@ -54,6 +54,7 @@ pub struct AddLogicState { // New fields for same-profile table names and column autocomplete pub same_profile_table_names: Vec, // Tables from same profile only pub script_editor_awaiting_column_autocomplete: Option, // Table name waiting for column fetch + pub app_mode: AppMode, } impl AddLogicState { @@ -91,6 +92,7 @@ impl AddLogicState { same_profile_table_names: Vec::new(), script_editor_awaiting_column_autocomplete: None, + app_mode: AppMode::Edit, } } @@ -269,7 +271,9 @@ impl AddLogicState { impl Default for AddLogicState { fn default() -> Self { - Self::new(&EditorConfig::default()) + let mut state = Self::new(&EditorConfig::default()); + state.app_mode = AppMode::Edit; + state } } @@ -439,4 +443,8 @@ impl CanvasState for AddLogicState { _ => None, } } + + fn current_mode(&self) -> AppMode { + self.app_mode + } } diff --git a/client/src/state/pages/add_table.rs b/client/src/state/pages/add_table.rs index 94c325e..a3439c6 100644 --- a/client/src/state/pages/add_table.rs +++ b/client/src/state/pages/add_table.rs @@ -1,5 +1,5 @@ // src/state/pages/add_table.rs -use canvas::canvas::{CanvasState, ActionContext, CanvasAction}; // External library +use canvas::canvas::{CanvasState, ActionContext, CanvasAction, AppMode}; use ratatui::widgets::TableState; use serde::{Deserialize, Serialize}; @@ -63,6 +63,7 @@ pub struct AddTableState { pub column_name_cursor_pos: usize, pub column_type_cursor_pos: usize, pub has_unsaved_changes: bool, + pub app_mode: AppMode, } impl Default for AddTableState { @@ -85,6 +86,7 @@ impl Default for AddTableState { column_name_cursor_pos: 0, column_type_cursor_pos: 0, has_unsaved_changes: false, + app_mode: AppMode::Edit, } } } @@ -297,4 +299,8 @@ impl CanvasState for AddTableState { _ => None, } } + + fn current_mode(&self) -> AppMode { + self.app_mode + } } diff --git a/client/src/state/pages/auth.rs b/client/src/state/pages/auth.rs index 5ed538b..dffdcf9 100644 --- a/client/src/state/pages/auth.rs +++ b/client/src/state/pages/auth.rs @@ -1,5 +1,5 @@ // src/state/pages/auth.rs -use canvas::canvas::{CanvasState, ActionContext, CanvasAction}; +use canvas::canvas::{CanvasState, ActionContext, CanvasAction, AppMode}; use canvas::autocomplete::{AutocompleteCanvasState, AutocompleteState, SuggestionItem}; use lazy_static::lazy_static; @@ -22,7 +22,6 @@ pub struct AuthState { } /// Represents the state of the Login form UI -#[derive(Default)] pub struct LoginState { pub username: String, pub password: String, @@ -31,10 +30,26 @@ pub struct LoginState { pub current_cursor_pos: usize, pub has_unsaved_changes: bool, pub login_request_pending: bool, + pub app_mode: AppMode, +} + +impl Default for LoginState { + fn default() -> Self { + Self { + username: String::new(), + password: String::new(), + error_message: None, + current_field: 0, + current_cursor_pos: 0, + has_unsaved_changes: false, + login_request_pending: false, + app_mode: AppMode::Edit, + } + } } /// Represents the state of the Registration form UI -#[derive(Default, Clone)] +#[derive(Clone)] pub struct RegisterState { pub username: String, pub email: String, @@ -45,8 +60,26 @@ pub struct RegisterState { pub current_field: usize, pub current_cursor_pos: usize, pub has_unsaved_changes: bool, - // NEW: Replace old autocomplete with external library's system pub autocomplete: AutocompleteState, + pub app_mode: AppMode, +} + +impl Default for RegisterState { + fn default() -> Self { + Self { + username: String::new(), + email: String::new(), + password: String::new(), + password_confirmation: String::new(), + role: String::new(), + error_message: None, + current_field: 0, + current_cursor_pos: 0, + has_unsaved_changes: false, + autocomplete: AutocompleteState::new(), + app_mode: AppMode::Edit, + } + } } impl AuthState { @@ -57,7 +90,10 @@ impl AuthState { impl LoginState { pub fn new() -> Self { - Self::default() + Self { + app_mode: AppMode::Edit, + ..Default::default() + } } } @@ -65,6 +101,7 @@ impl RegisterState { pub fn new() -> Self { let mut state = Self { autocomplete: AutocompleteState::new(), + app_mode: AppMode::Edit, ..Default::default() }; @@ -146,6 +183,10 @@ impl CanvasState for LoginState { _ => None, } } + + fn current_mode(&self) -> AppMode { + self.app_mode + } } // Implement external library's CanvasState for RegisterState @@ -237,6 +278,10 @@ impl CanvasState for RegisterState { _ => None, } } + + fn current_mode(&self) -> AppMode { + self.app_mode + } } // Add autocomplete support for RegisterState diff --git a/client/src/state/pages/form.rs b/client/src/state/pages/form.rs index 0b8bd9a..93dc480 100644 --- a/client/src/state/pages/form.rs +++ b/client/src/state/pages/form.rs @@ -1,7 +1,7 @@ // src/state/pages/form.rs use crate::config::colors::themes::Theme; -use canvas::canvas::{CanvasState, CanvasAction, ActionContext, HighlightState}; +use canvas::canvas::{CanvasState, CanvasAction, ActionContext, HighlightState, AppMode}; use common::proto::komp_ac::search::search_response::Hit; use ratatui::layout::Rect; use ratatui::Frame; @@ -41,6 +41,7 @@ pub struct FormState { pub selected_suggestion_index: Option, pub autocomplete_loading: bool, pub link_display_map: HashMap, + pub app_mode: AppMode, } impl FormState { @@ -74,6 +75,7 @@ impl FormState { selected_suggestion_index: None, autocomplete_loading: false, link_display_map: HashMap::new(), + app_mode: AppMode::Edit, } } @@ -231,6 +233,15 @@ impl FormState { self.selected_suggestion_index = if self.autocomplete_active { Some(0) } else { None }; self.autocomplete_loading = false; } + + // NEW: Add these methods to change modes + pub fn set_edit_mode(&mut self) { + self.app_mode = AppMode::Edit; + } + + pub fn set_readonly_mode(&mut self) { + self.app_mode = AppMode::ReadOnly; + } } impl CanvasState for FormState { @@ -320,4 +331,8 @@ impl CanvasState for FormState { fn has_display_override(&self, index: usize) -> bool { self.link_display_map.contains_key(&index) } + + fn current_mode(&self) -> AppMode { + self.app_mode + } }