diff --git a/src/app/mod.rs b/src/app/mod.rs index e6dc64c..130a6b7 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -50,10 +50,10 @@ pub struct App { pub td_client: T, /// Состояние чата - type-safe state machine (новое!) pub chat_state: ChatState, - // Auth state (используются часто в UI) - pub phone_input: String, - pub code_input: String, - pub password_input: String, + // Auth state (приватные, доступ через геттеры) + phone_input: String, + code_input: String, + password_input: String, pub error_message: Option, pub status_message: Option, // Main app state (используются часто) diff --git a/src/input/auth.rs b/src/input/auth.rs index 7007e0e..4a43a2a 100644 --- a/src/input/auth.rs +++ b/src/input/auth.rs @@ -8,19 +8,19 @@ pub async fn handle(app: &mut App, key_code: KeyCode) { match &app.td_client.auth_state() { AuthState::WaitPhoneNumber => match key_code { KeyCode::Char(c) => { - app.phone_input.push(c); + app.phone_input_mut().push(c); app.error_message = None; } KeyCode::Backspace => { - app.phone_input.pop(); + app.phone_input_mut().pop(); app.error_message = None; } KeyCode::Enter => { - if is_non_empty(&app.phone_input) { + if is_non_empty(app.phone_input()) { app.status_message = Some("Отправка номера...".to_string()); match with_timeout_msg( Duration::from_secs(10), - app.td_client.send_phone_number(app.phone_input.clone()), + app.td_client.send_phone_number(app.phone_input().to_string()), "Таймаут отправки номера", ) .await @@ -40,19 +40,19 @@ pub async fn handle(app: &mut App, key_code: KeyCode) { }, AuthState::WaitCode => match key_code { KeyCode::Char(c) if c.is_numeric() => { - app.code_input.push(c); + app.code_input_mut().push(c); app.error_message = None; } KeyCode::Backspace => { - app.code_input.pop(); + app.code_input_mut().pop(); app.error_message = None; } KeyCode::Enter => { - if is_non_empty(&app.code_input) { + if is_non_empty(app.code_input()) { app.status_message = Some("Проверка кода...".to_string()); match with_timeout_msg( Duration::from_secs(10), - app.td_client.send_code(app.code_input.clone()), + app.td_client.send_code(app.code_input().to_string()), "Таймаут проверки кода", ) .await @@ -72,19 +72,19 @@ pub async fn handle(app: &mut App, key_code: KeyCode) { }, AuthState::WaitPassword => match key_code { KeyCode::Char(c) => { - app.password_input.push(c); + app.password_input_mut().push(c); app.error_message = None; } KeyCode::Backspace => { - app.password_input.pop(); + app.password_input_mut().pop(); app.error_message = None; } KeyCode::Enter => { - if is_non_empty(&app.password_input) { + if is_non_empty(app.password_input()) { app.status_message = Some("Проверка пароля...".to_string()); match with_timeout_msg( Duration::from_secs(10), - app.td_client.send_password(app.password_input.clone()), + app.td_client.send_password(app.password_input().to_string()), "Таймаут проверки пароля", ) .await diff --git a/src/ui/auth.rs b/src/ui/auth.rs index 2428768..ac45d61 100644 --- a/src/ui/auth.rs +++ b/src/ui/auth.rs @@ -67,7 +67,7 @@ pub fn render(f: &mut Frame, app: &App) { .block(Block::default().borders(Borders::NONE)); f.render_widget(instructions_widget, auth_chunks[1]); - let input_text = format!("📱 {}", app.phone_input); + let input_text = format!("📱 {}", app.phone_input()); let input = Paragraph::new(input_text) .style(Style::default().fg(Color::Yellow)) .alignment(Alignment::Center) @@ -89,7 +89,7 @@ pub fn render(f: &mut Frame, app: &App) { .block(Block::default().borders(Borders::NONE)); f.render_widget(instructions_widget, auth_chunks[1]); - let input_text = format!("🔐 {}", app.code_input); + let input_text = format!("🔐 {}", app.code_input()); let input = Paragraph::new(input_text) .style(Style::default().fg(Color::Yellow)) .alignment(Alignment::Center) @@ -111,7 +111,7 @@ pub fn render(f: &mut Frame, app: &App) { .block(Block::default().borders(Borders::NONE)); f.render_widget(instructions_widget, auth_chunks[1]); - let masked_password = "*".repeat(app.password_input.len()); + let masked_password = "*".repeat(app.password_input().len()); let input_text = format!("🔒 {}", masked_password); let input = Paragraph::new(input_text) .style(Style::default().fg(Color::Yellow)) diff --git a/tests/helpers/app_builder.rs b/tests/helpers/app_builder.rs index 2c58d05..ec0449d 100644 --- a/tests/helpers/app_builder.rs +++ b/tests/helpers/app_builder.rs @@ -260,13 +260,13 @@ impl TestAppBuilder { // Применяем auth inputs if let Some(phone) = self.phone_input { - app.phone_input = phone; + app.set_phone_input(phone); } if let Some(code) = self.code_input { - app.code_input = code; + app.set_code_input(code); } if let Some(password) = self.password_input { - app.password_input = password; + app.set_password_input(password); } // Выбираем первый чат если есть