Skip to content

Commit

Permalink
Added increase/decrease of last done day of schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaaskarian committed Feb 5, 2024
1 parent 836aae3 commit 9332727
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/todo_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ impl App {
self.changed
}

#[inline]
pub fn increase_day_done(&mut self) {
if let Some(mut todo) = self.mut_todo() {
todo.schedule.add_days_to_done_date(1)
}
}

#[inline]
pub fn decrease_day_done(&mut self) {
if let Some(mut todo) = self.mut_todo() {
todo.schedule.add_days_to_done_date(-1)
}
}

#[inline]
pub fn show_done(&self) -> bool {
self.args.show_done
Expand Down
2 changes: 1 addition & 1 deletion src/todo_app/todo_list/todo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct Todo {
pub dependency: Dependency,
done:bool,
removed_names: Vec<String>,
schedule: Schedule,
pub schedule: Schedule,
}

impl Into<String> for &Todo {
Expand Down
10 changes: 9 additions & 1 deletion src/todo_app/todo_list/todo/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Schedule {
}
}

fn last_save (&self) -> Duration {
fn last_save(&self) -> Duration {
if let Some(done_date) = self.done_date {
date::current() - done_date
} else {
Expand All @@ -109,6 +109,14 @@ impl Schedule {
}
}

pub fn add_days_to_done_date(&mut self, days:i64) {
if let Some(date) = self.done_date {
if days <= self.last_save().num_days() {
self.done_date = Some(date+Duration::days(days));
}
}
}

pub fn set_daily(&mut self) {
self.set_day(1);
}
Expand Down
2 changes: 2 additions & 0 deletions src/tui_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ impl<'a>TuiApp<'a>{
Char('!') => self.todo_app.toggle_show_done(),
Char('y') => self.todo_app.yank_todo(),
Char('p') => self.todo_app.paste_todo(),
Char('i') => self.todo_app.increase_day_done(),
Char('o') => self.todo_app.decrease_day_done(),
KeyCode::Down | Char('j') => self.todo_app.increment(),
KeyCode::Up |Char('k') => self.todo_app.decrement(),
KeyCode::Right | Char('l') => self.todo_app.add_dependency_traverse_down(),
Expand Down

0 comments on commit 9332727

Please sign in to comment.