forked from janek/mostr
1
0
Fork 0

fix(task): properly parse str into State

This commit is contained in:
xeruf 2024-08-10 18:16:21 +03:00
parent b74ac18e39
commit 06bfe8e18a
2 changed files with 13 additions and 6 deletions

View File

@ -219,6 +219,17 @@ pub(crate) enum State {
Pending,
Procedure,
}
impl From<&str> for State {
fn from(value: &str) -> Self {
match value {
"Closed" => State::Closed,
"Done" => State::Done,
"Pending" => State::Pending,
"Proc" | "Procedure" | "List" => State::Procedure,
_ => State::Open,
}
}
}
impl TryFrom<Kind> for State {
type Error = ();
@ -236,7 +247,7 @@ impl TryFrom<Kind> for State {
impl State {
pub(crate) fn is_open(&self) -> bool {
match self {
State::Open | State::Procedure => true,
State::Open | State::Pending | State::Procedure => true,
_ => false,
}
}

View File

@ -712,11 +712,7 @@ impl Tasks {
}
pub(crate) fn set_state_for_with(&mut self, id: EventId, comment: &str) {
self.set_state_for(id, comment, match comment {
"Closed" => State::Closed,
"Done" => State::Done,
_ => State::Open,
});
self.set_state_for(id, comment, comment.into());
}
pub(crate) fn set_state_for(&mut self, id: EventId, comment: &str, state: State) -> EventId {