trackWork 0.15.0

A terminal-based time tracking application for managing work sessions
pub mod input;
pub mod ui;

pub use input::handle_triggers_input;
pub use ui::draw_triggers;

/// Lifecycle events that can fire a webhook callback.
#[derive(Clone, Copy, Debug)]
pub enum TriggerEvent {
    /// The "At Work" workday span first begins for today (clock-in).
    DayStart,
    /// An entry is marked as off-work (out of office).
    OooStart,
    /// A running off-work entry is stopped (back in office).
    OooEnd,
}

/// Human-readable labels, indexed to match [`TriggerEvent::index`].
pub const EVENT_LABELS: [&str; 3] = [
    "Day Start",
    "Out of Office Start",
    "Out of Office End",
];

impl TriggerEvent {
    pub fn index(self) -> usize {
        match self {
            TriggerEvent::DayStart => 0,
            TriggerEvent::OooStart => 1,
            TriggerEvent::OooEnd => 2,
        }
    }

    pub fn label(self) -> &'static str {
        EVENT_LABELS[self.index()]
    }
}

/// POST a JSON body to a webhook URL. Returns the HTTP status code on success.
pub fn send(url: &str, body: &str) -> Result<u16, String> {
    let client = reqwest::blocking::Client::new();
    let resp = client
        .post(url)
        .header("Content-Type", "application/json")
        .body(body.to_string())
        .send()
        .map_err(|e| e.to_string())?;
    Ok(resp.status().as_u16())
}