feat: return Event from task state updates

This commit is contained in:
xeruf 2024-07-23 13:45:25 +03:00
parent a3f342d80a
commit ab28cf4fd7
2 changed files with 13 additions and 11 deletions

View File

@ -65,12 +65,14 @@ impl Task {
self.state().map_or(State::Open, |s| s.state) self.state().map_or(State::Open, |s| s.state)
} }
pub(crate) fn update_state(&mut self, state: State, comment: &str) { pub(crate) fn update_state(&mut self, state: State, comment: &str) -> Event {
self.props.push(make_event( let event = make_event(
state.kind(), state.kind(),
comment, comment,
&[Tag::event(self.event.id)], &[Tag::event(self.event.id)],
)) );
self.props.push(event.clone());
event
} }
fn default_state(&self) -> TaskState { fn default_state(&self) -> TaskState {

View File

@ -178,24 +178,24 @@ impl Tasks {
} }
} }
pub(crate) fn update_state_for<F>(&mut self, id: &EventId, comment: &str, f: F) pub(crate) fn update_state_for<F>(&mut self, id: &EventId, comment: &str, f: F) -> Option<Event>
where where
F: FnOnce(&Task) -> Option<State>, F: FnOnce(&Task) -> Option<State>,
{ {
self.tasks.get_mut(id).map(|t| { self.tasks.get_mut(id).and_then(|t| {
f(t).map(|s| { f(t).map(|s| {
t.update_state(s, comment); t.update_state(s, comment)
}) })
}); })
} }
pub(crate) fn update_state<F>(&mut self, comment: &str, f: F) pub(crate) fn update_state<F>(&mut self, comment: &str, f: F) -> Option<Event>
where where
F: FnOnce(&Task) -> Option<State>, F: FnOnce(&Task) -> Option<State>,
{ {
self.position.inspect(|id| { self.position.and_then(|id| {
self.update_state_for(id, comment, f); self.update_state_for(&id, comment, f)
}); })
} }
} }