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>
This commit is contained in:
@@ -50,10 +50,10 @@ pub struct App<T: TdClientTrait = TdClient> {
|
|||||||
pub td_client: T,
|
pub td_client: T,
|
||||||
/// Состояние чата - type-safe state machine (новое!)
|
/// Состояние чата - type-safe state machine (новое!)
|
||||||
pub chat_state: ChatState,
|
pub chat_state: ChatState,
|
||||||
// Auth state (используются часто в UI)
|
// Auth state (приватные, доступ через геттеры)
|
||||||
pub phone_input: String,
|
phone_input: String,
|
||||||
pub code_input: String,
|
code_input: String,
|
||||||
pub password_input: String,
|
password_input: String,
|
||||||
pub error_message: Option<String>,
|
pub error_message: Option<String>,
|
||||||
pub status_message: Option<String>,
|
pub status_message: Option<String>,
|
||||||
// Main app state (используются часто)
|
// Main app state (используются часто)
|
||||||
|
|||||||
@@ -8,19 +8,19 @@ pub async fn handle<T: TdClientTrait>(app: &mut App<T>, key_code: KeyCode) {
|
|||||||
match &app.td_client.auth_state() {
|
match &app.td_client.auth_state() {
|
||||||
AuthState::WaitPhoneNumber => match key_code {
|
AuthState::WaitPhoneNumber => match key_code {
|
||||||
KeyCode::Char(c) => {
|
KeyCode::Char(c) => {
|
||||||
app.phone_input.push(c);
|
app.phone_input_mut().push(c);
|
||||||
app.error_message = None;
|
app.error_message = None;
|
||||||
}
|
}
|
||||||
KeyCode::Backspace => {
|
KeyCode::Backspace => {
|
||||||
app.phone_input.pop();
|
app.phone_input_mut().pop();
|
||||||
app.error_message = None;
|
app.error_message = None;
|
||||||
}
|
}
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter => {
|
||||||
if is_non_empty(&app.phone_input) {
|
if is_non_empty(app.phone_input()) {
|
||||||
app.status_message = Some("Отправка номера...".to_string());
|
app.status_message = Some("Отправка номера...".to_string());
|
||||||
match with_timeout_msg(
|
match with_timeout_msg(
|
||||||
Duration::from_secs(10),
|
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
|
.await
|
||||||
@@ -40,19 +40,19 @@ pub async fn handle<T: TdClientTrait>(app: &mut App<T>, key_code: KeyCode) {
|
|||||||
},
|
},
|
||||||
AuthState::WaitCode => match key_code {
|
AuthState::WaitCode => match key_code {
|
||||||
KeyCode::Char(c) if c.is_numeric() => {
|
KeyCode::Char(c) if c.is_numeric() => {
|
||||||
app.code_input.push(c);
|
app.code_input_mut().push(c);
|
||||||
app.error_message = None;
|
app.error_message = None;
|
||||||
}
|
}
|
||||||
KeyCode::Backspace => {
|
KeyCode::Backspace => {
|
||||||
app.code_input.pop();
|
app.code_input_mut().pop();
|
||||||
app.error_message = None;
|
app.error_message = None;
|
||||||
}
|
}
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter => {
|
||||||
if is_non_empty(&app.code_input) {
|
if is_non_empty(app.code_input()) {
|
||||||
app.status_message = Some("Проверка кода...".to_string());
|
app.status_message = Some("Проверка кода...".to_string());
|
||||||
match with_timeout_msg(
|
match with_timeout_msg(
|
||||||
Duration::from_secs(10),
|
Duration::from_secs(10),
|
||||||
app.td_client.send_code(app.code_input.clone()),
|
app.td_client.send_code(app.code_input().to_string()),
|
||||||
"Таймаут проверки кода",
|
"Таймаут проверки кода",
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -72,19 +72,19 @@ pub async fn handle<T: TdClientTrait>(app: &mut App<T>, key_code: KeyCode) {
|
|||||||
},
|
},
|
||||||
AuthState::WaitPassword => match key_code {
|
AuthState::WaitPassword => match key_code {
|
||||||
KeyCode::Char(c) => {
|
KeyCode::Char(c) => {
|
||||||
app.password_input.push(c);
|
app.password_input_mut().push(c);
|
||||||
app.error_message = None;
|
app.error_message = None;
|
||||||
}
|
}
|
||||||
KeyCode::Backspace => {
|
KeyCode::Backspace => {
|
||||||
app.password_input.pop();
|
app.password_input_mut().pop();
|
||||||
app.error_message = None;
|
app.error_message = None;
|
||||||
}
|
}
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter => {
|
||||||
if is_non_empty(&app.password_input) {
|
if is_non_empty(app.password_input()) {
|
||||||
app.status_message = Some("Проверка пароля...".to_string());
|
app.status_message = Some("Проверка пароля...".to_string());
|
||||||
match with_timeout_msg(
|
match with_timeout_msg(
|
||||||
Duration::from_secs(10),
|
Duration::from_secs(10),
|
||||||
app.td_client.send_password(app.password_input.clone()),
|
app.td_client.send_password(app.password_input().to_string()),
|
||||||
"Таймаут проверки пароля",
|
"Таймаут проверки пароля",
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ pub fn render<T: TdClientTrait>(f: &mut Frame, app: &App<T>) {
|
|||||||
.block(Block::default().borders(Borders::NONE));
|
.block(Block::default().borders(Borders::NONE));
|
||||||
f.render_widget(instructions_widget, auth_chunks[1]);
|
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)
|
let input = Paragraph::new(input_text)
|
||||||
.style(Style::default().fg(Color::Yellow))
|
.style(Style::default().fg(Color::Yellow))
|
||||||
.alignment(Alignment::Center)
|
.alignment(Alignment::Center)
|
||||||
@@ -89,7 +89,7 @@ pub fn render<T: TdClientTrait>(f: &mut Frame, app: &App<T>) {
|
|||||||
.block(Block::default().borders(Borders::NONE));
|
.block(Block::default().borders(Borders::NONE));
|
||||||
f.render_widget(instructions_widget, auth_chunks[1]);
|
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)
|
let input = Paragraph::new(input_text)
|
||||||
.style(Style::default().fg(Color::Yellow))
|
.style(Style::default().fg(Color::Yellow))
|
||||||
.alignment(Alignment::Center)
|
.alignment(Alignment::Center)
|
||||||
@@ -111,7 +111,7 @@ pub fn render<T: TdClientTrait>(f: &mut Frame, app: &App<T>) {
|
|||||||
.block(Block::default().borders(Borders::NONE));
|
.block(Block::default().borders(Borders::NONE));
|
||||||
f.render_widget(instructions_widget, auth_chunks[1]);
|
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_text = format!("🔒 {}", masked_password);
|
||||||
let input = Paragraph::new(input_text)
|
let input = Paragraph::new(input_text)
|
||||||
.style(Style::default().fg(Color::Yellow))
|
.style(Style::default().fg(Color::Yellow))
|
||||||
|
|||||||
@@ -260,13 +260,13 @@ impl TestAppBuilder {
|
|||||||
|
|
||||||
// Применяем auth inputs
|
// Применяем auth inputs
|
||||||
if let Some(phone) = self.phone_input {
|
if let Some(phone) = self.phone_input {
|
||||||
app.phone_input = phone;
|
app.set_phone_input(phone);
|
||||||
}
|
}
|
||||||
if let Some(code) = self.code_input {
|
if let Some(code) = self.code_input {
|
||||||
app.code_input = code;
|
app.set_code_input(code);
|
||||||
}
|
}
|
||||||
if let Some(password) = self.password_input {
|
if let Some(password) = self.password_input {
|
||||||
app.password_input = password;
|
app.set_password_input(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Выбираем первый чат если есть
|
// Выбираем первый чат если есть
|
||||||
|
|||||||
Reference in New Issue
Block a user