[refactor] simplify app state to a single countdown service

- replace AppState.countdowns vector with countdown_service
- add CountdownService::new(id, label, duration) for configurable initialization
- add CountdownService::default() with default countdown values
- remove unused next_id field and note TODO for multi-countdown support
This commit is contained in:
2026-02-26 12:32:52 +01:00
parent 7817c9c907
commit 503a3ef94c
2 changed files with 9 additions and 7 deletions

View File

@@ -20,18 +20,18 @@ impl ClockAnchor {
instant.duration_since(self.boot_instant).as_millis() + self.boot_epoch_ms
}
}
//TODO: implement the handling of multiple countdowns
#[derive(Debug)]
pub struct AppState {
pub clock_anchor: ClockAnchor,
pub countdowns: Vec<CountdownService>,
pub countdown_service: CountdownService,
}
impl AppState {
pub fn new() -> Self {
Self {
clock_anchor: ClockAnchor::new(),
countdowns: vec![CountdownService::new()],
countdown_service: CountdownService::default(),
}
}
}

View File

@@ -7,14 +7,16 @@ use crate::countdown::model::{Countdown, CountdownError};
#[derive(Debug)]
pub struct CountdownService {
countdown: Mutex<Countdown>,
next_id: u64,
}
impl CountdownService {
pub fn new() -> Self {
pub fn default() -> Self {
Self::new(0, "Countdown0", Duration::new(600, 0))
}
pub fn new(id: u64, label: &str, duration: Duration) -> Self {
Self {
countdown: Mutex::new(Countdown::new(0, "Countdown0", Duration::new(600, 0))),
next_id: 1,
countdown: Mutex::new(Countdown::new(id, label, duration)),
}
}