From 8bf305d4d4e2ae0ea0af176d9b910e39c8f9df1e Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sun, 18 Aug 2024 22:43:14 +0300 Subject: [PATCH] fix: only show default state for proper tasks --- src/task.rs | 9 ++++++++- src/tasks.rs | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/task.rs b/src/task.rs index 9244c35..f0678d6 100644 --- a/src/task.rs +++ b/src/task.rs @@ -122,6 +122,13 @@ impl Task { self.state().unwrap_or_else(|| self.default_state()) } + /// Returns None for a stateless task. + pub(crate) fn state_label(&self) -> Option { + self.state() + .or_else(|| Some(self.default_state()).filter(|_| self.is_task())) + .map(|state| state.get_colored_label()) + } + fn default_state(&self) -> TaskState { TaskState { name: None, @@ -151,7 +158,7 @@ impl Task { "pubkey" => Some(self.event.pubkey.to_string()), "created" => Some(local_datetimestamp(&self.event.created_at)), // Dynamic - "status" => Some(self.state_or_default().get_label()), + "status" => self.state_label().map(|c| c.to_string()), "desc" => self.descriptions().last().cloned(), "description" => Some(self.descriptions().join(" ")), "hashtags" => self.filter_tags(|tag| { is_hashtag(tag) }), diff --git a/src/tasks.rs b/src/tasks.rs index ec8edb2..b0cb3f1 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -468,11 +468,11 @@ impl Tasks { if let Some(task) = task.get_dependendees().iter().filter_map(|id| self.get_by_id(id)).find(|t| t.pure_state().is_open()) { return format!("Blocked by \"{}\"", task.get_title()).bright_red().to_string(); } - let state = task.state_or_default(); - if state.state.is_open() && progress.is_some_and(|p| p > 0.1) { - state.state.colorize(&prog_string) + let state = task.pure_state(); + if state.is_open() && progress.is_some_and(|p| p > 0.1) { + state.colorize(&prog_string) } else { - state.get_colored_label() + task.state_label().unwrap_or_default() }.to_string() } "progress" => prog_string.clone(),