diff --git a/src/task.rs b/src/task.rs index 6575b60..47c2f81 100644 --- a/src/task.rs +++ b/src/task.rs @@ -65,12 +65,14 @@ impl Task { self.state().map_or(State::Open, |s| s.state) } - pub(crate) fn update_state(&mut self, state: State, comment: &str) { - self.props.push(make_event( + pub(crate) fn update_state(&mut self, state: State, comment: &str) -> Event { + let event = make_event( state.kind(), comment, &[Tag::event(self.event.id)], - )) + ); + self.props.push(event.clone()); + event } fn default_state(&self) -> TaskState { diff --git a/src/tasks.rs b/src/tasks.rs index 5399323..3b22e35 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -178,24 +178,24 @@ impl Tasks { } } - pub(crate) fn update_state_for(&mut self, id: &EventId, comment: &str, f: F) + pub(crate) fn update_state_for(&mut self, id: &EventId, comment: &str, f: F) -> Option where F: FnOnce(&Task) -> Option, { - self.tasks.get_mut(id).map(|t| { + self.tasks.get_mut(id).and_then(|t| { f(t).map(|s| { - t.update_state(s, comment); + t.update_state(s, comment) }) - }); + }) } - pub(crate) fn update_state(&mut self, comment: &str, f: F) + pub(crate) fn update_state(&mut self, comment: &str, f: F) -> Option where F: FnOnce(&Task) -> Option, { - self.position.inspect(|id| { - self.update_state_for(id, comment, f); - }); + self.position.and_then(|id| { + self.update_state_for(&id, comment, f) + }) } }