Ajoute un bouton play sur les entrées
En tête du groupe d'actions : ▶ arrête le timer en cours et en relance
un sur le même projet et la même note (POST /ui/entries/{id}/relancer) ;
sur l'entrée en cours, ■ l'arrête. Les deux émettent timer-changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f612dbd764
commit
2ff27b2a65
5 files changed
+69
-7
No files matched your search
+19
-7
@@ -46,6 +46,7 @@ pub fn router() -> Router<SqlitePool> {
|
||||
get(entry_row).put(update_entry).delete(delete_entry),
|
||||
)
|
||||
.route("/ui/entries/{id}/edit", get(entry_edit))
|
||||
.route("/ui/entries/{id}/relancer", post(restart_entry))
|
||||
.route(
|
||||
"/ui/entries/{id}/dupliquer",
|
||||
get(entry_duplicate).post(duplicate_entry),
|
||||
@@ -99,6 +100,16 @@ fn with_entries_changed(resp: Response) -> Response {
|
||||
(AppendHeaders([("HX-Trigger", "entries-changed")]), resp).into_response()
|
||||
}
|
||||
|
||||
/// Same, plus `timer-changed` so the dashboard timer follows a start/stop
|
||||
/// made elsewhere (header, entry lists).
|
||||
fn with_timer_changed(resp: Response) -> Response {
|
||||
(
|
||||
AppendHeaders([("HX-Trigger", "entries-changed, timer-changed")]),
|
||||
resp,
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
|
||||
struct ProjectOption {
|
||||
id: i64,
|
||||
name: String,
|
||||
@@ -363,13 +374,7 @@ async fn stop_timer(State(pool): State<SqlitePool>) -> PageResult {
|
||||
Ok(_) | Err(AppError::Conflict(_)) => {}
|
||||
Err(e) => return Err(e.into()),
|
||||
}
|
||||
// `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())
|
||||
Ok(with_timer_changed(render(timer_state(&pool).await?)?))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -727,6 +732,13 @@ async fn update_entry(
|
||||
Ok(with_entries_changed(render(EntryRowTpl { e })?))
|
||||
}
|
||||
|
||||
/// Stops the running timer and starts a new one on this entry's project and note.
|
||||
async fn restart_entry(State(pool): State<SqlitePool>, Path(id): Path<i64>) -> PageResult {
|
||||
let e = entries::get(&pool, id).await?;
|
||||
entries::start(&pool, e.project_id, &e.note).await?;
|
||||
Ok(with_timer_changed(StatusCode::OK.into_response()))
|
||||
}
|
||||
|
||||
async fn delete_entry(State(pool): State<SqlitePool>, Path(id): Path<i64>) -> PageResult {
|
||||
entries::delete(&pool, id).await?;
|
||||
// htmx swaps the row with this empty body, removing it.
|
||||
|
||||
Reference in new issue
Block a user