forked from janek/mostr
feat: return Event from task state updates
This commit is contained in:
parent
a3f342d80a
commit
ab28cf4fd7
|
@ -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 {
|
||||
|
|
16
src/tasks.rs
16
src/tasks.rs
|
@ -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
|
||||
F: FnOnce(&Task) -> Option<State>,
|
||||
{
|
||||
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<F>(&mut self, comment: &str, f: F)
|
||||
pub(crate) fn update_state<F>(&mut self, comment: &str, f: F) -> Option<Event>
|
||||
where
|
||||
F: FnOnce(&Task) -> Option<State>,
|
||||
{
|
||||
self.position.inspect(|id| {
|
||||
self.update_state_for(id, comment, f);
|
||||
});
|
||||
self.position.and_then(|id| {
|
||||
self.update_state_for(&id, comment, f)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue