refactor(task): state kind numbers as enum values

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

View File

@ -3,18 +3,23 @@ use log::info;
use nostr_sdk::{Alphabet, EventBuilder, EventId, Kind, Tag, TagStandard};
use nostr_sdk::TagStandard::Hashtag;
use crate::task::State;
pub const METADATA_KIND: u16 = 0;
pub const NOTE_KIND: u16 = 1;
pub const TASK_KIND: u16 = 1621;
pub const PROCEDURE_KIND: u16 = 1639;
pub const TRACKING_KIND: u16 = 1650;
pub const KINDS: [u16; 9] = [
METADATA_KIND,
NOTE_KIND,
TASK_KIND,
TRACKING_KIND,
PROCEDURE_KIND,
1630, 1631, 1632, 1633];
State::Open as u16,
State::Done as u16,
State::Closed as u16,
State::Pending as u16,
State::Procedure as u16
];
/// Helper for available properties.
/// TODO: use formatting - bold / heading / italics - and generate from code

View File

@ -11,7 +11,7 @@ use log::{debug, error, info, trace, warn};
use nostr_sdk::{Event, EventId, Kind, Tag, TagStandard, Timestamp};
use crate::helpers::{local_datetimestamp, some_non_empty};
use crate::kinds::{is_hashtag, PROCEDURE_KIND, TASK_KIND};
use crate::kinds::{is_hashtag, TASK_KIND};
pub static MARKER_PARENT: &str = "parent";
pub static MARKER_DEPENDS: &str = "depends";
@ -219,6 +219,7 @@ impl Display for TaskState {
}
}
pub const PROCEDURE_KIND: u16 = 1639;
#[derive(Debug, Copy, Clone, PartialEq, Ord, PartialOrd, Eq)]
pub(crate) enum State {
/// Actionable
@ -265,14 +266,8 @@ impl State {
}
}
pub(crate) fn kind(&self) -> u16 {
match self {
State::Open => 1630,
State::Done => 1631,
State::Closed => 1632,
State::Pending => 1633,
State::Procedure => PROCEDURE_KIND,
}
pub(crate) fn kind(self) -> u16 {
self as u16
}
pub(crate) fn colorize(&self, str: &str) -> ColoredString {