Skip to content

Commit

Permalink
1: cleanup handling for timing when the seconds default differs from 60
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 committed Dec 20, 2023
1 parent facb9e6 commit 3b7e013
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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");
Expand All @@ -59,23 +58,32 @@ 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
}
}

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;
}
}
Expand Down Expand Up @@ -190,10 +198,10 @@ impl Component for App {
</head>
<body style={if self.blinked { "color:red" } else { "color:black" }} >
<div width="100%" height="100%" id="background">
<div class="mainTitle" align="center"><h1>{ "EMOM Timer" }</h1></div>
<div class="mainTitle" align="left"><h3>{ "EMOM Timer" }</h3></div>
<div class="roundsDisplay" id="roundsDisplay" style="text-align:left">
{ format!("{}/{}", state.current_round, state.rounds) }
<span style="float:right;">
<span style="float:left; width:660px">
{ format!("{}:{:02}", self.round_time.minutes, self.round_time.seconds) }
</span>
</div>
Expand Down

0 comments on commit 3b7e013

Please sign in to comment.