refactor: eliminate code duplication - extract helpers and use retry utils
Extracted duplicate code and unified timeout handling across the codebase. Changes: - Extracted open_chat_and_load_data() function (eliminates 52 lines of duplication) - Replaced manual y/н/Enter handling with handle_yes_no() from modal_handler (2 places) - Replaced 7 direct tokio::time::timeout calls with retry utils (auth, main_input, main) - Added with_timeout_ignore() for non-critical operations - Fixed modal_handler.rs bug: corrected Russian 'y' key (д → н) - Removed unused imports in handlers/mod.rs and utils/mod.rs Impact: - main_input.rs: 1164 → 958 lines (-206 lines, -18%) - Code duplication: 52 lines eliminated - Direct timeout calls: 7 → 1 (-86%) - DRY principle applied throughout Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -106,7 +106,7 @@ pub fn should_confirm_modal(key_code: KeyCode) -> bool {
|
||||
///
|
||||
/// assert_eq!(handle_yes_no(KeyCode::Char('y')), Some(true));
|
||||
/// assert_eq!(handle_yes_no(KeyCode::Char('Y')), Some(true));
|
||||
/// assert_eq!(handle_yes_no(KeyCode::Char('д')), Some(true)); // русская 'y'
|
||||
/// assert_eq!(handle_yes_no(KeyCode::Char('н')), Some(true)); // русская 'y'
|
||||
/// assert_eq!(handle_yes_no(KeyCode::Enter), Some(true));
|
||||
///
|
||||
/// assert_eq!(handle_yes_no(KeyCode::Char('n')), Some(false));
|
||||
@@ -118,7 +118,7 @@ pub fn should_confirm_modal(key_code: KeyCode) -> bool {
|
||||
pub fn handle_yes_no(key_code: KeyCode) -> Option<bool> {
|
||||
match key_code {
|
||||
// Yes - подтверждение (английская и русская раскладка)
|
||||
KeyCode::Char('y') | KeyCode::Char('Y') | KeyCode::Char('д') | KeyCode::Char('Д') => {
|
||||
KeyCode::Char('y') | KeyCode::Char('Y') | KeyCode::Char('н') | KeyCode::Char('Н') => {
|
||||
Some(true)
|
||||
}
|
||||
KeyCode::Enter => Some(true),
|
||||
@@ -165,8 +165,8 @@ mod tests {
|
||||
// Yes variants
|
||||
assert_eq!(handle_yes_no(KeyCode::Char('y')), Some(true));
|
||||
assert_eq!(handle_yes_no(KeyCode::Char('Y')), Some(true));
|
||||
assert_eq!(handle_yes_no(KeyCode::Char('д')), Some(true)); // Russian
|
||||
assert_eq!(handle_yes_no(KeyCode::Char('Д')), Some(true)); // Russian
|
||||
assert_eq!(handle_yes_no(KeyCode::Char('н')), Some(true)); // Russian
|
||||
assert_eq!(handle_yes_no(KeyCode::Char('Н')), Some(true)); // Russian
|
||||
assert_eq!(handle_yes_no(KeyCode::Enter), Some(true));
|
||||
|
||||
// No variants
|
||||
|
||||
Reference in New Issue
Block a user