//! home-screen key-input handler (split out of tui/input.rs). use super::{ App, AppEvent, KeyCode, KeyEvent, MnwApiClient, Path, Screen, load_analytics, load_collections, load_home_data, load_project_items, load_promo_codes, load_settings, load_staged_files, mpsc, }; pub(crate) async fn handle_home_input( key: KeyEvent, app: &mut App, screen: &mut Screen, api: &MnwApiClient, tx: &mpsc::Sender, staging_dir: &Path, ) { match key.code { KeyCode::Char('j') | KeyCode::Down => app.move_down(screen), KeyCode::Char('k') | KeyCode::Up => app.move_up(screen), KeyCode::Enter if !app.projects.is_empty() => { let idx = app.selected_index; let project_id = app.projects[idx].id.clone(); let user_id = app.user.user_id.clone(); *screen = Screen::Project(idx); app.items.clear(); app.selected_index = 0; app.loading = true; let api = api.clone(); let tx = tx.clone(); tokio::spawn(async move { load_project_items(&api, &project_id, &user_id, &tx).await; }); } KeyCode::Char('u' | 'U') => { *screen = Screen::Upload; app.selected_index = 0; app.loading = true; app.upload_status = None; app.editing_field = None; let staging_dir = staging_dir.to_path_buf(); let api = api.clone(); let user_id = app.user.user_id.clone(); let tx = tx.clone(); tokio::spawn(async move { load_staged_files(&staging_dir, &api, &user_id, &tx).await; }); } KeyCode::Char('a' | 'A') => { *screen = Screen::Analytics; app.analytics_data = None; app.analytics_status = None; app.analytics_show_transactions = false; app.selected_index = 0; app.loading = true; let api = api.clone(); let user_id = app.user.user_id.clone(); let range = app.analytics_range.clone(); let tx = tx.clone(); tokio::spawn(async move { load_analytics(&api, &user_id, &range, &tx).await; }); } KeyCode::Char('p' | 'P') => { *screen = Screen::Promo; app.promo_codes.clear(); app.promo_status = None; app.promo_editing_step = None; app.selected_index = 0; app.loading = true; let api = api.clone(); let user_id = app.user.user_id.clone(); let tx = tx.clone(); tokio::spawn(async move { load_promo_codes(&api, &user_id, &tx).await; }); } KeyCode::Char('c' | 'C') => { *screen = Screen::Collections; app.collections.clear(); app.collections_status = None; app.selected_index = 0; app.loading = true; let api = api.clone(); let user_id = app.user.user_id.clone(); let tx = tx.clone(); tokio::spawn(async move { load_collections(&api, &user_id, &tx).await; }); } KeyCode::Char('s' | 'S') => { *screen = Screen::Settings; app.ssh_keys.clear(); app.settings_status = None; app.selected_index = 0; app.loading = true; let api = api.clone(); let user_id = app.user.user_id.clone(); let tx = tx.clone(); tokio::spawn(async move { load_settings(&api, &user_id, &tx).await; }); } KeyCode::Char('r' | 'R') => { app.loading = true; let api = api.clone(); let user_id = app.user.user_id.clone(); let tx = tx.clone(); tokio::spawn(async move { load_home_data(&api, &user_id, &tx).await; }); } _ => {} } }