forked from janek/mostr
1
0
Fork 0

refactor(task): return descriptions as references

This commit is contained in:
xeruf 2024-07-26 12:38:27 +03:00
parent 4d9a496a1b
commit 867ba917c0
1 changed files with 14 additions and 10 deletions

View File

@ -15,7 +15,11 @@ impl Task {
Task { Task {
children: Default::default(), children: Default::default(),
props: Default::default(), props: Default::default(),
tags: if event.tags.is_empty() { None } else { Some(event.tags.iter().cloned().collect()) }, tags: if event.tags.is_empty() {
None
} else {
Some(event.tags.iter().cloned().collect())
},
event, event,
} }
} }
@ -30,10 +34,10 @@ impl Task {
None None
} }
fn descriptions(&self) -> impl Iterator<Item = String> + '_ { fn descriptions(&self) -> impl Iterator<Item = &String> + '_ {
self.props.iter().filter_map(|event| { self.props.iter().filter_map(|event| {
if event.kind == Kind::TextNote { if event.kind == Kind::TextNote {
Some(event.content.clone()) Some(&event.content)
} else { } else {
None None
} }
@ -97,11 +101,11 @@ impl Task {
"name" => Some(self.event.content.clone()), "name" => Some(self.event.content.clone()),
"time" => Some(self.time_tracked().to_string()), // TODO: format properly "time" => Some(self.time_tracked().to_string()), // TODO: format properly
"tags" => self.tags.as_ref().map(|tags| { "tags" => self.tags.as_ref().map(|tags| {
tags.iter() tags.iter()
.map(|t| format!("{}", t.content().unwrap())) .map(|t| format!("{}", t.content().unwrap()))
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join(" ") .join(" ")
}), }),
"props" => Some(format!( "props" => Some(format!(
"{:?}", "{:?}",
self.props self.props
@ -111,8 +115,8 @@ impl Task {
)), )),
"desc" | "description" => self.descriptions().fold(None, |total, s| { "desc" | "description" => self.descriptions().fold(None, |total, s| {
Some(match total { Some(match total {
None => s, None => s.clone(),
Some(i) => i + " " + &s, Some(i) => i + " " + s,
}) })
}), }),
_ => { _ => {