step2
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// src/state/pages/auth.rs
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct AuthState {
|
||||
@@ -22,20 +23,48 @@ impl AuthState {
|
||||
}
|
||||
}
|
||||
|
||||
// These methods are now redundant since we implement CanvasState
|
||||
// but we'll keep them for backward compatibility
|
||||
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 in AuthState"),
|
||||
}
|
||||
self.get_current_input_mut()
|
||||
}
|
||||
|
||||
pub fn get_current_input(&self) -> &str {
|
||||
match self.current_field {
|
||||
0 => &self.username,
|
||||
1 => &self.password,
|
||||
_ => panic!("Invalid current_field in AuthState"),
|
||||
}
|
||||
self.get_current_input()
|
||||
}
|
||||
}
|
||||
|
||||
impl CanvasState for AuthState {
|
||||
fn current_field(&self) -> usize {
|
||||
self.current_field
|
||||
}
|
||||
|
||||
fn current_cursor_pos(&self) -> usize {
|
||||
self.current_cursor_pos
|
||||
}
|
||||
|
||||
fn has_unsaved_changes(&self) -> bool {
|
||||
// Auth form doesn't need unsaved changes tracking
|
||||
false
|
||||
}
|
||||
|
||||
fn inputs(&self) -> Vec<&String> {
|
||||
vec![&self.username, &self.password]
|
||||
}
|
||||
|
||||
fn get_current_input(&self) -> &str {
|
||||
match self.current_field {
|
||||
0 => &self.username,
|
||||
1 => &self.password,
|
||||
_ => "", // Return empty string for invalid index instead of panicking
|
||||
}
|
||||
}
|
||||
|
||||
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 AuthState"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user