Skip to content

Commit

Permalink
feat: show completed tasks with DONE
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-pitblado committed Oct 26, 2024
1 parent a1e74d7 commit 8c56281
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = config.vikunja.api_key;

let all_tasks = api::fetch_tasks(&instance_url, &api_key, 1).await?;

let incomplete_tasks: Vec<models::Task> =
all_tasks.into_iter().filter(|task| !task.done).collect();
let tasks_for_app = all_tasks.clone();

enable_raw_mode()?;
let mut stdout = io::stdout();
Expand All @@ -60,7 +58,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

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;

Expand Down
2 changes: 1 addition & 1 deletion src/models.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
17 changes: 15 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,20 @@ pub async fn run_app<B: Backend>(
let tasks: Vec<ListItem> = 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)
Expand All @@ -136,7 +149,7 @@ pub async fn run_app<B: Backend>(
)
.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"))
};

Expand Down

0 comments on commit 8c56281

Please sign in to comment.