feat(tasks): PR 1.5 — return refreshed subtask + parent from completion

Change complete_subtask_and_check_parent to return
(TaskRow, Option<TaskRow>): the refreshed subtask, plus the parent when
the cascade auto-completed it. Both rows are read inside the same
transaction so the frontend never observes partial state.

Wrap the cmd in a CompleteSubtaskResult { updatedSubtask,
autoCompletedParent } DTO. MicroSteps now applies the refreshed subtask
locally and, when present, calls a new replaceTaskFromDto helper on the
Tasks store so the parent's done/doneAt/badge counts update without a
follow-up list_tasks_cmd round-trip.

Test: complete_subtask_returns_updated_subtask_and_optional_parent
covers both paths (sibling-pending → None, last-sibling → Some(parent)).
All 61 kon-storage tests pass; svelte-check clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-26 18:17:30 +01:00
parent 0a8cb55447
commit 6e663a3625
4 changed files with 126 additions and 7 deletions

View File

@@ -378,14 +378,29 @@ pub async fn list_subtasks_cmd(
.map_err(|e| e.to_string())
}
/// Return shape for `complete_subtask_cmd`. The frontend uses
/// `updated_subtask` to refresh the row in MicroSteps and, when present,
/// uses `auto_completed_parent` to swap the parent in the Tasks store
/// without a round-trip refetch (PR 1.5).
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CompleteSubtaskResult {
pub updated_subtask: TaskDto,
pub auto_completed_parent: Option<TaskDto>,
}
#[tauri::command]
pub async fn complete_subtask_cmd(
state: tauri::State<'_, AppState>,
subtask_id: String,
) -> Result<(), String> {
db_complete_subtask(&state.db, &subtask_id)
) -> Result<CompleteSubtaskResult, String> {
let (subtask_row, parent_row) = db_complete_subtask(&state.db, &subtask_id)
.await
.map_err(|e| e.to_string())
.map_err(|e| e.to_string())?;
Ok(CompleteSubtaskResult {
updated_subtask: TaskDto::from(subtask_row),
auto_completed_parent: parent_row.map(TaskDto::from),
})
}
/// Phase 8: daily completion counts for the Tasks-page badge and the