Skip to main content

max / makenotwork

1.0 KB · 34 lines History Blame Raw
1 //! settings-screen key-input handler (split out of tui/input.rs).
2
3 use super::{App, AppEvent, KeyCode, KeyEvent, MnwApiClient, Screen, load_settings, mpsc};
4
5 pub(crate) async fn handle_settings_input(
6 key: KeyEvent,
7 app: &mut App,
8 screen: &mut Screen,
9 api: &MnwApiClient,
10 tx: &mpsc::Sender<AppEvent>,
11 ) {
12 match key.code {
13 KeyCode::Char('j') | KeyCode::Down => app.move_down(screen),
14 KeyCode::Char('k') | KeyCode::Up => app.move_up(screen),
15 KeyCode::Esc => {
16 *screen = Screen::Home;
17 app.ssh_keys.clear();
18 app.settings_status = None;
19 app.selected_index = 0;
20 }
21 KeyCode::Char('r' | 'R') => {
22 app.loading = true;
23 app.settings_status = None;
24 let api = api.clone();
25 let user_id = app.user.user_id.clone();
26 let tx = tx.clone();
27 tokio::spawn(async move {
28 load_settings(&api, &user_id, &tx).await;
29 });
30 }
31 _ => {}
32 }
33 }
34