login moved to the pages
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
|
||||
use crate::services::auth::AuthClient;
|
||||
use crate::state::pages::auth::AuthState;
|
||||
use crate::state::pages::auth::LoginState;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::buffer::state::{AppView, BufferState};
|
||||
use crate::config::storage::storage::{StoredAuthData, save_auth_data};
|
||||
use crate::ui::handlers::context::DialogPurpose;
|
||||
use common::proto::komp_ac::auth::LoginResponse;
|
||||
use crate::pages::login::LoginState;
|
||||
use anyhow::{Context, Result};
|
||||
use tokio::spawn;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
@@ -4,6 +4,6 @@ pub mod state;
|
||||
pub mod ui;
|
||||
pub mod logic;
|
||||
|
||||
pub use state::LoginState;
|
||||
pub use state::*;
|
||||
pub use ui::render_login;
|
||||
pub use logic::*;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// src/pages/login/state.rs
|
||||
|
||||
use canvas::AppMode;
|
||||
use canvas::{AppMode, DataProvider};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
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::{
|
||||
config::colors::themes::Theme,
|
||||
state::pages::auth::LoginState,
|
||||
state::app::state::AppState,
|
||||
};
|
||||
use ratatui::{
|
||||
@@ -17,6 +16,7 @@ use canvas::{
|
||||
render_suggestions_dropdown,
|
||||
DefaultCanvasTheme,
|
||||
};
|
||||
use crate::pages::login::LoginState;
|
||||
use crate::dialog;
|
||||
|
||||
pub fn render_login(
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
// src/pages/routing/router.rs
|
||||
use crate::state::pages::{
|
||||
admin::AdminState,
|
||||
auth::{AuthState, LoginState, RegisterState},
|
||||
auth::{AuthState, RegisterState},
|
||||
intro::IntroState,
|
||||
add_logic::AddLogicState,
|
||||
add_table::AddTableState,
|
||||
};
|
||||
use crate::pages::forms::FormState;
|
||||
use crate::pages::login::LoginState;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Page {
|
||||
|
||||
Reference in New Issue
Block a user