register on the way
This commit is contained in:
@@ -15,6 +15,18 @@ pub struct AuthState {
|
||||
pub has_unsaved_changes: bool,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone)] // Add Clone derive
|
||||
pub struct RegisterState {
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
pub password_confirmation: String,
|
||||
pub error_message: Option<String>,
|
||||
pub current_field: usize,
|
||||
pub current_cursor_pos: usize,
|
||||
pub has_unsaved_changes: bool,
|
||||
}
|
||||
|
||||
impl AuthState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
@@ -32,6 +44,21 @@ impl AuthState {
|
||||
}
|
||||
}
|
||||
|
||||
impl RegisterState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
username: String::new(),
|
||||
email: String::new(),
|
||||
password: String::new(),
|
||||
password_confirmation: String::new(),
|
||||
error_message: None,
|
||||
current_field: 0,
|
||||
current_cursor_pos: 0,
|
||||
has_unsaved_changes: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CanvasState for AuthState {
|
||||
fn current_field(&self) -> usize {
|
||||
self.current_field
|
||||
@@ -102,3 +129,91 @@ impl CanvasState for AuthState {
|
||||
self.has_unsaved_changes = changed;
|
||||
}
|
||||
}
|
||||
|
||||
impl CanvasState for RegisterState {
|
||||
fn current_field(&self) -> usize {
|
||||
self.current_field
|
||||
}
|
||||
|
||||
fn current_cursor_pos(&self) -> usize {
|
||||
let len = match self.current_field {
|
||||
0 => self.username.len(),
|
||||
1 => self.email.len(),
|
||||
2 => self.password.len(),
|
||||
3 => self.password_confirmation.len(),
|
||||
_ => 0,
|
||||
};
|
||||
self.current_cursor_pos.min(len)
|
||||
}
|
||||
|
||||
fn has_unsaved_changes(&self) -> bool {
|
||||
self.has_unsaved_changes
|
||||
}
|
||||
|
||||
fn inputs(&self) -> Vec<&String> {
|
||||
vec![
|
||||
&self.username,
|
||||
&self.email,
|
||||
&self.password,
|
||||
&self.password_confirmation,
|
||||
]
|
||||
}
|
||||
|
||||
fn get_current_input(&self) -> &str {
|
||||
match self.current_field {
|
||||
0 => &self.username,
|
||||
1 => &self.email,
|
||||
2 => &self.password,
|
||||
3 => &self.password_confirmation,
|
||||
_ => "",
|
||||
}
|
||||
}
|
||||
|
||||
fn get_current_input_mut(&mut self) -> &mut String {
|
||||
match self.current_field {
|
||||
0 => &mut self.username,
|
||||
1 => &mut self.email,
|
||||
2 => &mut self.password,
|
||||
3 => &mut self.password_confirmation,
|
||||
_ => panic!("Invalid current_field index in RegisterState"),
|
||||
}
|
||||
}
|
||||
|
||||
fn fields(&self) -> Vec<&str> {
|
||||
vec![
|
||||
"Username",
|
||||
"Email (Optional)",
|
||||
"Password (Optional)",
|
||||
"Confirm Password",
|
||||
]
|
||||
}
|
||||
|
||||
fn set_current_field(&mut self, index: usize) {
|
||||
if index < 4 { // RegisterState has 4 fields
|
||||
self.current_field = index;
|
||||
let len = match self.current_field {
|
||||
0 => self.username.len(),
|
||||
1 => self.email.len(),
|
||||
2 => self.password.len(),
|
||||
3 => self.password_confirmation.len(),
|
||||
_ => 0,
|
||||
};
|
||||
self.current_cursor_pos = self.current_cursor_pos.min(len);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_current_cursor_pos(&mut self, pos: usize) {
|
||||
let len = match self.current_field {
|
||||
0 => self.username.len(),
|
||||
1 => self.email.len(),
|
||||
2 => self.password.len(),
|
||||
3 => self.password_confirmation.len(),
|
||||
_ => 0,
|
||||
};
|
||||
self.current_cursor_pos = pos.min(len);
|
||||
}
|
||||
|
||||
fn set_has_unsaved_changes(&mut self, changed: bool) {
|
||||
self.has_unsaved_changes = changed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::env;
|
||||
use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
||||
use crate::components::IntroState;
|
||||
use crate::modes::handlers::mode_manager::AppMode;
|
||||
use crate::state::pages::auth::{AuthState, RegisterState};
|
||||
use crate::ui::handlers::context::DialogPurpose;
|
||||
|
||||
pub struct DialogState {
|
||||
@@ -21,9 +22,10 @@ pub struct UiState {
|
||||
pub show_admin: bool,
|
||||
pub show_form: bool,
|
||||
pub show_login: bool,
|
||||
pub show_register: bool,
|
||||
pub intro_state: IntroState,
|
||||
pub focus_outside_canvas: bool,
|
||||
pub dialog: DialogState, // Add dialog state here
|
||||
pub dialog: DialogState,
|
||||
}
|
||||
|
||||
pub struct GeneralState {
|
||||
@@ -144,6 +146,7 @@ impl Default for UiState {
|
||||
show_admin: false,
|
||||
show_form: false,
|
||||
show_login: false,
|
||||
show_register: false,
|
||||
intro_state: IntroState::new(),
|
||||
focus_outside_canvas: false,
|
||||
dialog: DialogState::default(),
|
||||
|
||||
Reference in New Issue
Block a user