Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3decdac13 | ||
|
|
1baf89dde6 | ||
|
|
0219dc0ede | ||
|
|
1c662888c6 |
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -421,7 +421,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "client"
|
name = "client"
|
||||||
version = "0.2.5"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"common",
|
"common",
|
||||||
@@ -458,7 +458,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common"
|
name = "common"
|
||||||
version = "0.2.5"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"prost",
|
"prost",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -2589,7 +2589,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "server"
|
name = "server"
|
||||||
version = "0.2.5"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bcrypt",
|
"bcrypt",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ resolver = "2"
|
|||||||
[workspace.package]
|
[workspace.package]
|
||||||
# TODO: idk how to do the name, fix later
|
# TODO: idk how to do the name, fix later
|
||||||
# name = "Multieko2"
|
# name = "Multieko2"
|
||||||
version = "0.2.5"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
authors = ["Filip Priečinský <filippriec@gmail.com>"]
|
authors = ["Filip Priečinský <filippriec@gmail.com>"]
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ use crate::{
|
|||||||
config::colors::themes::Theme,
|
config::colors::themes::Theme,
|
||||||
state::pages::auth::AuthState,
|
state::pages::auth::AuthState,
|
||||||
components::common::dialog,
|
components::common::dialog,
|
||||||
state::state::AppState, // Add this import
|
state::state::AppState,
|
||||||
};
|
};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Alignment, Constraint, Direction, Layout, Rect, Margin},
|
layout::{Alignment, Constraint, Direction, Layout, Rect, Margin},
|
||||||
style::{Style, Modifier, Color}, // Removed unused Color import
|
style::{Style, Modifier, Color},
|
||||||
widgets::{Block, BorderType, Borders, Paragraph},
|
widgets::{Block, BorderType, Borders, Paragraph},
|
||||||
Frame, // Removed unused Span import
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn render_login(
|
pub fn render_login(
|
||||||
@@ -18,7 +18,7 @@ pub fn render_login(
|
|||||||
area: Rect,
|
area: Rect,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
state: &AuthState,
|
state: &AuthState,
|
||||||
app_state: &AppState, // Add AppState parameter
|
app_state: &AppState,
|
||||||
is_edit_mode: bool,
|
is_edit_mode: bool,
|
||||||
) {
|
) {
|
||||||
// Main container
|
// Main container
|
||||||
@@ -47,24 +47,9 @@ pub fn render_login(
|
|||||||
.split(inner_area);
|
.split(inner_area);
|
||||||
|
|
||||||
// --- FORM RENDERING ---
|
// --- FORM RENDERING ---
|
||||||
let input_block = Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_style(if is_edit_mode {
|
|
||||||
Style::default().fg(theme.accent)
|
|
||||||
} else {
|
|
||||||
Style::default().fg(theme.border)
|
|
||||||
})
|
|
||||||
.style(Style::default().bg(theme.bg));
|
|
||||||
|
|
||||||
// Calculate inner area BEFORE rendering
|
|
||||||
let input_area = input_block.inner(chunks[0]);
|
|
||||||
|
|
||||||
f.render_widget(input_block, chunks[0]);
|
|
||||||
|
|
||||||
// Use the canvas renderer for fields
|
|
||||||
crate::components::handlers::canvas::render_canvas(
|
crate::components::handlers::canvas::render_canvas(
|
||||||
f,
|
f,
|
||||||
input_area, // Use the pre-calculated area
|
chunks[0],
|
||||||
state,
|
state,
|
||||||
&["Username/Email", "Password"],
|
&["Username/Email", "Password"],
|
||||||
&state.current_field,
|
&state.current_field,
|
||||||
@@ -73,7 +58,17 @@ pub fn render_login(
|
|||||||
is_edit_mode,
|
is_edit_mode,
|
||||||
);
|
);
|
||||||
|
|
||||||
// --- BUTTONS --- (Keep this unchanged)
|
// --- ERROR MESSAGE ---
|
||||||
|
if let Some(err) = &state.error_message {
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(err.as_str())
|
||||||
|
.style(Style::default().fg(Color::Red))
|
||||||
|
.alignment(Alignment::Center),
|
||||||
|
chunks[1],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- BUTTONS ---
|
||||||
let button_chunks = Layout::default()
|
let button_chunks = Layout::default()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
|
||||||
@@ -123,24 +118,18 @@ pub fn render_login(
|
|||||||
button_chunks[1],
|
button_chunks[1],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Error message
|
// --- DIALOG ---
|
||||||
if let Some(err) = &state.error_message {
|
// Check the correct field name for showing the dialog
|
||||||
f.render_widget(
|
if app_state.ui.dialog.dialog_show {
|
||||||
Paragraph::new(err.as_str())
|
// Pass all 7 arguments correctly
|
||||||
.style(Style::default().fg(Color::Red))
|
|
||||||
.alignment(Alignment::Center),
|
|
||||||
chunks[1],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if app_state.ui.dialog.show_dialog {
|
|
||||||
dialog::render_dialog(
|
dialog::render_dialog(
|
||||||
f,
|
f,
|
||||||
f.area(), // Use area() instead of deprecated size()
|
f.area(),
|
||||||
theme,
|
theme,
|
||||||
&app_state.ui.dialog.dialog_title,
|
&app_state.ui.dialog.dialog_title,
|
||||||
&app_state.ui.dialog.dialog_message,
|
&app_state.ui.dialog.dialog_message,
|
||||||
app_state.ui.dialog.dialog_button_active,
|
&app_state.ui.dialog.dialog_buttons, // Pass buttons slice
|
||||||
|
app_state.ui.dialog.dialog_active_button_index, // Pass active index
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,101 +1,146 @@
|
|||||||
// src/components/common/dialog.rs
|
// src/components/common/dialog.rs
|
||||||
use ratatui::{
|
|
||||||
layout::{Constraint, Direction, Layout, Rect, Margin},
|
|
||||||
style::{Modifier, Style},
|
|
||||||
widgets::{Block, BorderType, Borders, Paragraph},
|
|
||||||
Frame,
|
|
||||||
text::{Text, Line, Span}
|
|
||||||
};
|
|
||||||
use ratatui::prelude::Alignment;
|
|
||||||
use crate::config::colors::themes::Theme;
|
use crate::config::colors::themes::Theme;
|
||||||
|
use ratatui::{
|
||||||
|
layout::{Constraint, Direction, Layout, Margin, Rect},
|
||||||
|
prelude::Alignment,
|
||||||
|
style::{Modifier, Style},
|
||||||
|
text::{Line, Span, Text},
|
||||||
|
widgets::{Block, BorderType, Borders, Paragraph, Clear}, // Added Clear
|
||||||
|
Frame,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn render_dialog(
|
pub fn render_dialog(
|
||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
title: &str,
|
dialog_title: &str,
|
||||||
message: &str,
|
dialog_message: &str,
|
||||||
is_active: bool,
|
dialog_buttons: &[String],
|
||||||
|
dialog_active_button_index: usize,
|
||||||
) {
|
) {
|
||||||
// Create a centered rect for the dialog
|
let message_lines: Vec<_> = dialog_message.lines().collect();
|
||||||
let dialog_area = centered_rect(60, 25, area);
|
let message_height = message_lines.len() as u16;
|
||||||
|
let button_row_height = if dialog_buttons.is_empty() { 0 } else { 3 };
|
||||||
|
let vertical_padding = 2; // Block borders (top/bottom)
|
||||||
|
let inner_vertical_margin = 2; // Margin inside block (top/bottom)
|
||||||
|
|
||||||
|
let required_inner_height =
|
||||||
|
message_height + button_row_height + inner_vertical_margin;
|
||||||
|
// Add block border height
|
||||||
|
let required_total_height = required_inner_height + vertical_padding;
|
||||||
|
|
||||||
|
// Use a fixed percentage width, clamped to min/max
|
||||||
|
let width_percentage: u16 = 60;
|
||||||
|
let dialog_width = (area.width * width_percentage / 100)
|
||||||
|
.max(20) // Minimum width
|
||||||
|
.min(area.width); // Maximum width
|
||||||
|
|
||||||
|
// Ensure height doesn't exceed available area
|
||||||
|
let dialog_height = required_total_height.min(area.height);
|
||||||
|
|
||||||
|
// Calculate centered area manually
|
||||||
|
let dialog_x = area.x + (area.width.saturating_sub(dialog_width)) / 2;
|
||||||
|
let dialog_y = area.y + (area.height.saturating_sub(dialog_height)) / 2;
|
||||||
|
let dialog_area = Rect::new(dialog_x, dialog_y, dialog_width, dialog_height);
|
||||||
|
|
||||||
|
// Clear the area first before drawing the dialog
|
||||||
|
f.render_widget(Clear, dialog_area);
|
||||||
|
|
||||||
// Main dialog container
|
|
||||||
let block = Block::default()
|
let block = Block::default()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Rounded)
|
.border_type(BorderType::Rounded)
|
||||||
.border_style(Style::default().fg(theme.accent))
|
.border_style(Style::default().fg(theme.accent))
|
||||||
.title(title)
|
.title(format!(" {} ", dialog_title)) // Add padding to title
|
||||||
.style(Style::default().bg(theme.bg));
|
.style(Style::default().bg(theme.bg));
|
||||||
|
|
||||||
f.render_widget(&block, dialog_area);
|
f.render_widget(block, dialog_area);
|
||||||
|
|
||||||
// Inner content area
|
// Calculate inner area *after* defining the block
|
||||||
let inner_area = block.inner(dialog_area).inner(Margin {
|
let inner_area = dialog_area.inner(Margin {
|
||||||
horizontal: 2,
|
horizontal: 2, // Left/Right padding inside border
|
||||||
vertical: 1,
|
vertical: 1, // Top/Bottom padding inside border
|
||||||
});
|
});
|
||||||
|
|
||||||
// Split into message and button areas
|
// Layout for Message and Buttons
|
||||||
|
let mut constraints = vec![
|
||||||
|
// Allocate space for message, ensuring at least 1 line height
|
||||||
|
Constraint::Min(message_height.max(1)),
|
||||||
|
];
|
||||||
|
if button_row_height > 0 {
|
||||||
|
constraints.push(Constraint::Length(button_row_height));
|
||||||
|
}
|
||||||
|
|
||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints(constraints)
|
||||||
Constraint::Min(3), // Message content
|
|
||||||
Constraint::Length(3), // Button
|
|
||||||
])
|
|
||||||
.split(inner_area);
|
.split(inner_area);
|
||||||
|
|
||||||
// Message text
|
// Render Message
|
||||||
let message_text = Text::from(message.lines().map(|l| Line::from(Span::styled(
|
let message_text = Text::from(
|
||||||
l,
|
message_lines
|
||||||
Style::default().fg(theme.fg)
|
.into_iter()
|
||||||
))).collect::<Vec<_>>());
|
.map(|l| Line::from(Span::styled(l, Style::default().fg(theme.fg))))
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
);
|
||||||
|
|
||||||
let message_paragraph = Paragraph::new(message_text)
|
let message_paragraph =
|
||||||
.alignment(Alignment::Center);
|
Paragraph::new(message_text).alignment(Alignment::Center);
|
||||||
|
// Render message in the first chunk
|
||||||
f.render_widget(message_paragraph, chunks[0]);
|
f.render_widget(message_paragraph, chunks[0]);
|
||||||
|
|
||||||
// OK Button
|
// Render Buttons if they exist and there's a chunk for them
|
||||||
let button_style = if is_active {
|
if !dialog_buttons.is_empty() && chunks.len() > 1 {
|
||||||
Style::default()
|
let button_area = chunks[1];
|
||||||
.fg(theme.highlight)
|
let button_count = dialog_buttons.len();
|
||||||
.add_modifier(Modifier::BOLD)
|
|
||||||
} else {
|
|
||||||
Style::default().fg(theme.fg)
|
|
||||||
};
|
|
||||||
|
|
||||||
let button_block = Block::default()
|
// Use Ratio for potentially more even distribution with few buttons
|
||||||
.borders(Borders::ALL)
|
let button_constraints = std::iter::repeat(Constraint::Ratio(
|
||||||
.border_type(BorderType::Plain)
|
1,
|
||||||
.border_style(Style::default().fg(theme.accent))
|
button_count as u32,
|
||||||
.style(Style::default().bg(theme.bg));
|
))
|
||||||
|
.take(button_count)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
f.render_widget(
|
let button_chunks = Layout::default()
|
||||||
Paragraph::new("OK")
|
.direction(Direction::Horizontal)
|
||||||
.block(button_block)
|
.constraints(button_constraints)
|
||||||
.style(button_style)
|
.horizontal_margin(1) // Add space between buttons
|
||||||
.alignment(Alignment::Center),
|
.split(button_area);
|
||||||
chunks[1],
|
|
||||||
);
|
for (i, button_label) in dialog_buttons.iter().enumerate() {
|
||||||
|
// Ensure we don't try to render into a non-existent chunk
|
||||||
|
if i >= button_chunks.len() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
let is_active = i == dialog_active_button_index;
|
||||||
|
let (button_style, border_style) = if is_active {
|
||||||
|
(
|
||||||
|
Style::default()
|
||||||
|
.fg(theme.highlight)
|
||||||
|
.add_modifier(Modifier::BOLD),
|
||||||
|
Style::default().fg(theme.accent), // Highlight border
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
(
|
||||||
|
Style::default().fg(theme.fg),
|
||||||
|
Style::default().fg(theme.border), // Normal border
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
let button_block = Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.border_type(BorderType::Plain)
|
||||||
|
.border_style(border_style);
|
||||||
|
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(button_label.as_str())
|
||||||
|
.block(button_block)
|
||||||
|
.style(button_style)
|
||||||
|
.alignment(Alignment::Center),
|
||||||
|
button_chunks[i],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper function to center a rect with given percentage values
|
|
||||||
fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
|
|
||||||
let popup_layout = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Percentage((100 - percent_y) / 2),
|
|
||||||
Constraint::Percentage(percent_y),
|
|
||||||
Constraint::Percentage((100 - percent_y) / 2),
|
|
||||||
])
|
|
||||||
.split(r);
|
|
||||||
|
|
||||||
Layout::default()
|
|
||||||
.direction(Direction::Horizontal)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Percentage((100 - percent_x) / 2),
|
|
||||||
Constraint::Percentage(percent_x),
|
|
||||||
Constraint::Percentage((100 - percent_x) / 2),
|
|
||||||
])
|
|
||||||
.split(popup_layout[1])[1]
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
|||||||
use crate::components::IntroState;
|
use crate::components::IntroState;
|
||||||
use crate::modes::handlers::mode_manager::AppMode;
|
use crate::modes::handlers::mode_manager::AppMode;
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct DialogState {
|
pub struct DialogState {
|
||||||
pub show_dialog: bool,
|
pub dialog_show: bool,
|
||||||
pub dialog_title: String,
|
pub dialog_title: String,
|
||||||
pub dialog_message: String,
|
pub dialog_message: String,
|
||||||
pub dialog_button_active: bool,
|
pub dialog_buttons: Vec<String>,
|
||||||
|
pub dialog_active_button_index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UiState {
|
pub struct UiState {
|
||||||
@@ -77,21 +77,55 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add dialog helper methods
|
// Add dialog helper methods
|
||||||
pub fn show_dialog(&mut self, title: &str, message: &str) {
|
/// Shows a dialog with the given title, message, and buttons.
|
||||||
self.ui.dialog.show_dialog = true;
|
/// The first button (index 0) is active by default.
|
||||||
|
pub fn show_dialog(
|
||||||
|
&mut self,
|
||||||
|
title: &str,
|
||||||
|
message: &str,
|
||||||
|
buttons: Vec<String>,
|
||||||
|
) {
|
||||||
self.ui.dialog.dialog_title = title.to_string();
|
self.ui.dialog.dialog_title = title.to_string();
|
||||||
self.ui.dialog.dialog_message = message.to_string();
|
self.ui.dialog.dialog_message = message.to_string();
|
||||||
self.ui.dialog.dialog_button_active = true;
|
self.ui.dialog.dialog_buttons = buttons;
|
||||||
|
self.ui.dialog.dialog_active_button_index = 0; // Default to first button
|
||||||
|
self.ui.dialog.dialog_show = true; // Use new name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Hides the dialog and clears its content.
|
||||||
pub fn hide_dialog(&mut self) {
|
pub fn hide_dialog(&mut self) {
|
||||||
self.ui.dialog.show_dialog = false;
|
self.ui.dialog.dialog_show = false; // Use new name
|
||||||
self.ui.dialog.dialog_title.clear();
|
self.ui.dialog.dialog_title.clear();
|
||||||
self.ui.dialog.dialog_message.clear();
|
self.ui.dialog.dialog_message.clear();
|
||||||
|
self.ui.dialog.dialog_buttons.clear();
|
||||||
|
self.ui.dialog.dialog_active_button_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_dialog_button_active(&mut self, active: bool) {
|
/// Sets the active button index, wrapping around if necessary.
|
||||||
self.ui.dialog.dialog_button_active = active;
|
pub fn next_dialog_button(&mut self) {
|
||||||
|
if !self.ui.dialog.dialog_buttons.is_empty() {
|
||||||
|
let next_index = (self.ui.dialog.dialog_active_button_index + 1)
|
||||||
|
% self.ui.dialog.dialog_buttons.len();
|
||||||
|
self.ui.dialog.dialog_active_button_index = next_index; // Use new name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the active button index, wrapping around if necessary.
|
||||||
|
pub fn previous_dialog_button(&mut self) {
|
||||||
|
if !self.ui.dialog.dialog_buttons.is_empty() {
|
||||||
|
let len = self.ui.dialog.dialog_buttons.len();
|
||||||
|
let prev_index =
|
||||||
|
(self.ui.dialog.dialog_active_button_index + len - 1) % len;
|
||||||
|
self.ui.dialog.dialog_active_button_index = prev_index; // Use new name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets the label of the currently active button, if any.
|
||||||
|
pub fn get_active_dialog_button_label(&self) -> Option<&str> {
|
||||||
|
self.ui.dialog
|
||||||
|
.dialog_buttons // Use new name
|
||||||
|
.get(self.ui.dialog.dialog_active_button_index) // Use new name
|
||||||
|
.map(|s| s.as_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,3 +143,16 @@ impl Default for UiState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the Default implementation for DialogState itself
|
||||||
|
impl Default for DialogState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
dialog_show: false, // Use new name
|
||||||
|
dialog_title: String::new(), // Use new name
|
||||||
|
dialog_message: String::new(), // Use new name
|
||||||
|
dialog_buttons: Vec::new(), // Use new name
|
||||||
|
dialog_active_button_index: 0, // Use new name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ use crate::services::auth::AuthClient;
|
|||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
use crate::state::canvas_state::CanvasState;
|
use crate::state::canvas_state::CanvasState;
|
||||||
|
// Remove unused import if CanvasState is not directly used here
|
||||||
|
// use crate::state::canvas_state::CanvasState;
|
||||||
|
|
||||||
/// Attempts to log the user in using the provided credentials via gRPC.
|
/// Attempts to log the user in using the provided credentials via gRPC.
|
||||||
/// Updates AuthState and AppState on success or failure.
|
/// Updates AuthState and AppState on success or failure.
|
||||||
@@ -14,48 +16,87 @@ pub async fn save(
|
|||||||
let identifier = auth_state.username.clone();
|
let identifier = auth_state.username.clone();
|
||||||
let password = auth_state.password.clone();
|
let password = auth_state.password.clone();
|
||||||
|
|
||||||
|
// Clear previous error/dialog state before attempting
|
||||||
|
auth_state.error_message = None;
|
||||||
|
// Use the helper to ensure dialog is hidden and cleared properly
|
||||||
|
app_state.hide_dialog();
|
||||||
|
|
||||||
// Call the gRPC login method
|
// Call the gRPC login method
|
||||||
match auth_client.login(identifier, password).await {
|
match auth_client.login(identifier, password).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
// Store authentication details on success
|
// Store authentication details on success
|
||||||
auth_state.auth_token = Some(response.access_token);
|
auth_state.auth_token = Some(response.access_token.clone());
|
||||||
auth_state.user_id = Some(response.user_id);
|
auth_state.user_id = Some(response.user_id.clone());
|
||||||
auth_state.role = Some(response.role);
|
auth_state.role = Some(response.role.clone());
|
||||||
auth_state.error_message = None;
|
auth_state.set_has_unsaved_changes(false);
|
||||||
auth_state.set_has_unsaved_changes(false); // Mark as "saved"
|
|
||||||
|
|
||||||
// Update app state to transition from login to the main form view
|
let success_message = format!(
|
||||||
app_state.ui.show_login = false;
|
"Login Successful!\n\n\
|
||||||
app_state.ui.show_form = true; // Assuming form is the next view
|
Access Token: {}\n\
|
||||||
|
Token Type: {}\n\
|
||||||
|
Expires In: {}\n\
|
||||||
|
User ID: {}\n\
|
||||||
|
Role: {}",
|
||||||
|
response.access_token,
|
||||||
|
response.token_type,
|
||||||
|
response.expires_in,
|
||||||
|
response.user_id,
|
||||||
|
response.role
|
||||||
|
);
|
||||||
|
|
||||||
Ok("Login successful!".to_string())
|
// Use the helper method to configure and show the dialog
|
||||||
|
app_state.show_dialog(
|
||||||
|
"Login Success",
|
||||||
|
&success_message,
|
||||||
|
vec!["OK".to_string()], // Pass buttons here
|
||||||
|
);
|
||||||
|
// REMOVE these lines:
|
||||||
|
// app_state.ui.dialog.dialog_title = "Login Success".to_string();
|
||||||
|
// app_state.ui.dialog.dialog_message = success_message;
|
||||||
|
// app_state.ui.dialog.dialog_show = true;
|
||||||
|
// app_state.ui.dialog.dialog_button_active = true;
|
||||||
|
|
||||||
|
Ok("Login successful, details shown in dialog.".to_string())
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// Store error message on failure
|
let error_message = format!("{}", e);
|
||||||
let error_message = format!("Login failed: {}", e);
|
|
||||||
auth_state.error_message = Some(error_message.clone());
|
// Use the helper method to configure and show the dialog
|
||||||
// Keep unsaved changes true if login fails, allowing retry/revert
|
app_state.show_dialog(
|
||||||
|
"Login Failed",
|
||||||
|
&error_message,
|
||||||
|
vec!["OK".to_string()], // Pass buttons here
|
||||||
|
);
|
||||||
|
// REMOVE these lines:
|
||||||
|
// app_state.ui.dialog.dialog_title = "Login Failed".to_string();
|
||||||
|
// app_state.ui.dialog.dialog_message = error_message.clone();
|
||||||
|
// app_state.ui.dialog.dialog_show = true;
|
||||||
|
// app_state.ui.dialog.dialog_button_active = true;
|
||||||
|
|
||||||
auth_state.set_has_unsaved_changes(true);
|
auth_state.set_has_unsaved_changes(true);
|
||||||
Ok(error_message) // Return error message to display
|
|
||||||
|
Ok(format!("Login failed: {}", error_message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reverts the login form fields to empty and returns to the previous screen (Intro).
|
/// Reverts the login form fields to empty and returns to the previous screen (Intro).
|
||||||
/// This function is now named 'revert' to match the 'form' counterpart.
|
|
||||||
pub async fn revert(
|
pub async fn revert(
|
||||||
auth_state: &mut AuthState,
|
auth_state: &mut AuthState,
|
||||||
app_state: &mut AppState,
|
_app_state: &mut AppState, // Prefix unused variable
|
||||||
) -> String {
|
) -> String {
|
||||||
// Clear the input fields
|
// Clear the input fields
|
||||||
auth_state.username.clear();
|
auth_state.username.clear();
|
||||||
auth_state.password.clear();
|
auth_state.password.clear();
|
||||||
auth_state.error_message = None; // Clear any previous error
|
auth_state.error_message = None;
|
||||||
auth_state.set_has_unsaved_changes(false); // Fields are cleared, no unsaved changes
|
auth_state.set_has_unsaved_changes(false);
|
||||||
|
|
||||||
// Update app state to hide login and show the previous screen (Intro)
|
// Ensure dialog is hidden if revert is called
|
||||||
app_state.ui.show_login = false;
|
// _app_state.hide_dialog(); // Uncomment if needed
|
||||||
app_state.ui.show_intro = true; // Assuming Intro is the screen before login
|
|
||||||
|
// Navigation logic (currently disabled in original code)
|
||||||
|
// _app_state.ui.show_login = false;
|
||||||
|
// _app_state.ui.show_intro = true;
|
||||||
|
|
||||||
"Login reverted".to_string()
|
"Login reverted".to_string()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user