aboutsummaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-07-19 07:27:32 +0100
committerAkshay <[email protected]>2020-07-19 07:27:32 +0100
commit516116fbe429043303a354f4a71eba4badbd34fc (patch)
tree83a22908119b1b4c880957c63ed363da14d00c5f /src/app
parent6bdf3fa422dc5d53def54ba2ad3e055737773440 (diff)
stop habits from consuming global events
Diffstat (limited to 'src/app')
-rw-r--r--src/app/impl_self.rs25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs
index f4c16f3..2b115a0 100644
--- a/src/app/impl_self.rs
+++ b/src/app/impl_self.rs
@@ -211,6 +211,15 @@ impl App {
211 } 211 }
212 212
213 pub fn parse_command(&mut self, result: Result<Command, CommandLineError>) { 213 pub fn parse_command(&mut self, result: Result<Command, CommandLineError>) {
214 let mut _track = |name: &str, event: TrackEvent| {
215 let target_habit = self
216 .habits
217 .iter_mut()
218 .find(|x| x.name() == name && x.is_auto());
219 if let Some(h) = target_habit {
220 h.modify(Local::now().naive_utc().date(), event);
221 }
222 };
214 match result { 223 match result {
215 Ok(c) => match c { 224 Ok(c) => match c {
216 Command::Add(name, goal, auto) => { 225 Command::Add(name, goal, auto) => {
@@ -226,22 +235,10 @@ impl App {
226 self.focus = 0; 235 self.focus = 0;
227 } 236 }
228 Command::TrackUp(name) => { 237 Command::TrackUp(name) => {
229 let target_habit = self 238 _track(&name, TrackEvent::Increment);
230 .habits
231 .iter_mut()
232 .find(|x| x.name() == name && x.is_auto());
233 if let Some(h) = target_habit {
234 h.modify(Local::now().naive_utc().date(), TrackEvent::Increment);
235 }
236 } 239 }
237 Command::TrackDown(name) => { 240 Command::TrackDown(name) => {
238 let target_habit = self 241 _track(&name, TrackEvent::Decrement);
239 .habits
240 .iter_mut()
241 .find(|x| x.name() == name && x.is_auto());
242 if let Some(h) = target_habit {
243 h.modify(Local::now().naive_utc().date(), TrackEvent::Decrement);
244 }
245 } 242 }
246 Command::Quit => self.save_state(), 243 Command::Quit => self.save_state(),
247 Command::MonthNext => self.sift_forward(), 244 Command::MonthNext => self.sift_forward(),