new canvas library changed client for compatibility

This commit is contained in:
Priec
2025-07-30 22:42:32 +02:00
parent ad82bd4302
commit cc19c61f37
4 changed files with 83 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
// src/state/pages/add_logic.rs // src/state/pages/add_logic.rs
use crate::config::binds::config::{EditorConfig, EditorKeybindingMode}; 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 crate::components::common::text_editor::{TextEditor, VimState};
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
@@ -54,6 +54,7 @@ pub struct AddLogicState {
// New fields for same-profile table names and column autocomplete // New fields for same-profile table names and column autocomplete
pub same_profile_table_names: Vec<String>, // Tables from same profile only pub same_profile_table_names: Vec<String>, // Tables from same profile only
pub script_editor_awaiting_column_autocomplete: Option<String>, // Table name waiting for column fetch pub script_editor_awaiting_column_autocomplete: Option<String>, // Table name waiting for column fetch
pub app_mode: AppMode,
} }
impl AddLogicState { impl AddLogicState {
@@ -91,6 +92,7 @@ impl AddLogicState {
same_profile_table_names: Vec::new(), same_profile_table_names: Vec::new(),
script_editor_awaiting_column_autocomplete: None, script_editor_awaiting_column_autocomplete: None,
app_mode: AppMode::Edit,
} }
} }
@@ -269,7 +271,9 @@ impl AddLogicState {
impl Default for AddLogicState { impl Default for AddLogicState {
fn default() -> Self { 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, _ => None,
} }
} }
fn current_mode(&self) -> AppMode {
self.app_mode
}
} }

View File

@@ -1,5 +1,5 @@
// src/state/pages/add_table.rs // 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 ratatui::widgets::TableState;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -63,6 +63,7 @@ pub struct AddTableState {
pub column_name_cursor_pos: usize, pub column_name_cursor_pos: usize,
pub column_type_cursor_pos: usize, pub column_type_cursor_pos: usize,
pub has_unsaved_changes: bool, pub has_unsaved_changes: bool,
pub app_mode: AppMode,
} }
impl Default for AddTableState { impl Default for AddTableState {
@@ -85,6 +86,7 @@ impl Default for AddTableState {
column_name_cursor_pos: 0, column_name_cursor_pos: 0,
column_type_cursor_pos: 0, column_type_cursor_pos: 0,
has_unsaved_changes: false, has_unsaved_changes: false,
app_mode: AppMode::Edit,
} }
} }
} }
@@ -297,4 +299,8 @@ impl CanvasState for AddTableState {
_ => None, _ => None,
} }
} }
fn current_mode(&self) -> AppMode {
self.app_mode
}
} }

View File

@@ -1,5 +1,5 @@
// src/state/pages/auth.rs // 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 canvas::autocomplete::{AutocompleteCanvasState, AutocompleteState, SuggestionItem};
use lazy_static::lazy_static; use lazy_static::lazy_static;
@@ -22,7 +22,6 @@ pub struct AuthState {
} }
/// Represents the state of the Login form UI /// Represents the state of the Login form UI
#[derive(Default)]
pub struct LoginState { pub struct LoginState {
pub username: String, pub username: String,
pub password: String, pub password: String,
@@ -31,10 +30,26 @@ pub struct LoginState {
pub current_cursor_pos: usize, pub current_cursor_pos: usize,
pub has_unsaved_changes: bool, pub has_unsaved_changes: bool,
pub login_request_pending: 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 /// Represents the state of the Registration form UI
#[derive(Default, Clone)] #[derive(Clone)]
pub struct RegisterState { pub struct RegisterState {
pub username: String, pub username: String,
pub email: String, pub email: String,
@@ -45,8 +60,26 @@ pub struct RegisterState {
pub current_field: usize, pub current_field: usize,
pub current_cursor_pos: usize, pub current_cursor_pos: usize,
pub has_unsaved_changes: bool, pub has_unsaved_changes: bool,
// NEW: Replace old autocomplete with external library's system
pub autocomplete: AutocompleteState<String>, pub autocomplete: AutocompleteState<String>,
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 { impl AuthState {
@@ -57,7 +90,10 @@ impl AuthState {
impl LoginState { impl LoginState {
pub fn new() -> Self { pub fn new() -> Self {
Self::default() Self {
app_mode: AppMode::Edit,
..Default::default()
}
} }
} }
@@ -65,6 +101,7 @@ impl RegisterState {
pub fn new() -> Self { pub fn new() -> Self {
let mut state = Self { let mut state = Self {
autocomplete: AutocompleteState::new(), autocomplete: AutocompleteState::new(),
app_mode: AppMode::Edit,
..Default::default() ..Default::default()
}; };
@@ -146,6 +183,10 @@ impl CanvasState for LoginState {
_ => None, _ => None,
} }
} }
fn current_mode(&self) -> AppMode {
self.app_mode
}
} }
// Implement external library's CanvasState for RegisterState // Implement external library's CanvasState for RegisterState
@@ -237,6 +278,10 @@ impl CanvasState for RegisterState {
_ => None, _ => None,
} }
} }
fn current_mode(&self) -> AppMode {
self.app_mode
}
} }
// Add autocomplete support for RegisterState // Add autocomplete support for RegisterState

View File

@@ -1,7 +1,7 @@
// src/state/pages/form.rs // src/state/pages/form.rs
use crate::config::colors::themes::Theme; 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 common::proto::komp_ac::search::search_response::Hit;
use ratatui::layout::Rect; use ratatui::layout::Rect;
use ratatui::Frame; use ratatui::Frame;
@@ -41,6 +41,7 @@ pub struct FormState {
pub selected_suggestion_index: Option<usize>, pub selected_suggestion_index: Option<usize>,
pub autocomplete_loading: bool, pub autocomplete_loading: bool,
pub link_display_map: HashMap<usize, String>, pub link_display_map: HashMap<usize, String>,
pub app_mode: AppMode,
} }
impl FormState { impl FormState {
@@ -74,6 +75,7 @@ impl FormState {
selected_suggestion_index: None, selected_suggestion_index: None,
autocomplete_loading: false, autocomplete_loading: false,
link_display_map: HashMap::new(), 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.selected_suggestion_index = if self.autocomplete_active { Some(0) } else { None };
self.autocomplete_loading = false; 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 { impl CanvasState for FormState {
@@ -320,4 +331,8 @@ impl CanvasState for FormState {
fn has_display_override(&self, index: usize) -> bool { fn has_display_override(&self, index: usize) -> bool {
self.link_display_map.contains_key(&index) self.link_display_map.contains_key(&index)
} }
fn current_mode(&self) -> AppMode {
self.app_mode
}
} }