forked from janek/mostr
1
0
Fork 0

fix: only show default state for proper tasks

This commit is contained in:
xeruf 2024-08-18 22:43:14 +03:00
parent eaeeebca7b
commit 8bf305d4d4
2 changed files with 12 additions and 5 deletions

View File

@ -122,6 +122,13 @@ impl Task {
self.state().unwrap_or_else(|| self.default_state()) self.state().unwrap_or_else(|| self.default_state())
} }
/// Returns None for a stateless task.
pub(crate) fn state_label(&self) -> Option<ColoredString> {
self.state()
.or_else(|| Some(self.default_state()).filter(|_| self.is_task()))
.map(|state| state.get_colored_label())
}
fn default_state(&self) -> TaskState { fn default_state(&self) -> TaskState {
TaskState { TaskState {
name: None, name: None,
@ -151,7 +158,7 @@ impl Task {
"pubkey" => Some(self.event.pubkey.to_string()), "pubkey" => Some(self.event.pubkey.to_string()),
"created" => Some(local_datetimestamp(&self.event.created_at)), "created" => Some(local_datetimestamp(&self.event.created_at)),
// Dynamic // Dynamic
"status" => Some(self.state_or_default().get_label()), "status" => self.state_label().map(|c| c.to_string()),
"desc" => self.descriptions().last().cloned(), "desc" => self.descriptions().last().cloned(),
"description" => Some(self.descriptions().join(" ")), "description" => Some(self.descriptions().join(" ")),
"hashtags" => self.filter_tags(|tag| { is_hashtag(tag) }), "hashtags" => self.filter_tags(|tag| { is_hashtag(tag) }),

View File

@ -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()) { 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(); return format!("Blocked by \"{}\"", task.get_title()).bright_red().to_string();
} }
let state = task.state_or_default(); let state = task.pure_state();
if state.state.is_open() && progress.is_some_and(|p| p > 0.1) { if state.is_open() && progress.is_some_and(|p| p > 0.1) {
state.state.colorize(&prog_string) state.colorize(&prog_string)
} else { } else {
state.get_colored_label() task.state_label().unwrap_or_default()
}.to_string() }.to_string()
} }
"progress" => prog_string.clone(), "progress" => prog_string.clone(),