Remove task with D, move methods to column struct, select next/previous
This commit is contained in:
parent
be4fc3566d
commit
fc237b9f29
16
src/app.rs
16
src/app.rs
@ -107,6 +107,17 @@ impl Column {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_task(&mut self, title: String, description: String) {
|
||||
let task = Task { title, description };
|
||||
self.tasks.push(task);
|
||||
self.select_next_task();
|
||||
}
|
||||
|
||||
pub fn remove_task(&mut self) {
|
||||
self.tasks.remove(self.selected_task_idx);
|
||||
self.select_previous_task();
|
||||
}
|
||||
|
||||
pub fn get_selected_task(&self) -> Option<&Task> {
|
||||
self.tasks.get(self.selected_task_idx)
|
||||
}
|
||||
@ -149,11 +160,6 @@ impl Project {
|
||||
Self::load_from_json(&json)
|
||||
}
|
||||
|
||||
pub fn add_task(&mut self, title: String, description: String) {
|
||||
let task = Task { title, description };
|
||||
self.columns[self.selected_column_idx].tasks.push(task);
|
||||
}
|
||||
|
||||
pub fn save(&self) {
|
||||
let json = serde_json::to_string_pretty(&self).unwrap();
|
||||
std::fs::write("kanban-tui.json", json).unwrap();
|
||||
|
@ -36,8 +36,7 @@ pub fn handle_input(state: &mut AppState) -> Result<(), std::io::Error> {
|
||||
KeyCode::Enter => {
|
||||
let title = task.title.clone().into_lines().join("\n");
|
||||
let description = task.description.clone().into_lines().clone().join("\n");
|
||||
project.add_task(title, description);
|
||||
|
||||
column.add_task(title, description);
|
||||
state.new_task_state = None
|
||||
}
|
||||
_ => (),
|
||||
@ -80,6 +79,7 @@ pub fn handle_input(state: &mut AppState) -> Result<(), std::io::Error> {
|
||||
Some(_) => state.new_task_state = None,
|
||||
}
|
||||
}
|
||||
KeyCode::Char('D') => column.remove_task(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ fn draw_tasks<B: Backend>(f: &mut Frame<B>, area: &Rect, state: &AppState) {
|
||||
if i == state.project.selected_column_idx {
|
||||
style = style.fg(Color::Green);
|
||||
};
|
||||
let mut s = Span::raw(format!("{:?}", column.name));
|
||||
let mut s = Span::raw(column.name.as_str());
|
||||
s.style = Style::default()
|
||||
.add_modifier(Modifier::BOLD | Modifier::ITALIC | Modifier::UNDERLINED)
|
||||
.fg(Color::White);
|
||||
|
Loading…
x
Reference in New Issue
Block a user