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, Pending,
Procedure, 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 { impl TryFrom<Kind> for State {
type Error = (); type Error = ();
@ -236,7 +247,7 @@ impl TryFrom<Kind> for State {
impl State { impl State {
pub(crate) fn is_open(&self) -> bool { pub(crate) fn is_open(&self) -> bool {
match self { match self {
State::Open | State::Procedure => true, State::Open | State::Pending | State::Procedure => true,
_ => false, _ => false,
} }
} }

View File

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