refactor
This commit is contained in:
parent
870ec706b3
commit
ada01926ba
3 changed files with 44 additions and 29 deletions
|
@ -9,12 +9,14 @@ use crossterm::{
|
|||
pub mod project;
|
||||
pub mod task;
|
||||
|
||||
/// Print `txt` with a custom `color`
|
||||
pub fn print_color(color: Color, txt: &str) {
|
||||
stdout().execute(SetForegroundColor(color)).unwrap();
|
||||
print!("{txt}");
|
||||
stdout().execute(SetForegroundColor(Color::Reset)).unwrap();
|
||||
}
|
||||
|
||||
/// Convert a HEX Color String into a `Color` struct
|
||||
fn hex_to_color(hex: &str) -> Result<Color, String> {
|
||||
let hex = hex.trim_start_matches('#');
|
||||
|
||||
|
@ -29,6 +31,7 @@ fn hex_to_color(hex: &str) -> Result<Color, String> {
|
|||
Ok(Color::Rgb { r, g, b })
|
||||
}
|
||||
|
||||
/// Parse datetime string
|
||||
fn parse_datetime(datetime_str: &str) -> Option<DateTime<Utc>> {
|
||||
if datetime_str == "0001-01-01T00:00:00Z" {
|
||||
return None;
|
||||
|
@ -40,6 +43,7 @@ fn parse_datetime(datetime_str: &str) -> Option<DateTime<Utc>> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Return a formatted time duration
|
||||
pub fn time_since(event: DateTime<Utc>) -> String {
|
||||
let now = Utc::now();
|
||||
let duration = now.signed_duration_since(event);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
api::{Task, VikunjaAPI},
|
||||
api::{ProjectID, Task, VikunjaAPI},
|
||||
ui::{parse_datetime, time_since},
|
||||
};
|
||||
|
||||
|
@ -31,11 +31,11 @@ pub fn print_current_tasks(api: &VikunjaAPI, done: bool, fav: bool, project: Opt
|
|||
};
|
||||
|
||||
if let Some(project) = project {
|
||||
let p_id = api.parse_project_id(project).unwrap();
|
||||
let p_id = ProjectID::parse(api, project).unwrap();
|
||||
|
||||
selection = selection
|
||||
.into_iter()
|
||||
.filter(|x| x.project_id == p_id)
|
||||
.filter(|x| x.project_id == p_id.0)
|
||||
.collect();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue