This commit is contained in:
filipriec
2025-08-20 11:33:34 +02:00
parent 2cda54633f
commit 589220a2ba
6 changed files with 11 additions and 62 deletions

View File

@@ -3,8 +3,7 @@ use crate::config::colors::themes::Theme;
use crate::state::app::highlight::HighlightState;
use crate::state::app::state::AppState;
use crate::state::pages::add_logic::{AddLogicFocus, AddLogicState};
use canvas::{render_canvas_default, render_canvas};
use canvas::canvas::HighlightState as CanvasHighlightState;
use canvas::{render_canvas, FormEditor};
use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Modifier, Style},
@@ -15,15 +14,6 @@ use ratatui::{
use crate::components::common::{dialog, autocomplete}; // Added autocomplete
use crate::config::binds::config::EditorKeybindingMode;
// Helper function to convert between HighlightState types
fn convert_highlight_state(local: &HighlightState) -> CanvasHighlightState {
match local {
HighlightState::Off => CanvasHighlightState::Off,
HighlightState::Characterwise { anchor } => CanvasHighlightState::Characterwise { anchor: *anchor },
HighlightState::Linewise { anchor_line } => CanvasHighlightState::Linewise { anchor_line: *anchor_line },
}
}
pub fn render_add_logic(
f: &mut Frame,
area: Rect,
@@ -31,7 +21,6 @@ pub fn render_add_logic(
app_state: &AppState,
add_logic_state: &mut AddLogicState,
is_edit_mode: bool,
highlight_state: &HighlightState,
) {
let main_block = Block::default()
.title(" Add New Logic Script ")
@@ -169,16 +158,12 @@ pub fn render_add_logic(
| AddLogicFocus::InputDescription
);
let canvas_highlight_state = convert_highlight_state(highlight_state);
let active_field_rect = render_canvas(
f,
canvas_area,
add_logic_state, // will later be wrapped in FormEditor
);
let editor = FormEditor::new(add_logic_state.clone());
let active_field_rect = render_canvas(f, canvas_area, &editor, theme);
// --- Render Autocomplete for Target Column ---
// `is_edit_mode` here refers to the general edit mode of the EventHandler
if is_edit_mode && add_logic_state.current_field() == 1 { // Target Column field
if is_edit_mode && editor.current_field() == 1 { // Target Column field
if add_logic_state.in_target_column_suggestion_mode && add_logic_state.show_target_column_suggestions {
if !add_logic_state.target_column_suggestions.is_empty() {
if let Some(input_rect) = active_field_rect {

View File

@@ -3,8 +3,7 @@ use crate::config::colors::themes::Theme;
use crate::state::app::highlight::HighlightState;
use crate::state::app::state::AppState;
use crate::state::pages::add_table::{AddTableFocus, AddTableState};
use canvas::{render_canvas_default, render_canvas};
use canvas::canvas::HighlightState as CanvasHighlightState;
use canvas::{render_canvas_default, render_canvas, FormEditor};
use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Modifier, Style},
@@ -14,15 +13,6 @@ use ratatui::{
};
use crate::components::common::dialog;
// Helper function to convert between HighlightState types
fn convert_highlight_state(local: &HighlightState) -> CanvasHighlightState {
match local {
HighlightState::Off => CanvasHighlightState::Off,
HighlightState::Characterwise { anchor } => CanvasHighlightState::Characterwise { anchor: *anchor },
HighlightState::Linewise { anchor_line } => CanvasHighlightState::Linewise { anchor_line: *anchor_line },
}
}
/// Renders the Add New Table page layout, structuring the display of table information,
/// input fields, and action buttons. Adapts layout based on terminal width.
pub fn render_add_table(
@@ -358,12 +348,8 @@ pub fn render_add_table(
);
// --- Canvas Rendering (Column Definition Input) - USING CANVAS LIBRARY ---
let canvas_highlight_state = convert_highlight_state(highlight_state);
let _active_field_rect = render_canvas(
f,
canvas_area,
add_table_state, // will later be wrapped in FormEditor
);
let editor = FormEditor::new(add_table_state.clone());
let _active_field_rect = render_canvas(f, canvas_area, &editor, theme);
// --- Button Style Helpers ---
let get_button_style = |button_focus: AddTableFocus, current_focus| {

View File

@@ -19,20 +19,6 @@ use canvas::{
render_suggestions_dropdown,
DefaultCanvasTheme,
};
use canvas::canvas::HighlightState as CanvasHighlightState;
// Helper function to convert between HighlightState types
fn convert_highlight_state(local: &HighlightState) -> CanvasHighlightState {
match local {
HighlightState::Off => CanvasHighlightState::Off,
HighlightState::Characterwise { anchor } => {
CanvasHighlightState::Characterwise { anchor: *anchor }
}
HighlightState::Linewise { anchor_line } => {
CanvasHighlightState::Linewise { anchor_line: *anchor_line }
}
}
}
pub fn render_login(
f: &mut Frame,
@@ -69,11 +55,8 @@ pub fn render_login(
])
.split(inner_area);
// --- FORM RENDERING (Using new canvas API) ---
let _canvas_highlight_state = convert_highlight_state(highlight_state);
// Wrap LoginState in FormEditor (no clone needed)
let editor = FormEditor::new(login_state);
let editor = FormEditor::new(login_state.clone());
// Use DefaultCanvasTheme instead of app Theme
let input_rect = render_canvas(

View File

@@ -2,7 +2,6 @@
use crate::tui::terminal::core::TerminalCore;
use crate::state::app::state::AppState;
use crate::state::pages::{form::FormState, auth::LoginState, auth::RegisterState};
use canvas::canvas::CanvasState;
use anyhow::Result;
pub struct CommandHandler;

View File

@@ -11,7 +11,7 @@ use crate::state::pages::admin::AdminState;
use crate::ui::handlers::context::UiContext;
use crate::modes::handlers::event::EventOutcome;
use crate::modes::general::command_navigation::{handle_command_navigation_event, NavigationState};
use canvas::canvas::CanvasState;
use canvas::DataProvider;
use anyhow::Result;
pub async fn handle_navigation_event(
@@ -90,10 +90,10 @@ pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_
if app_state.focused_button_index == 0 {
app_state.ui.focus_outside_canvas = false;
if app_state.ui.show_login {
let last_field_index = login_state.fields().len().saturating_sub(1);
let last_field_index = login_state.field_count().saturating_sub(1);
login_state.set_current_field(last_field_index);
} else {
let last_field_index = register_state.fields().len().saturating_sub(1);
let last_field_index = register_state.field_count().saturating_sub(1);
register_state.set_current_field(last_field_index);
}
} else {

View File

@@ -136,7 +136,6 @@ pub fn render_ui(
register_state,
app_state,
register_state.current_field() < 4, // Now using CanvasState trait method
highlight_state, // Uses local version
);
} else if app_state.ui.show_add_table {
render_add_table(
@@ -146,7 +145,6 @@ pub fn render_ui(
app_state,
&mut admin_state.add_table_state,
is_event_handler_edit_mode,
highlight_state, // Uses local version
);
} else if app_state.ui.show_add_logic {
render_add_logic(
@@ -156,7 +154,6 @@ pub fn render_ui(
app_state,
&mut admin_state.add_logic_state,
is_event_handler_edit_mode,
highlight_state, // Uses local version
);
} else if app_state.ui.show_login {
render_login(
@@ -166,7 +163,6 @@ pub fn render_ui(
login_state,
app_state,
login_state.current_field() < 2, // Now using CanvasState trait method
highlight_state, // Uses local version
);
} else if app_state.ui.show_admin {
crate::components::admin::admin_panel::render_admin_panel(