aboutsummaryrefslogtreecommitdiff
path: root/src/pomo/state.rs
blob: c7a3011f5525fcd45427e9f0442eab1021945c46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use ratatui::widgets::ListState;
use ratatui::prelude::Color;
use std::time::Duration;

#[derive(PartialEq, Clone, Copy)]
pub enum SessionMode {
    Work,
    ShortBreak,
    LongBreak,
}

impl SessionMode {
    pub fn get_color(&self) -> Color {
        match self {
            SessionMode::Work => Color::Cyan,
            SessionMode::ShortBreak => Color::Green,
            SessionMode::LongBreak => Color::Magenta,
        }
    }
}

pub struct Task {
    pub title: String,
    pub is_done: bool,
}

pub struct Pomo {
    pub mode: SessionMode,
    pub time_remaining: Duration,
    pub is_running: bool,
    pub tasks: Vec<Task>,
    pub task_state: ListState,
    pub should_quit: bool,
}

impl Pomo {
    pub fn new() -> Self {
        let dummy_tasks = vec![
            Task { title: "Complete Milestone 1".into(), is_done: true },
            Task { title: "Refactor UI for Flocus look".into(), is_done: false },
        ];

        Self {
            mode: SessionMode::Work,
            time_remaining: Duration::from_secs(25 * 60),
            is_running: false,
            tasks: dummy_tasks,
            task_state: ListState::default(),
            should_quit: false,
        }
    }

    pub fn tick(&mut self) {
        if self.is_running && self.time_remaining.as_secs() > 0 {
            self.time_remaining -= Duration::from_secs(1);
        } else if self.time_remaining.as_secs() == 0 {
            self.is_running = false;
            // TODO: Add further mode switching logic
        }
    }

    pub fn toggle_timer(&mut self) {
        self.is_running = !self.is_running;
    }
}