Move task state getter to column methods
This commit is contained in:
parent
78cb7fe84a
commit
88990089c2
13
src/app.rs
13
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<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 {
|
||||
|
14
src/input.rs
14
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(),
|
||||
_ => {}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
// #![deny(rust_2018_idioms)]
|
||||
mod app;
|
||||
mod ui;
|
||||
mod input;
|
||||
|
Loading…
x
Reference in New Issue
Block a user