From 2ce5801925da76db1a142e1d683940af71fbc6a4 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Wed, 20 Nov 2024 23:10:28 +0100 Subject: [PATCH] fix: task descriptions ordering --- src/kinds.rs | 2 +- src/task.rs | 9 +++++---- src/tasks.rs | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/kinds.rs b/src/kinds.rs index 2c611df..e07b2bd 100644 --- a/src/kinds.rs +++ b/src/kinds.rs @@ -41,7 +41,7 @@ Task: - `hashtags` - list of hashtags set for the task - `tags` - values of all nostr tags associated with the event, except event tags - `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 Utilities: - `state` - indicator of current progress diff --git a/src/task.rs b/src/task.rs index d5e7319..8857d33 100644 --- a/src/task.rs +++ b/src/task.rs @@ -92,11 +92,12 @@ impl Task { self.event.content.trim().trim_start_matches('#').to_string() } - pub(crate) fn description_events(&self) -> impl Iterator + '_ { + fn description_events(&self) -> impl DoubleEndedIterator + '_ { self.props.iter().filter(|event| event.kind == Kind::TextNote) } - pub(crate) fn descriptions(&self) -> impl Iterator + '_ { + /// Description items, ordered newest to oldest + pub(crate) fn descriptions(&self) -> impl DoubleEndedIterator + '_ { self.description_events().map(|e| &e.content) } @@ -208,8 +209,8 @@ impl Task { // Dynamic "priority" => self.priority_raw().map(|c| c.to_string()), "status" => self.state_label().map(|c| c.to_string()), - "desc" => self.descriptions().last().cloned(), - "description" => Some(self.descriptions().join(" ")), + "desc" => self.descriptions().next().cloned(), + "description" => Some(self.descriptions().rev().join(" ")), "hashtags" => Some(self.join_tags(|tag| { is_hashtag(tag) })), "tags" => Some(self.join_tags(|_| true)), // TODO test these! "alltags" => Some(format!("{:?}", self.tags)), diff --git a/src/tasks.rs b/src/tasks.rs index 7bf0531..6daa0d4 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -1291,7 +1291,7 @@ impl Display for TasksRelay { state.get_label(), format_timestamp_relative(&state.time) )?; - for d in t.descriptions() { writeln!(lock, "{}", d)?; } + for d in t.descriptions().rev() { writeln!(lock, "{}", d)?; } writeln!(lock)?; }