NewTask state to manage adding a new task
This commit is contained in:
parent
c9a69c7abe
commit
167f506291
28
src/app.rs
28
src/app.rs
@ -55,23 +55,45 @@ impl Default for Project {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum NewTaskFocus {
|
||||
Title,
|
||||
Description,
|
||||
Buttons
|
||||
}
|
||||
|
||||
pub struct NewTask {
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub focus: NewTaskFocus
|
||||
}
|
||||
|
||||
impl Default for NewTask {
|
||||
fn default() -> Self {
|
||||
NewTask {
|
||||
title: String::new(),
|
||||
description: String::new(),
|
||||
focus: NewTaskFocus::Title
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
pub project: Project,
|
||||
pub quit: bool,
|
||||
pub columns: Vec<Column>,
|
||||
pub popup_text: Option<String>,
|
||||
pub new_task_state: Option<NewTask>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new(project: Project) -> Self {
|
||||
AppState {
|
||||
quit: false,
|
||||
popup_text: None,
|
||||
new_task_state: None,
|
||||
project,
|
||||
columns: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Column {
|
||||
|
10
src/input.rs
10
src/input.rs
@ -1,12 +1,14 @@
|
||||
use crossterm::event;
|
||||
use crossterm::event::{Event, KeyCode};
|
||||
use crate::app::{AppState};
|
||||
use crate::app::{NewTask, AppState};
|
||||
|
||||
pub fn handle_input(state: &mut AppState) -> Result<(), std::io::Error> {
|
||||
let project = &mut state.project;
|
||||
let column = project.get_selected_column_mut();
|
||||
if let Event::Key(key) = event::read()? {
|
||||
match key.code {
|
||||
// KeyCode::BackTab =>
|
||||
// KeyCode::Tab =>
|
||||
KeyCode::Char('q') => state.quit = true,
|
||||
KeyCode::Char('h') |
|
||||
KeyCode::Left => { project.select_previous_column(); },
|
||||
@ -25,9 +27,9 @@ pub fn handle_input(state: &mut AppState) -> Result<(), std::io::Error> {
|
||||
KeyCode::Char('-') |
|
||||
KeyCode::Char('K') => project.move_task_up(),
|
||||
KeyCode::Char('p') => {
|
||||
match state.popup_text {
|
||||
None => state.popup_text = Some("".to_string()),
|
||||
Some(_) => state.popup_text = None,
|
||||
match state.new_task_state {
|
||||
None => state.new_task_state = Some(NewTask::default()),
|
||||
Some(_) => state.new_task_state = None,
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -62,6 +62,7 @@ fn draw_task_info<B: Backend>(f: &mut Frame<B>, area: &Rect, state: &AppState) {
|
||||
f.render_widget(p, *area);
|
||||
}
|
||||
}
|
||||
|
||||
fn centered_rect_for_popup(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
|
||||
let popup_layout = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
@ -91,15 +92,15 @@ fn centered_rect_for_popup(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
|
||||
pub fn draw_new_task_popup<B: Backend>(f: &mut Frame<B>, state: &mut AppState) {
|
||||
let area = centered_rect_for_popup(45, 60, f.size());
|
||||
f.render_widget(Clear, area);
|
||||
match &state.popup_text {
|
||||
match &state.new_task_state {
|
||||
None => {}
|
||||
Some(s) => {
|
||||
Some(task) => {
|
||||
let block = Block::default()
|
||||
.title("Add Task")
|
||||
.title_alignment(Alignment::Center)
|
||||
.borders(Borders::ALL);
|
||||
let block_inner = block.inner(area);
|
||||
let main = Paragraph::new(s.as_ref()).block(block);
|
||||
let main = Paragraph::new(task.description.as_ref()).block(block);
|
||||
let layout = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(
|
||||
@ -157,7 +158,7 @@ pub fn draw<B: Backend>(f: &mut Frame<B>, state: &mut AppState) {
|
||||
.block(block);
|
||||
f.render_widget(foot_txt, main_layout[3]);
|
||||
|
||||
if state.popup_text.is_some() {
|
||||
if state.new_task_state.is_some() {
|
||||
draw_new_task_popup(f, state);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user