Move task state getter to column methods

This commit is contained in:
Joseph Ferano 2023-06-07 11:22:19 +07:00
parent 78cb7fe84a
commit 88990089c2
3 changed files with 15 additions and 13 deletions

View File

@ -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<TaskState<'a>> {
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 {

View File

@ -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(),
_ => {}
}

View File

@ -1,3 +1,4 @@
// #![deny(rust_2018_idioms)]
mod app;
mod ui;
mod input;