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.
This commit is contained in:
Claude 2026-04-17 16:23:51 +00:00
parent d01bd9d280
commit 0fc1f16c9d
No known key found for this signature in database
3 changed files with 25 additions and 5 deletions

View file

@ -374,6 +374,8 @@ fn create_task(
title: String,
description: Option<String>,
parent_id: Option<String>,
date: Option<chrono::DateTime<chrono::Utc>>,
has_time: Option<bool>,
state: State<'_, Mutex<AppState>>,
) -> Result<Task, String> {
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())

View file

@ -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;

View file

@ -261,7 +261,13 @@ async function deleteList(id: string) {
}
}
async function createTask(title: string, description?: string, parentId?: string): Promise<Task | null> {
async function createTask(
title: string,
description?: string,
parentId?: string,
date?: string | null,
hasTime?: boolean,
): Promise<Task | null> {
if (!activeListId) return null;
try {
const task = await invoke<Task>("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;