From 8c5628187fc96ea805521d787dfb896558d3b480 Mon Sep 17 00:00:00 2001 From: Mark Pitblado Date: Sat, 26 Oct 2024 05:58:08 -0700 Subject: [PATCH] feat: show completed tasks with DONE --- src/main.rs | 6 ++---- src/models.rs | 2 +- src/ui.rs | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index f3e8eba..797fae4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,9 +48,7 @@ async fn main() -> Result<(), Box> { let api_key = config.vikunja.api_key; let all_tasks = api::fetch_tasks(&instance_url, &api_key, 1).await?; - - let incomplete_tasks: Vec = - all_tasks.into_iter().filter(|task| !task.done).collect(); + let tasks_for_app = all_tasks.clone(); enable_raw_mode()?; let mut stdout = io::stdout(); @@ -60,7 +58,7 @@ async fn main() -> Result<(), Box> { terminal.hide_cursor()?; - let app = App::new(incomplete_tasks); + let app = App::new(tasks_for_app); let res = run_app(&mut terminal, app, &instance_url, &api_key).await; diff --git a/src/models.rs b/src/models.rs index 8b85d12..c9f242d 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,7 +1,7 @@ use serde::Deserialize; // Task struct -#[derive(Deserialize, Debug)] +#[derive(Clone, Deserialize, Debug)] pub struct Task { pub id: u64, pub title: String, diff --git a/src/ui.rs b/src/ui.rs index 046d516..479ccbf 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -124,7 +124,20 @@ pub async fn run_app( let tasks: Vec = app .tasks .iter() - .map(|task| ListItem::new(Line::from(task.title.clone()))) + .map(|task| { + // Check if the task is done + let content = if task.done { + // Prepend "DONE" for completed tasks + vec![ + Span::styled("DONE ", Style::default().fg(Color::Green)), + Span::raw(&task.title), + ] + } else { + vec![Span::raw(&task.title)] + }; + + ListItem::new(Line::from(content)) + }) .collect(); List::new(tasks) @@ -136,7 +149,7 @@ pub async fn run_app( ) .highlight_symbol(">> ") } else { - List::new(vec![ListItem::new("No incomplete tasks available")]) + List::new(vec![ListItem::new("No tasks available")]) .block(Block::default().borders(Borders::ALL).title("Tasks")) };