From 88990089c2b6c5b9e7f594fdbcef12b06c73bc22 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Wed, 7 Jun 2023 11:22:19 +0700 Subject: [PATCH] Move task state getter to column methods --- src/app.rs | 13 ++++++++++++- src/input.rs | 14 ++------------ src/lib.rs | 1 + 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/app.rs b/src/app.rs index a01c34a..13d38c2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -100,7 +100,7 @@ impl AppState<'_> { } } -impl Column { +impl<'a> Column { pub fn new(name: &str) -> Self { Column { name: name.to_owned(), @@ -141,6 +141,17 @@ impl Column { pub fn select_last_task(&mut self) { self.selected_task_idx = self.tasks.len() - 1; } + + pub fn get_task_state_from_curr_selected_task(&self) -> Option> { + self.get_selected_task().map(|t| { + TaskState { + title: TextArea::from(t.title.lines()), + description: TextArea::from(t.description.lines()), + focus: TaskEditFocus::Title, + is_edit: true + } + }) + } } impl Project { diff --git a/src/input.rs b/src/input.rs index c1c61bd..7f403f5 100644 --- a/src/input.rs +++ b/src/input.rs @@ -81,18 +81,8 @@ pub fn handle_input(state: &mut AppState) -> Result<(), std::io::Error> { KeyCode::Char('-') | KeyCode::Char('K') => project.move_task_up(), KeyCode::Char('n') => state.task_edit_state = Some(TaskState::default()), - KeyCode::Char('e') => { - if let Some(task) = column.get_selected_task() { - let task_state = - TaskState { - title: TextArea::from(task.title.lines()), - description: TextArea::from(task.description.lines()), - focus: TaskEditFocus::Title, - is_edit: true - }; - state.task_edit_state = Some(task_state); - } - } + KeyCode::Char('e') => + state.task_edit_state = column.get_task_state_from_curr_selected_task(), KeyCode::Char('D') => column.remove_task(), _ => {} } diff --git a/src/lib.rs b/src/lib.rs index 36766b7..bbf5681 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +// #![deny(rust_2018_idioms)] mod app; mod ui; mod input;