fix: task descriptions ordering

This commit is contained in:
xeruf 2024-11-20 23:10:28 +01:00
parent ca50bdf3bb
commit 2ce5801925
3 changed files with 7 additions and 6 deletions

View file

@ -41,7 +41,7 @@ Task:
- `hashtags` - list of hashtags set for the task - `hashtags` - list of hashtags set for the task
- `tags` - values of all nostr tags associated with the event, except event tags - `tags` - values of all nostr tags associated with the event, except event tags
- `desc` - last note on the task - `desc` - last note on the task
- `description` - accumulated notes on the task - `description` - all notes on the task
- `time` - time tracked on this task by you - `time` - time tracked on this task by you
Utilities: Utilities:
- `state` - indicator of current progress - `state` - indicator of current progress

View file

@ -92,11 +92,12 @@ impl Task {
self.event.content.trim().trim_start_matches('#').to_string() self.event.content.trim().trim_start_matches('#').to_string()
} }
pub(crate) fn description_events(&self) -> impl Iterator<Item=&Event> + '_ { fn description_events(&self) -> impl DoubleEndedIterator<Item=&Event> + '_ {
self.props.iter().filter(|event| event.kind == Kind::TextNote) self.props.iter().filter(|event| event.kind == Kind::TextNote)
} }
pub(crate) fn descriptions(&self) -> impl Iterator<Item=&String> + '_ { /// Description items, ordered newest to oldest
pub(crate) fn descriptions(&self) -> impl DoubleEndedIterator<Item=&String> + '_ {
self.description_events().map(|e| &e.content) self.description_events().map(|e| &e.content)
} }
@ -208,8 +209,8 @@ impl Task {
// Dynamic // Dynamic
"priority" => self.priority_raw().map(|c| c.to_string()), "priority" => self.priority_raw().map(|c| c.to_string()),
"status" => self.state_label().map(|c| c.to_string()), "status" => self.state_label().map(|c| c.to_string()),
"desc" => self.descriptions().last().cloned(), "desc" => self.descriptions().next().cloned(),
"description" => Some(self.descriptions().join(" ")), "description" => Some(self.descriptions().rev().join(" ")),
"hashtags" => Some(self.join_tags(|tag| { is_hashtag(tag) })), "hashtags" => Some(self.join_tags(|tag| { is_hashtag(tag) })),
"tags" => Some(self.join_tags(|_| true)), // TODO test these! "tags" => Some(self.join_tags(|_| true)), // TODO test these!
"alltags" => Some(format!("{:?}", self.tags)), "alltags" => Some(format!("{:?}", self.tags)),

View file

@ -1291,7 +1291,7 @@ impl Display for TasksRelay {
state.get_label(), state.get_label(),
format_timestamp_relative(&state.time) format_timestamp_relative(&state.time)
)?; )?;
for d in t.descriptions() { writeln!(lock, "{}", d)?; } for d in t.descriptions().rev() { writeln!(lock, "{}", d)?; }
writeln!(lock)?; writeln!(lock)?;
} }