refactor
This commit is contained in:
parent
a11fe29048
commit
09f6dd0625
6 changed files with 53 additions and 70 deletions
|
@ -46,10 +46,7 @@ fn parse_datetime(datetime_str: &str) -> Option<DateTime<Utc>> {
|
|||
return None;
|
||||
}
|
||||
|
||||
match DateTime::parse_from_rfc3339(datetime_str) {
|
||||
Ok(dt) => Some(dt.with_timezone(&Utc)),
|
||||
Err(_) => None, // Return None if parsing fails
|
||||
}
|
||||
DateTime::parse_from_rfc3339(datetime_str).map_or(None, |dt| Some(dt.with_timezone(&Utc)))
|
||||
}
|
||||
|
||||
/// Return a formatted time duration
|
||||
|
@ -58,19 +55,19 @@ pub fn time_since(event: DateTime<Utc>) -> String {
|
|||
let duration = now.signed_duration_since(event);
|
||||
|
||||
if duration.num_days() > 0 {
|
||||
return format!("{}d ago", duration.num_days());
|
||||
format!("{}d ago", duration.num_days())
|
||||
} else if duration.num_hours() > 0 {
|
||||
return format!("{}h ago", duration.num_hours());
|
||||
format!("{}h ago", duration.num_hours())
|
||||
} else if duration.num_minutes() > 0 {
|
||||
return format!("{}m ago", duration.num_minutes());
|
||||
format!("{}m ago", duration.num_minutes())
|
||||
} else {
|
||||
return "Just now".to_string();
|
||||
"Just now".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
fn print_label(label: &Label) {
|
||||
let color = hex_to_color(&label.hex_color).unwrap();
|
||||
print_color_bg(color, &label.title.trim());
|
||||
print_color_bg(color, label.title.trim());
|
||||
}
|
||||
|
||||
pub fn print_all_labels(api: &VikunjaAPI) {
|
||||
|
|
|
@ -15,7 +15,7 @@ pub fn list_projects(api: &VikunjaAPI) {
|
|||
for prj in projects {
|
||||
project_map
|
||||
.entry(prj.parent_project_id)
|
||||
.or_insert_with(Vec::new)
|
||||
.or_default()
|
||||
.push(prj);
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ pub fn list_projects(api: &VikunjaAPI) {
|
|||
hex_to_color(&prj.hex_color).unwrap()
|
||||
};
|
||||
print_color(color, &prj.title);
|
||||
print!(" [{}]\n", prj.id);
|
||||
println!(" [{}]", prj.id);
|
||||
|
||||
if let Some(sub_projects) = project_map.get(&(prj.id as usize)) {
|
||||
for sub_prj in sub_projects {
|
||||
|
@ -36,7 +36,7 @@ pub fn list_projects(api: &VikunjaAPI) {
|
|||
hex_to_color(&sub_prj.hex_color).unwrap()
|
||||
};
|
||||
print_color(color, &format!(" - {}", sub_prj.title));
|
||||
print!(" [{}]\n", sub_prj.id);
|
||||
println!(" [{}]", sub_prj.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
api::{Label, ProjectID, Task, VikunjaAPI},
|
||||
ui::{hex_to_color, parse_datetime, print_color, print_color_bg, print_label, time_since},
|
||||
api::{ProjectID, Task, VikunjaAPI},
|
||||
ui::{parse_datetime, print_color, print_label, time_since},
|
||||
};
|
||||
|
||||
fn print_task_oneline(task: &Task, api: &VikunjaAPI) {
|
||||
|
@ -30,7 +30,7 @@ fn print_task_oneline(task: &Task, api: &VikunjaAPI) {
|
|||
}
|
||||
}
|
||||
|
||||
print!("\n");
|
||||
println!();
|
||||
}
|
||||
|
||||
pub fn print_current_tasks(
|
||||
|
@ -57,27 +57,20 @@ pub fn print_current_tasks(
|
|||
|
||||
if let Some(project) = project {
|
||||
let p_id = ProjectID::parse(api, project).unwrap();
|
||||
|
||||
selection = selection
|
||||
.into_iter()
|
||||
.filter(|x| x.project_id == p_id.0)
|
||||
.collect();
|
||||
selection.retain(|x| x.project_id == p_id.0);
|
||||
}
|
||||
|
||||
if let Some(label_match) = label {
|
||||
selection = selection
|
||||
.into_iter()
|
||||
.filter(|x| {
|
||||
if let Some(labels) = &x.labels {
|
||||
for label in labels {
|
||||
if label.title.trim() == *label_match {
|
||||
return true;
|
||||
}
|
||||
selection.retain(|x| {
|
||||
if let Some(labels) = &x.labels {
|
||||
for label in labels {
|
||||
if label.title.trim() == *label_match {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
false
|
||||
});
|
||||
}
|
||||
|
||||
for task in selection {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue