From 48b2658b55a62d4482a8c752b4061c7084ca9ec2 Mon Sep 17 00:00:00 2001 From: filipriec Date: Fri, 28 Mar 2025 14:29:36 +0100 Subject: [PATCH] step2 --- client/src/state/pages/auth.rs | 49 +++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/client/src/state/pages/auth.rs b/client/src/state/pages/auth.rs index 296329d..2d9be17 100644 --- a/client/src/state/pages/auth.rs +++ b/client/src/state/pages/auth.rs @@ -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"), + } + } +}