Files
telegram-tui/src/input/auth.rs
Mikhail Kilin 7b2dd6c9a9 refactor: encapsulate auth fields (Group 1/5)
Фаза 1, Подход 2 - постепенная инкапсуляция полей App.

Changes:
- src/app/mod.rs: сделаны приватными phone_input, code_input, password_input
- src/input/auth.rs: замены на phone_input_mut(), code_input_mut(), password_input_mut()
- src/ui/auth.rs: замены на phone_input(), code_input(), password_input()
- tests/helpers/app_builder.rs: замены на set_phone_input(), set_code_input(), set_password_input()

Используются существующие геттеры/сеттеры (были добавлены ранее).

Progress: Group 1/5 complete (auth fields)
Next: Group 2 (UI state: screen, is_loading, needs_redraw, is_searching)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 17:56:34 +03:00

108 lines
4.0 KiB
Rust

use crate::app::App;
use crate::tdlib::{AuthState, TdClientTrait};
use crate::utils::{is_non_empty, with_timeout_msg};
use crossterm::event::KeyCode;
use std::time::Duration;
pub async fn handle<T: TdClientTrait>(app: &mut App<T>, key_code: KeyCode) {
match &app.td_client.auth_state() {
AuthState::WaitPhoneNumber => match key_code {
KeyCode::Char(c) => {
app.phone_input_mut().push(c);
app.error_message = None;
}
KeyCode::Backspace => {
app.phone_input_mut().pop();
app.error_message = None;
}
KeyCode::Enter => {
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().to_string()),
"Таймаут отправки номера",
)
.await
{
Ok(_) => {
app.error_message = None;
app.status_message = None;
}
Err(e) => {
app.error_message = Some(e);
app.status_message = None;
}
}
}
}
_ => {}
},
AuthState::WaitCode => match key_code {
KeyCode::Char(c) if c.is_numeric() => {
app.code_input_mut().push(c);
app.error_message = None;
}
KeyCode::Backspace => {
app.code_input_mut().pop();
app.error_message = None;
}
KeyCode::Enter => {
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().to_string()),
"Таймаут проверки кода",
)
.await
{
Ok(_) => {
app.error_message = None;
app.status_message = None;
}
Err(e) => {
app.error_message = Some(e);
app.status_message = None;
}
}
}
}
_ => {}
},
AuthState::WaitPassword => match key_code {
KeyCode::Char(c) => {
app.password_input_mut().push(c);
app.error_message = None;
}
KeyCode::Backspace => {
app.password_input_mut().pop();
app.error_message = None;
}
KeyCode::Enter => {
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().to_string()),
"Таймаут проверки пароля",
)
.await
{
Ok(_) => {
app.error_message = None;
app.status_message = None;
}
Err(e) => {
app.error_message = Some(e);
app.status_message = None;
}
}
}
}
_ => {}
},
_ => {}
}
}