Affiche le timer en cours dans le header
Pastille à droite du header sur toutes les pages (fragment /ui/timer/entete) : description ou projet, chrono et bouton stop, bordée à la couleur du projet. L'arrêt émet timer-changed pour rafraîchir le timer de l'accueil (GET /ui/timer). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cbc8ba8ce0
commit
ef69462e06
7 files changed
+79
-2
No files matched your search
+26
-1
@@ -27,6 +27,8 @@ pub fn router() -> Router<SqlitePool> {
|
||||
.route("/reports", get(reports_page))
|
||||
.route("/ui/today", get(today_fragment))
|
||||
.route("/ui/dernieres-entrees", get(recent_fragment))
|
||||
.route("/ui/timer", get(timer_fragment))
|
||||
.route("/ui/timer/entete", get(mini_timer))
|
||||
.route("/ui/timer/start", post(start_timer))
|
||||
.route("/ui/timer/stop", post(stop_timer))
|
||||
.route("/ui/timer/debut", post(set_timer_start))
|
||||
@@ -222,6 +224,13 @@ struct TimerTpl {
|
||||
groups: Vec<ProjectGroup>,
|
||||
}
|
||||
|
||||
/// Compact running timer shown in the header of every page.
|
||||
#[derive(Template)]
|
||||
#[template(path = "_mini_timer.html")]
|
||||
struct MiniTimerTpl {
|
||||
running: Option<Entry>,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "_today.html")]
|
||||
struct TodayTpl {
|
||||
@@ -318,6 +327,16 @@ async fn dashboard(State(pool): State<SqlitePool>) -> PageResult {
|
||||
})
|
||||
}
|
||||
|
||||
async fn timer_fragment(State(pool): State<SqlitePool>) -> PageResult {
|
||||
render(timer_state(&pool).await?)
|
||||
}
|
||||
|
||||
async fn mini_timer(State(pool): State<SqlitePool>) -> PageResult {
|
||||
render(MiniTimerTpl {
|
||||
running: entries::running(&pool).await?,
|
||||
})
|
||||
}
|
||||
|
||||
async fn today_fragment(State(pool): State<SqlitePool>) -> PageResult {
|
||||
render(today_state(&pool).await?)
|
||||
}
|
||||
@@ -344,7 +363,13 @@ async fn stop_timer(State(pool): State<SqlitePool>) -> PageResult {
|
||||
Ok(_) | Err(AppError::Conflict(_)) => {}
|
||||
Err(e) => return Err(e.into()),
|
||||
}
|
||||
Ok(with_entries_changed(render(timer_state(&pool).await?)?))
|
||||
// `timer-changed` refreshes the dashboard timer when stopped from the header.
|
||||
let resp = render(timer_state(&pool).await?)?;
|
||||
Ok((
|
||||
AppendHeaders([("HX-Trigger", "entries-changed, timer-changed")]),
|
||||
resp,
|
||||
)
|
||||
.into_response())
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
||||
Reference in new issue
Block a user