From 3b7e013c62ed14d912fe0b90cb2af4d60d419094 Mon Sep 17 00:00:00 2001 From: John Cairns Date: Wed, 20 Dec 2023 10:33:35 -0600 Subject: [PATCH] 1: cleanup handling for timing when the seconds default differs from 60 --- src/main.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 028e823..e3744c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use gloo_timers::callback::Interval; -use log::{debug, info}; +use log::info; use yew::{html, Component, Context, Html}; use emom::emomtimer::{Msg, Time, Timer, DEFAULT_MINUTES, DEFAULT_ROUNDS, DEFAULT_SECONDS}; @@ -40,7 +40,6 @@ impl App { } fn tick(&mut self) { - debug!("ticking"); self.timer.current_time.tick(self.max_seconds()); if self.timer.current_time.is_zero() { info!("end of round"); @@ -59,7 +58,7 @@ impl App { } fn max_seconds(&self) -> usize { - if self.round_time.seconds == 0 { + if self.round_time.minutes > 0 || self.round_time.seconds == 0 { 60 } else { self.round_time.seconds @@ -67,15 +66,24 @@ impl App { } fn toggle_blinked_off(&mut self) { - if emom::emomtimer::distance::<_>(self.max_seconds(), self.timer.current_time.seconds) > 4 - && self.blinked + if self.round_time.minutes == self.timer.current_time.minutes + || emom::emomtimer::distance::<_>( + self.round_time.seconds, + self.timer.current_time.seconds, + ) > 4 + && self.blinked { self.blinked = false; } } fn toggle_blinked(&mut self) { - if emom::emomtimer::distance::<_>(self.max_seconds(), self.timer.current_time.seconds) < 4 { + if self.round_time.minutes == self.timer.current_time.minutes + && emom::emomtimer::distance::<_>( + self.round_time.seconds, + self.timer.current_time.seconds, + ) < 4 + { self.blinked = !self.blinked; } } @@ -190,10 +198,10 @@ impl Component for App {
-

{ "EMOM Timer" }

+

{ "EMOM Timer" }

{ format!("{}/{}", state.current_round, state.rounds) } - + { format!("{}:{:02}", self.round_time.minutes, self.round_time.seconds) }