From 0fc1f16c9de0b706765ee557e8a47780491f242b Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 17 Apr 2026 16:23:51 +0000 Subject: [PATCH] fix(new-task): attach date in a single create_task call to prevent loss The new-task bottom sheet called createTask then, if a date was set, made a follow-up updateTask to attach the date. If the update failed (e.g. filesystem error between the two writes) the user was left with a dateless task and, because transient sync errors are already suppressed, often no visible error either. Extend the create_task Tauri command to accept optional date/has_time fields and pass them through. The frontend now creates the task in one round-trip. No separate update path needed. --- apps/tauri/src-tauri/src/lib.rs | 7 +++++++ apps/tauri/src/lib/components/NewTaskInput.svelte | 13 +++++++++---- apps/tauri/src/lib/stores/app.svelte.ts | 10 +++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/apps/tauri/src-tauri/src/lib.rs b/apps/tauri/src-tauri/src/lib.rs index 937afc4..8f512e9 100644 --- a/apps/tauri/src-tauri/src/lib.rs +++ b/apps/tauri/src-tauri/src/lib.rs @@ -374,6 +374,8 @@ fn create_task( title: String, description: Option, parent_id: Option, + date: Option>, + has_time: Option, state: State<'_, Mutex>, ) -> Result { let mut s = lock_state(&state)?; @@ -388,6 +390,11 @@ fn create_task( let parent_uuid = Uuid::parse_str(&pid).map_err(|e| e.to_string())?; task.parent_id = Some(parent_uuid); } + // Accept the date fields at creation time so callers don't have to do a + // second update() round-trip just to attach a date — which previously + // dropped the date entirely if the follow-up update failed. + task.date = date; + task.has_time = has_time.unwrap_or(false); repo_mut(&mut s)? .create_task(id, task) .map_err(|e| e.to_string()) diff --git a/apps/tauri/src/lib/components/NewTaskInput.svelte b/apps/tauri/src/lib/components/NewTaskInput.svelte index 9edc833..cf8027d 100644 --- a/apps/tauri/src/lib/components/NewTaskInput.svelte +++ b/apps/tauri/src/lib/components/NewTaskInput.svelte @@ -17,10 +17,15 @@ async function handleSubmit() { if (!title.trim()) return; - const created = await app.createTask(title.trim(), description.trim() || undefined); - if (date && created) { - await app.updateTask({ ...created, date: date, has_time: dateHasTime }); - } + // Pass date/has_time into createTask directly so the date can't be lost + // if a second round-trip to update() failed after the create succeeded. + await app.createTask( + title.trim(), + description.trim() || undefined, + undefined, + date, + dateHasTime, + ); title = ""; description = ""; date = null; diff --git a/apps/tauri/src/lib/stores/app.svelte.ts b/apps/tauri/src/lib/stores/app.svelte.ts index 2b57daa..65e0238 100644 --- a/apps/tauri/src/lib/stores/app.svelte.ts +++ b/apps/tauri/src/lib/stores/app.svelte.ts @@ -261,7 +261,13 @@ async function deleteList(id: string) { } } -async function createTask(title: string, description?: string, parentId?: string): Promise { +async function createTask( + title: string, + description?: string, + parentId?: string, + date?: string | null, + hasTime?: boolean, +): Promise { if (!activeListId) return null; try { const task = await invoke("create_task", { @@ -269,6 +275,8 @@ async function createTask(title: string, description?: string, parentId?: string title, description: description ?? "", parentId: parentId ?? null, + date: date ?? null, + hasTime: hasTime ?? false, }); tasks = parentId ? [task, ...tasks] : [...tasks, task]; error = null;