login moved to the pages
This commit is contained in:
@@ -25,10 +25,11 @@ use crate::state::{
|
|||||||
},
|
},
|
||||||
pages::{
|
pages::{
|
||||||
admin::AdminState,
|
admin::AdminState,
|
||||||
auth::{AuthState, LoginState, RegisterState},
|
auth::{AuthState, RegisterState},
|
||||||
intro::IntroState,
|
intro::IntroState,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use crate::pages::login::LoginState;
|
||||||
use crate::tui::common::register;
|
use crate::tui::common::register;
|
||||||
use crate::pages::login;
|
use crate::pages::login;
|
||||||
use crate::pages::login::logic;
|
use crate::pages::login::logic;
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
use crate::services::auth::AuthClient;
|
use crate::services::auth::AuthClient;
|
||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
use crate::state::pages::auth::LoginState;
|
|
||||||
use crate::state::app::state::AppState;
|
use crate::state::app::state::AppState;
|
||||||
use crate::buffer::state::{AppView, BufferState};
|
use crate::buffer::state::{AppView, BufferState};
|
||||||
use crate::config::storage::storage::{StoredAuthData, save_auth_data};
|
use crate::config::storage::storage::{StoredAuthData, save_auth_data};
|
||||||
use crate::ui::handlers::context::DialogPurpose;
|
use crate::ui::handlers::context::DialogPurpose;
|
||||||
use common::proto::komp_ac::auth::LoginResponse;
|
use common::proto::komp_ac::auth::LoginResponse;
|
||||||
|
use crate::pages::login::LoginState;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use tokio::spawn;
|
use tokio::spawn;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ pub mod state;
|
|||||||
pub mod ui;
|
pub mod ui;
|
||||||
pub mod logic;
|
pub mod logic;
|
||||||
|
|
||||||
pub use state::LoginState;
|
pub use state::*;
|
||||||
pub use ui::render_login;
|
pub use ui::render_login;
|
||||||
pub use logic::*;
|
pub use logic::*;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// src/pages/login/state.rs
|
// src/pages/login/state.rs
|
||||||
|
|
||||||
use canvas::AppMode;
|
use canvas::{AppMode, DataProvider};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct LoginState {
|
pub struct LoginState {
|
||||||
@@ -28,3 +28,94 @@ impl Default for LoginState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl LoginState {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
app_mode: AppMode::Edit,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn current_field(&self) -> usize {
|
||||||
|
self.current_field
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn current_cursor_pos(&self) -> usize {
|
||||||
|
self.current_cursor_pos
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_current_field(&mut self, index: usize) {
|
||||||
|
if index < 2 {
|
||||||
|
self.current_field = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_current_cursor_pos(&mut self, pos: usize) {
|
||||||
|
self.current_cursor_pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_current_input(&self) -> &str {
|
||||||
|
match self.current_field {
|
||||||
|
0 => &self.username,
|
||||||
|
1 => &self.password,
|
||||||
|
_ => "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_current_input_mut(&mut self) -> &mut String {
|
||||||
|
match self.current_field {
|
||||||
|
0 => &mut self.username,
|
||||||
|
1 => &mut self.password,
|
||||||
|
_ => panic!("Invalid current_field index in LoginState"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn current_mode(&self) -> AppMode {
|
||||||
|
self.app_mode
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_unsaved_changes(&self) -> bool {
|
||||||
|
self.has_unsaved_changes
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_has_unsaved_changes(&mut self, changed: bool) {
|
||||||
|
self.has_unsaved_changes = changed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implement DataProvider for LoginState
|
||||||
|
impl DataProvider for LoginState {
|
||||||
|
fn field_count(&self) -> usize {
|
||||||
|
2
|
||||||
|
}
|
||||||
|
|
||||||
|
fn field_name(&self, index: usize) -> &str {
|
||||||
|
match index {
|
||||||
|
0 => "Username/Email",
|
||||||
|
1 => "Password",
|
||||||
|
_ => "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn field_value(&self, index: usize) -> &str {
|
||||||
|
match index {
|
||||||
|
0 => &self.username,
|
||||||
|
1 => &self.password,
|
||||||
|
_ => "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_field_value(&mut self, index: usize, value: String) {
|
||||||
|
match index {
|
||||||
|
0 => self.username = value,
|
||||||
|
1 => self.password = value,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
self.has_unsaved_changes = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn supports_suggestions(&self, _field_index: usize) -> bool {
|
||||||
|
false // Login form doesn't support suggestions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::colors::themes::Theme,
|
config::colors::themes::Theme,
|
||||||
state::pages::auth::LoginState,
|
|
||||||
state::app::state::AppState,
|
state::app::state::AppState,
|
||||||
};
|
};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
@@ -17,6 +16,7 @@ use canvas::{
|
|||||||
render_suggestions_dropdown,
|
render_suggestions_dropdown,
|
||||||
DefaultCanvasTheme,
|
DefaultCanvasTheme,
|
||||||
};
|
};
|
||||||
|
use crate::pages::login::LoginState;
|
||||||
use crate::dialog;
|
use crate::dialog;
|
||||||
|
|
||||||
pub fn render_login(
|
pub fn render_login(
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
// src/pages/routing/router.rs
|
// src/pages/routing/router.rs
|
||||||
use crate::state::pages::{
|
use crate::state::pages::{
|
||||||
admin::AdminState,
|
admin::AdminState,
|
||||||
auth::{AuthState, LoginState, RegisterState},
|
auth::{AuthState, RegisterState},
|
||||||
intro::IntroState,
|
intro::IntroState,
|
||||||
add_logic::AddLogicState,
|
add_logic::AddLogicState,
|
||||||
add_table::AddTableState,
|
add_table::AddTableState,
|
||||||
};
|
};
|
||||||
use crate::pages::forms::FormState;
|
use crate::pages::forms::FormState;
|
||||||
|
use crate::pages::login::LoginState;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Page {
|
pub enum Page {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// src/state/pages/auth.rs
|
// src/state/pages/auth.rs
|
||||||
|
|
||||||
use canvas::{DataProvider, AppMode};
|
use canvas::{DataProvider, AppMode};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
@@ -20,34 +21,6 @@ pub struct AuthState {
|
|||||||
pub decoded_username: Option<String>,
|
pub decoded_username: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the state of the Login form UI
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct LoginState {
|
|
||||||
pub username: String,
|
|
||||||
pub password: String,
|
|
||||||
pub error_message: Option<String>,
|
|
||||||
pub current_field: usize,
|
|
||||||
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
|
/// Represents the state of the Registration form UI
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct RegisterState {
|
pub struct RegisterState {
|
||||||
@@ -61,7 +34,6 @@ pub struct RegisterState {
|
|||||||
pub current_cursor_pos: usize,
|
pub current_cursor_pos: usize,
|
||||||
pub has_unsaved_changes: bool,
|
pub has_unsaved_changes: bool,
|
||||||
pub app_mode: AppMode,
|
pub app_mode: AppMode,
|
||||||
// Keep role suggestions for later integration
|
|
||||||
pub role_suggestions: Vec<String>,
|
pub role_suggestions: Vec<String>,
|
||||||
pub role_suggestions_active: bool,
|
pub role_suggestions_active: bool,
|
||||||
}
|
}
|
||||||
@@ -91,63 +63,6 @@ impl AuthState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LoginState {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
app_mode: AppMode::Edit,
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Legacy method compatibility
|
|
||||||
pub fn current_field(&self) -> usize {
|
|
||||||
self.current_field
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn current_cursor_pos(&self) -> usize {
|
|
||||||
self.current_cursor_pos
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_current_field(&mut self, index: usize) {
|
|
||||||
if index < 2 {
|
|
||||||
self.current_field = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_current_cursor_pos(&mut self, pos: usize) {
|
|
||||||
self.current_cursor_pos = pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_current_input(&self) -> &str {
|
|
||||||
match self.current_field {
|
|
||||||
0 => &self.username,
|
|
||||||
1 => &self.password,
|
|
||||||
_ => "",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_current_input_mut(&mut self) -> &mut String {
|
|
||||||
match self.current_field {
|
|
||||||
0 => &mut self.username,
|
|
||||||
1 => &mut self.password,
|
|
||||||
_ => panic!("Invalid current_field index in LoginState"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn current_mode(&self) -> AppMode {
|
|
||||||
self.app_mode
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add missing methods that used to come from CanvasState trait
|
|
||||||
pub fn has_unsaved_changes(&self) -> bool {
|
|
||||||
self.has_unsaved_changes
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_has_unsaved_changes(&mut self, changed: bool) {
|
|
||||||
self.has_unsaved_changes = changed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RegisterState {
|
impl RegisterState {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -158,7 +73,6 @@ impl RegisterState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy method compatibility
|
|
||||||
pub fn current_field(&self) -> usize {
|
pub fn current_field(&self) -> usize {
|
||||||
self.current_field
|
self.current_field
|
||||||
}
|
}
|
||||||
@@ -171,7 +85,6 @@ impl RegisterState {
|
|||||||
if index < 5 {
|
if index < 5 {
|
||||||
self.current_field = index;
|
self.current_field = index;
|
||||||
|
|
||||||
// Auto-activate role suggestions when moving to role field (index 4)
|
|
||||||
if index == 4 {
|
if index == 4 {
|
||||||
self.activate_role_suggestions();
|
self.activate_role_suggestions();
|
||||||
} else {
|
} else {
|
||||||
@@ -195,8 +108,8 @@ impl RegisterState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_current_input_mut(&mut self) -> &mut String {
|
pub fn get_current_input_mut(&mut self, index: usize) -> &mut String {
|
||||||
match self.current_field {
|
match index {
|
||||||
0 => &mut self.username,
|
0 => &mut self.username,
|
||||||
1 => &mut self.email,
|
1 => &mut self.email,
|
||||||
2 => &mut self.password,
|
2 => &mut self.password,
|
||||||
@@ -210,10 +123,8 @@ impl RegisterState {
|
|||||||
self.app_mode
|
self.app_mode
|
||||||
}
|
}
|
||||||
|
|
||||||
// Role suggestions management
|
|
||||||
pub fn activate_role_suggestions(&mut self) {
|
pub fn activate_role_suggestions(&mut self) {
|
||||||
self.role_suggestions_active = true;
|
self.role_suggestions_active = true;
|
||||||
// Filter suggestions based on current input
|
|
||||||
let current_input = self.role.to_lowercase();
|
let current_input = self.role.to_lowercase();
|
||||||
self.role_suggestions = AVAILABLE_ROLES
|
self.role_suggestions = AVAILABLE_ROLES
|
||||||
.iter()
|
.iter()
|
||||||
@@ -234,7 +145,6 @@ impl RegisterState {
|
|||||||
&self.role_suggestions
|
&self.role_suggestions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add missing methods that used to come from CanvasState trait
|
|
||||||
pub fn has_unsaved_changes(&self) -> bool {
|
pub fn has_unsaved_changes(&self) -> bool {
|
||||||
self.has_unsaved_changes
|
self.has_unsaved_changes
|
||||||
}
|
}
|
||||||
@@ -244,43 +154,6 @@ impl RegisterState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2: Implement DataProvider for LoginState
|
|
||||||
impl DataProvider for LoginState {
|
|
||||||
fn field_count(&self) -> usize {
|
|
||||||
2
|
|
||||||
}
|
|
||||||
|
|
||||||
fn field_name(&self, index: usize) -> &str {
|
|
||||||
match index {
|
|
||||||
0 => "Username/Email",
|
|
||||||
1 => "Password",
|
|
||||||
_ => "",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn field_value(&self, index: usize) -> &str {
|
|
||||||
match index {
|
|
||||||
0 => &self.username,
|
|
||||||
1 => &self.password,
|
|
||||||
_ => "",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_field_value(&mut self, index: usize, value: String) {
|
|
||||||
match index {
|
|
||||||
0 => self.username = value,
|
|
||||||
1 => self.password = value,
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
self.has_unsaved_changes = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn supports_suggestions(&self, _field_index: usize) -> bool {
|
|
||||||
false // Login form doesn't support suggestions
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 3: Implement DataProvider for RegisterState
|
|
||||||
impl DataProvider for RegisterState {
|
impl DataProvider for RegisterState {
|
||||||
fn field_count(&self) -> usize {
|
fn field_count(&self) -> usize {
|
||||||
5
|
5
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use crate::modes::common::commands::CommandHandler;
|
|||||||
use crate::modes::handlers::event::{EventHandler, EventOutcome};
|
use crate::modes::handlers::event::{EventHandler, EventOutcome};
|
||||||
use crate::modes::handlers::mode_manager::{AppMode, ModeManager};
|
use crate::modes::handlers::mode_manager::{AppMode, ModeManager};
|
||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
use crate::state::pages::auth::LoginState;
|
|
||||||
use crate::state::pages::auth::RegisterState;
|
use crate::state::pages::auth::RegisterState;
|
||||||
use crate::state::pages::admin::AdminState;
|
use crate::state::pages::admin::AdminState;
|
||||||
use crate::state::pages::admin::AdminFocus;
|
use crate::state::pages::admin::AdminFocus;
|
||||||
@@ -23,6 +22,7 @@ use crate::tui::terminal::{EventReader, TerminalCore};
|
|||||||
use crate::ui::handlers::render::render_ui;
|
use crate::ui::handlers::render::render_ui;
|
||||||
use crate::pages::login;
|
use crate::pages::login;
|
||||||
use crate::pages::login::LoginResult;
|
use crate::pages::login::LoginResult;
|
||||||
|
use crate::pages::login::LoginState;
|
||||||
use crate::tui::functions::common::register::RegisterResult;
|
use crate::tui::functions::common::register::RegisterResult;
|
||||||
use crate::ui::handlers::context::DialogPurpose;
|
use crate::ui::handlers::context::DialogPurpose;
|
||||||
use crate::tui::functions::common::register;
|
use crate::tui::functions::common::register;
|
||||||
|
|||||||
Reference in New Issue
Block a user