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:
parent
d01bd9d280
commit
0fc1f16c9d
|
|
@ -374,6 +374,8 @@ fn create_task(
|
||||||
title: String,
|
title: String,
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
parent_id: Option<String>,
|
parent_id: Option<String>,
|
||||||
|
date: Option<chrono::DateTime<chrono::Utc>>,
|
||||||
|
has_time: Option<bool>,
|
||||||
state: State<'_, Mutex<AppState>>,
|
state: State<'_, Mutex<AppState>>,
|
||||||
) -> Result<Task, String> {
|
) -> Result<Task, String> {
|
||||||
let mut s = lock_state(&state)?;
|
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())?;
|
let parent_uuid = Uuid::parse_str(&pid).map_err(|e| e.to_string())?;
|
||||||
task.parent_id = Some(parent_uuid);
|
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)?
|
repo_mut(&mut s)?
|
||||||
.create_task(id, task)
|
.create_task(id, task)
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,15 @@
|
||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
if (!title.trim()) return;
|
if (!title.trim()) return;
|
||||||
const created = await app.createTask(title.trim(), description.trim() || undefined);
|
// Pass date/has_time into createTask directly so the date can't be lost
|
||||||
if (date && created) {
|
// if a second round-trip to update() failed after the create succeeded.
|
||||||
await app.updateTask({ ...created, date: date, has_time: dateHasTime });
|
await app.createTask(
|
||||||
}
|
title.trim(),
|
||||||
|
description.trim() || undefined,
|
||||||
|
undefined,
|
||||||
|
date,
|
||||||
|
dateHasTime,
|
||||||
|
);
|
||||||
title = "";
|
title = "";
|
||||||
description = "";
|
description = "";
|
||||||
date = null;
|
date = null;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
if (!activeListId) return null;
|
||||||
try {
|
try {
|
||||||
const task = await invoke<Task>("create_task", {
|
const task = await invoke<Task>("create_task", {
|
||||||
|
|
@ -269,6 +275,8 @@ async function createTask(title: string, description?: string, parentId?: string
|
||||||
title,
|
title,
|
||||||
description: description ?? "",
|
description: description ?? "",
|
||||||
parentId: parentId ?? null,
|
parentId: parentId ?? null,
|
||||||
|
date: date ?? null,
|
||||||
|
hasTime: hasTime ?? false,
|
||||||
});
|
});
|
||||||
tasks = parentId ? [task, ...tasks] : [...tasks, task];
|
tasks = parentId ? [task, ...tasks] : [...tasks, task];
|
||||||
error = null;
|
error = null;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue