login moved to the pages
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// src/state/pages/auth.rs
|
||||
|
||||
use canvas::{DataProvider, AppMode};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
@@ -20,34 +21,6 @@ pub struct AuthState {
|
||||
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
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RegisterState {
|
||||
@@ -61,7 +34,6 @@ pub struct RegisterState {
|
||||
pub current_cursor_pos: usize,
|
||||
pub has_unsaved_changes: bool,
|
||||
pub app_mode: AppMode,
|
||||
// Keep role suggestions for later integration
|
||||
pub role_suggestions: Vec<String>,
|
||||
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 {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
@@ -158,7 +73,6 @@ impl RegisterState {
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy method compatibility
|
||||
pub fn current_field(&self) -> usize {
|
||||
self.current_field
|
||||
}
|
||||
@@ -171,7 +85,6 @@ impl RegisterState {
|
||||
if index < 5 {
|
||||
self.current_field = index;
|
||||
|
||||
// Auto-activate role suggestions when moving to role field (index 4)
|
||||
if index == 4 {
|
||||
self.activate_role_suggestions();
|
||||
} else {
|
||||
@@ -195,8 +108,8 @@ impl RegisterState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_current_input_mut(&mut self) -> &mut String {
|
||||
match self.current_field {
|
||||
pub fn get_current_input_mut(&mut self, index: usize) -> &mut String {
|
||||
match index {
|
||||
0 => &mut self.username,
|
||||
1 => &mut self.email,
|
||||
2 => &mut self.password,
|
||||
@@ -210,10 +123,8 @@ impl RegisterState {
|
||||
self.app_mode
|
||||
}
|
||||
|
||||
// Role suggestions management
|
||||
pub fn activate_role_suggestions(&mut self) {
|
||||
self.role_suggestions_active = true;
|
||||
// Filter suggestions based on current input
|
||||
let current_input = self.role.to_lowercase();
|
||||
self.role_suggestions = AVAILABLE_ROLES
|
||||
.iter()
|
||||
@@ -234,7 +145,6 @@ impl RegisterState {
|
||||
&self.role_suggestions
|
||||
}
|
||||
|
||||
// Add missing methods that used to come from CanvasState trait
|
||||
pub fn has_unsaved_changes(&self) -> bool {
|
||||
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 {
|
||||
fn field_count(&self) -> usize {
|
||||
5
|
||||
|
||||
Reference in New Issue
Block a user