auth not working with canvas crate yet
This commit is contained in:
@@ -5,7 +5,6 @@ use crate::{
|
||||
state::pages::auth::LoginState,
|
||||
components::common::dialog,
|
||||
state::app::state::AppState,
|
||||
components::handlers::canvas_bridge::render_canvas_form, // Use our bridge function
|
||||
};
|
||||
use ratatui::{
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect, Margin},
|
||||
@@ -14,6 +13,16 @@ use ratatui::{
|
||||
Frame,
|
||||
};
|
||||
use crate::state::app::highlight::HighlightState;
|
||||
use canvas::canvas::{render_canvas, HighlightState as CanvasHighlightState}; // Use canvas library's render function
|
||||
|
||||
// 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,
|
||||
@@ -49,14 +58,15 @@ pub fn render_login(
|
||||
])
|
||||
.split(inner_area);
|
||||
|
||||
// --- FORM RENDERING (Using bridge function) ---
|
||||
render_canvas_form(
|
||||
// --- FORM RENDERING (Using canvas library directly) ---
|
||||
let canvas_highlight_state = convert_highlight_state(highlight_state);
|
||||
render_canvas(
|
||||
f,
|
||||
chunks[0],
|
||||
login_state, // LoginState implements CanvasState
|
||||
theme,
|
||||
theme, // Theme implements CanvasTheme
|
||||
is_edit_mode,
|
||||
highlight_state,
|
||||
&canvas_highlight_state,
|
||||
);
|
||||
|
||||
// --- ERROR MESSAGE ---
|
||||
|
||||
@@ -6,15 +6,25 @@ use crate::{
|
||||
components::common::dialog,
|
||||
state::app::state::AppState,
|
||||
modes::handlers::mode_manager::AppMode,
|
||||
components::handlers::canvas_bridge::render_canvas_form, // Use our bridge function
|
||||
};
|
||||
use ratatui::{
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect, Margin},
|
||||
style::{Style, Modifier, Color},
|
||||
widgets::{Block, BorderType, Borders, Paragraph, List, ListItem, ListState},
|
||||
widgets::{Block, BorderType, Borders, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
use crate::state::app::highlight::HighlightState;
|
||||
use canvas::canvas::{render_canvas, HighlightState as CanvasHighlightState}; // Use canvas library's render function
|
||||
use canvas::autocomplete::gui::render_autocomplete_dropdown; // Use canvas library's autocomplete dropdown
|
||||
|
||||
// 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_register(
|
||||
f: &mut Frame,
|
||||
@@ -49,14 +59,15 @@ pub fn render_register(
|
||||
])
|
||||
.split(inner_area);
|
||||
|
||||
// --- FORM RENDERING (Using bridge function) ---
|
||||
let input_rect = render_canvas_form(
|
||||
// --- FORM RENDERING (Using canvas library directly) ---
|
||||
let canvas_highlight_state = convert_highlight_state(highlight_state);
|
||||
let input_rect = render_canvas(
|
||||
f,
|
||||
chunks[0],
|
||||
state, // RegisterState implements CanvasState
|
||||
theme,
|
||||
theme, // Theme implements CanvasTheme
|
||||
is_edit_mode,
|
||||
highlight_state,
|
||||
&canvas_highlight_state,
|
||||
);
|
||||
|
||||
// --- HELP TEXT ---
|
||||
@@ -135,13 +146,17 @@ pub fn render_register(
|
||||
button_chunks[1],
|
||||
);
|
||||
|
||||
// --- AUTOCOMPLETE DROPDOWN (Simple bridge implementation) ---
|
||||
// --- AUTOCOMPLETE DROPDOWN (Using canvas library directly) ---
|
||||
if app_state.current_mode == AppMode::Edit {
|
||||
if let Some(autocomplete_state) = state.autocomplete_state() {
|
||||
if autocomplete_state.is_active && !autocomplete_state.suggestions.is_empty() {
|
||||
if let Some(field_rect) = input_rect {
|
||||
render_simple_autocomplete_dropdown(f, field_rect, f.area(), theme, autocomplete_state);
|
||||
}
|
||||
if let Some(input_rect) = input_rect {
|
||||
render_autocomplete_dropdown(
|
||||
f,
|
||||
f.area(), // Frame area
|
||||
input_rect, // Current input field rect
|
||||
theme, // Theme implements CanvasTheme
|
||||
autocomplete_state,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,89 +175,3 @@ pub fn render_register(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Simple autocomplete dropdown renderer (bridge implementation)
|
||||
fn render_simple_autocomplete_dropdown(
|
||||
f: &mut Frame,
|
||||
input_rect: Rect,
|
||||
frame_area: Rect,
|
||||
theme: &Theme,
|
||||
autocomplete_state: &canvas::AutocompleteState<String>,
|
||||
) {
|
||||
if autocomplete_state.is_loading {
|
||||
// Show loading indicator
|
||||
let loading_area = Rect {
|
||||
x: input_rect.x,
|
||||
y: input_rect.y + 1,
|
||||
width: input_rect.width,
|
||||
height: 3,
|
||||
};
|
||||
|
||||
let loading_paragraph = Paragraph::new("Loading suggestions...")
|
||||
.style(Style::default().fg(theme.fg))
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(ratatui::widgets::Borders::ALL)
|
||||
.border_style(Style::default().fg(theme.accent))
|
||||
.style(Style::default().bg(theme.bg)),
|
||||
);
|
||||
|
||||
f.render_widget(loading_paragraph, loading_area);
|
||||
return;
|
||||
}
|
||||
|
||||
if autocomplete_state.suggestions.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate dropdown position
|
||||
let dropdown_height = (autocomplete_state.suggestions.len() as u16).min(8) + 2;
|
||||
let dropdown_width = input_rect.width.max(20);
|
||||
|
||||
let mut dropdown_area = Rect {
|
||||
x: input_rect.x,
|
||||
y: input_rect.y + 1,
|
||||
width: dropdown_width,
|
||||
height: dropdown_height,
|
||||
};
|
||||
|
||||
// Keep dropdown within bounds
|
||||
if dropdown_area.bottom() > frame_area.height {
|
||||
dropdown_area.y = input_rect.y.saturating_sub(dropdown_height);
|
||||
}
|
||||
if dropdown_area.right() > frame_area.width {
|
||||
dropdown_area.x = frame_area.width.saturating_sub(dropdown_width);
|
||||
}
|
||||
|
||||
// Create list items
|
||||
let items: Vec<ListItem> = autocomplete_state
|
||||
.suggestions
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, suggestion)| {
|
||||
let is_selected = autocomplete_state.selected_index == Some(i);
|
||||
let style = if is_selected {
|
||||
Style::default()
|
||||
.fg(theme.bg)
|
||||
.bg(theme.highlight)
|
||||
.add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(theme.fg).bg(theme.bg)
|
||||
};
|
||||
|
||||
ListItem::new(suggestion.display_text.as_str()).style(style)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items).block(
|
||||
Block::default()
|
||||
.borders(ratatui::widgets::Borders::ALL)
|
||||
.border_style(Style::default().fg(theme.accent))
|
||||
.style(Style::default().bg(theme.bg)),
|
||||
);
|
||||
|
||||
let mut list_state = ListState::default();
|
||||
list_state.select(autocomplete_state.selected_index);
|
||||
|
||||
f.render_stateful_widget(list, dropdown_area, &mut list_state);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user